forked from mtierltd/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdateformat.js
More file actions
53 lines (44 loc) · 1.44 KB
/
dateformat.js
File metadata and controls
53 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var moment = require("moment");
moment.locale(document.documentElement.getAttribute("data-locale") || undefined);
const dformat = moment.localeData().longDateFormat('L');
const tformat = moment.localeData().longDateFormat('LTS');
exports.dformat = function () {
return dformat;
};
exports.tformat = function () {
return tformat;
};
exports.dtformat = function () {
return dformat + ' ' + tformat;
};
exports.mformat = function () {
var sample;
try {
sample = window.Intl ? new Intl.DateTimeFormat((document.documentElement.getAttribute("data-locale") || undefined), {
numberingSystem: 'latn',
calendar: 'gregory',
}).format(new Date(1970, 11, 31)) : '';
} catch {
sample = window.Intl ? new Intl.DateTimeFormat(undefined, {
numberingSystem: 'latn',
calendar: 'gregory',
}).format(new Date(1970, 11, 31)) : '';
}
let mm = 0,
mi = sample.indexOf(12);
let dd = 1,
di = sample.indexOf(31);
let yy = 2,
yi = sample.indexOf(1970);
// IE 10 or earlier, iOS 9 or earlier, non-Latin numbering system
// or non-Gregorian calendar; fall back to mm/dd/yyyy
if (yi >= 0 && mi >= 0 && di >= 0) {
mm = (mi > yi) + (mi > di);
dd = (di > yi) + (di > mi);
yy = (yi > mi) + (yi > di);
}
let r = [];
r[yy] = 'YYYY';
r[mm] = 'MM';
return r.join(sample.match(/[-.]/) || '/').replace('//','/');
};