1 | "use strict";
|
2 |
|
3 |
|
4 | Object.defineProperty(exports, "__esModule", { value: true });
|
5 | exports.Time = void 0;
|
6 |
|
7 |
|
8 |
|
9 | const UNITS = [
|
10 | { name: 'years', milliseconds: 365 * 24 * 60 * 60 * 1000 },
|
11 | { name: 'months', milliseconds: 30 * 24 * 60 * 60 * 1000 },
|
12 | { name: 'days', milliseconds: 24 * 60 * 60 * 1000 },
|
13 | { name: 'hours', milliseconds: 60 * 60 * 1000 },
|
14 | { name: 'minutes', milliseconds: 60 * 1000 },
|
15 | { name: 'seconds', milliseconds: 1000 }
|
16 | ];
|
17 |
|
18 |
|
19 |
|
20 | var Time;
|
21 | (function (Time) {
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | function formatHuman(value, format = 'long') {
|
30 | const lang = document.documentElement.lang || 'en';
|
31 | const formatter = new Intl.RelativeTimeFormat(lang, {
|
32 | numeric: 'auto',
|
33 | style: format
|
34 | });
|
35 | const delta = new Date(value).getTime() - Date.now();
|
36 | for (let unit of UNITS) {
|
37 | const amount = Math.ceil(delta / unit.milliseconds);
|
38 | if (amount === 0) {
|
39 | continue;
|
40 | }
|
41 | return formatter.format(amount, unit.name);
|
42 | }
|
43 | return formatter.format(0, 'seconds');
|
44 | }
|
45 | Time.formatHuman = formatHuman;
|
46 | |
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | function format(value) {
|
54 | const lang = document.documentElement.lang || 'en';
|
55 | const formatter = new Intl.DateTimeFormat(lang, {
|
56 | dateStyle: 'short',
|
57 | timeStyle: 'short'
|
58 | });
|
59 | return formatter.format(new Date(value));
|
60 | }
|
61 | Time.format = format;
|
62 | })(Time || (exports.Time = Time = {}));
|
63 |
|
\ | No newline at end of file |