decord/alpha/source/modules/markup/TimestampUtils.tsx

140 lines
4.1 KiB
TypeScript
Raw Permalink Normal View History

2026-10-12 06:59:38 +00:00
// Module ID: 8156
// Function ID: 8157
// Name: TimestampUtils
2026-10-10 08:08:14 +00:00
// Dependencies: [4793, 4702, 1102, 2]
2026-07-29 08:29:29 +00:00
// Exports: formatTimestampMention, parseTimestamp, unparseTimestamp
2026-07-20 16:05:17 +00:00
2026-10-12 06:59:38 +00:00
// Module 8156 (TimestampUtils)
2026-10-03 08:58:59 +00:00
import DurationsDefault from "Durations" /* 1102 */;
2026-10-10 08:08:14 +00:00
import _modDef4702 from "module_4702" /* 4702 */;
import DateUtils from "DateUtils" /* 4793 */;
import size from "module_2" /* 2 */;
2026-08-24 06:08:38 +00:00
const TIMESTAMP_FORMATS = {
2026-07-20 16:05:17 +00:00
t(date) {
2026-10-03 08:58:59 +00:00
const obj = DateUtils;
return obj.dateFormat(date, "LT");
2026-07-20 16:05:17 +00:00
},
T(date) {
2026-10-03 08:58:59 +00:00
const obj = DateUtils;
return obj.dateFormat(date, "LTS");
2026-07-20 16:05:17 +00:00
},
d(date) {
2026-10-03 08:58:59 +00:00
const obj = DateUtils;
return obj.dateFormat(date, "L");
2026-07-20 16:05:17 +00:00
},
D(date) {
2026-10-03 08:58:59 +00:00
const obj = DateUtils;
return obj.dateFormat(date, "LL");
2026-07-20 16:05:17 +00:00
},
f(date) {
2026-10-03 08:58:59 +00:00
const obj = DateUtils;
return obj.dateFormat(date, "LLL");
2026-07-20 16:05:17 +00:00
},
F(date) {
2026-10-03 08:58:59 +00:00
const obj = DateUtils;
return obj.dateFormat(date, "LLLL");
2026-07-20 16:05:17 +00:00
},
s(date) {
2026-10-03 08:58:59 +00:00
const obj = DateUtils;
return obj.dateFormat(date, "L LT");
2026-07-20 16:05:17 +00:00
},
S(date) {
2026-10-03 08:58:59 +00:00
const obj = DateUtils;
return obj.dateFormat(date, "L LTS");
2026-07-20 16:05:17 +00:00
},
R(toDate) {
2026-10-10 08:08:14 +00:00
const obj = _modDef4702;
2026-10-03 08:58:59 +00:00
const result = obj.relativeTimeThreshold("s");
2026-10-10 08:08:14 +00:00
const obj2 = _modDef4702;
2026-10-03 08:58:59 +00:00
const result1 = obj2.relativeTimeThreshold("s", 60);
2026-10-10 08:08:14 +00:00
const obj3 = _modDef4702;
2026-10-03 08:58:59 +00:00
const result2 = obj3.relativeTimeThreshold("ss");
2026-10-10 08:08:14 +00:00
const obj4 = _modDef4702;
2026-10-03 08:58:59 +00:00
const result3 = obj4.relativeTimeThreshold("ss", -1);
2026-10-10 08:08:14 +00:00
const obj5 = _modDef4702;
2026-10-03 08:58:59 +00:00
const result4 = obj5.relativeTimeThreshold("m");
2026-10-10 08:08:14 +00:00
const obj6 = _modDef4702;
2026-10-03 08:58:59 +00:00
const result5 = obj6.relativeTimeThreshold("m", 60);
let fromNowResult = null;
2026-07-29 08:29:29 +00:00
try {
2026-10-10 08:08:14 +00:00
const tmpResult = _modDef4702;
2026-10-03 08:58:59 +00:00
const tmpResultResult = tmpResult(toDate.toDate());
fromNowResult = tmpResultResult.fromNow();
2026-07-29 08:29:29 +00:00
} catch (err) {
2026-07-20 16:05:17 +00:00
}
2026-10-10 08:08:14 +00:00
const tmpResult5 = _modDef4702;
2026-10-03 08:58:59 +00:00
const result6 = tmpResult5.relativeTimeThreshold("s", result);
2026-10-10 08:08:14 +00:00
const tmpResult6 = _modDef4702;
2026-10-03 08:58:59 +00:00
const result7 = tmpResult6.relativeTimeThreshold("ss", result2);
2026-10-10 08:08:14 +00:00
const tmpResult7 = _modDef4702;
2026-10-03 08:58:59 +00:00
const result8 = tmpResult7.relativeTimeThreshold("m", result4);
if (fromNowResult == null) {
2026-10-10 08:08:14 +00:00
const tmpResult8 = _modDef4702;
2026-10-03 08:58:59 +00:00
const tmpResult4Result = tmpResult8(toDate.toDate());
fromNowResult = tmpResult4Result.fromNow();
}
return fromNowResult;
2026-07-20 16:05:17 +00:00
}
};
Object.setPrototypeOf(TIMESTAMP_FORMATS, null);
const keys = Object.keys(TIMESTAMP_FORMATS);
2026-07-20 16:05:17 +00:00
const regExp = new RegExp("^<t:(-?\\d{1,17})(?::(" + keys.join("|") + "))?>");
let result = size.fileFinishedImporting("modules/markup/TimestampUtils.tsx");
2026-07-20 16:05:17 +00:00
export { TIMESTAMP_FORMATS };
2026-07-20 16:05:17 +00:00
export const DEFAULT_TIMESTAMP_FORMAT = "f";
export const TIMESTAMP_REGEX = regExp;
2026-09-02 09:53:35 +00:00
export const formatTimestampMention = function formatTimestampMention(mention) {
2026-10-03 08:58:59 +00:00
let format;
let obj;
let timestamp;
2026-09-02 09:53:35 +00:00
({ timestamp, format } = mention);
2026-10-10 08:08:14 +00:00
const tmp = _modDef4702;
2026-10-03 08:58:59 +00:00
const NumberResult = Number(timestamp);
const tmpResult = tmp(NumberResult * DurationsDefault.Millis.SECOND);
2026-07-29 08:29:29 +00:00
if (tmpResult.isValid()) {
let f;
if (null != format) {
f = obj[format];
}
if (null == f) {
f = obj.f;
}
2026-10-03 08:58:59 +00:00
obj = { timestamp, format, parsed: tmpResult, full: obj.F(tmpResult), formatted: f(tmpResult) };
2026-07-29 08:29:29 +00:00
return obj;
} else {
return null;
}
};
export const parseTimestamp = function parseTimestamp(timestamp, format) {
2026-10-03 08:58:59 +00:00
let obj;
2026-10-10 08:08:14 +00:00
const tmp = _modDef4702;
2026-10-03 08:58:59 +00:00
const NumberResult = Number(timestamp);
const tmpResult = tmp(NumberResult * DurationsDefault.Millis.SECOND);
2026-07-29 08:29:29 +00:00
let tmp3 = null;
if (tmpResult.isValid()) {
let f;
if (null != format) {
f = obj[format];
2026-07-29 08:29:29 +00:00
}
if (null == f) {
f = obj.f;
}
2026-10-03 08:58:59 +00:00
obj = { timestamp, format, parsed: tmpResult, full: obj.F(tmpResult), formatted: f(tmpResult) };
2026-07-29 08:29:29 +00:00
tmp3 = obj;
}
return tmp3;
2026-07-20 16:05:17 +00:00
};
2026-09-02 09:53:35 +00:00
export const unparseTimestamp = function unparseTimestamp(timestamp, format) {
2026-10-03 08:58:59 +00:00
let combined;
2026-09-02 09:53:35 +00:00
if (null != format) {
2026-07-20 16:05:17 +00:00
const _HermesInternal2 = HermesInternal;
2026-10-03 08:58:59 +00:00
combined = "<t:" + timestamp + ":" + format + ">";
2026-07-20 16:05:17 +00:00
} else {
const _HermesInternal = HermesInternal;
2026-09-02 09:53:35 +00:00
combined = "<t:" + timestamp + ">";
2026-07-20 16:05:17 +00:00
}
return combined;
};