replyke-rn
Version:
Replyke React Native components: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
55 lines • 2.13 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var jsx_runtime_1 = require("react/jsx-runtime");
var moment_1 = __importDefault(require("moment"));
var react_native_1 = require("react-native");
function formatTime(time, justNowText) {
var now = new Date();
var then = new Date(time);
var seconds = Math.floor((now.getTime() - then.getTime()) / 1000);
var timeString = "";
if (seconds < 20) {
timeString = justNowText;
}
else if (seconds < 60) {
timeString = "".concat(seconds, "s");
}
else if (seconds < 3600) {
timeString = "".concat(Math.floor(seconds / 60), "m");
}
else if (seconds < 86400) {
timeString = "".concat(Math.floor(seconds / 3600), "h");
}
else if (seconds < 2592000) {
// 30 days
timeString = "".concat(Math.floor(seconds / 86400), "d");
}
else if (seconds < 31536000) {
// 365 days
timeString = "".concat(Math.floor(seconds / 2592000), "mo");
}
else {
timeString = "".concat(Math.floor(seconds / 31536000), "y");
}
return timeString;
}
function FromNow(_a) {
var time = _a.time, _b = _a.fontSize, fontSize = _b === void 0 ? 12 : _b, _c = _a.fontWeight, fontWeight = _c === void 0 ? 400 : _c, _d = _a.color, color = _d === void 0 ? "#737373" : _d, lean = _a.lean, _e = _a.justNowText, justNowText = _e === void 0 ? "Just now" : _e;
if (lean) {
return ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: {
fontSize: fontSize,
fontWeight: fontWeight,
color: color,
}, children: formatTime(time, justNowText) }));
}
return ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: {
fontSize: fontSize,
fontWeight: fontWeight,
color: color,
}, children: (0, moment_1.default)(new Date(time)).fromNow() }));
}
exports.default = FromNow;
//# sourceMappingURL=FromNow.js.map