-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmoment-strftime.js
71 lines (65 loc) · 1.43 KB
/
moment-strftime.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(function () {
var moment, replacements;
if (typeof require === "function") {
moment = require('moment');
} else {
moment = this.moment;
}
replacements = {
'a': 'ddd',
'A': 'dddd',
'b': 'MMM',
'B': 'MMMM',
'c': 'lll',
'd': 'DD',
'-d': 'D',
'e': 'D',
'F': 'YYYY-MM-DD',
'H': 'HH',
'-H': 'H',
'I': 'hh',
'-I': 'h',
'j': 'DDDD',
'-j': 'DDD',
'k': 'H',
'l': 'h',
'm': 'MM',
'-m': 'M',
'M': 'mm',
'-M': 'm',
'p': 'A',
'P': 'a',
'S': 'ss',
'-S': 's',
'u': 'E',
'w': 'd',
'W': 'WW',
'x': 'll',
'X': 'LTS',
'y': 'YY',
'Y': 'YYYY',
'z': 'ZZ',
'Z': 'z',
'f': 'SSS',
'%': '%'
};
moment.fn.strftime = function (format) {
var momentFormat, tokens;
// Break up format string based on strftime tokens
tokens = format.split(/(%\-?.)/);
momentFormat = tokens.map(function (token) {
// Replace strftime tokens with moment formats
if (token[0] === '%' && replacements.hasOwnProperty(token.substr(1))) {
return replacements[token.substr(1)];
}
// Escape non-token strings to avoid accidental formatting
return token.length > 0 ? '[' + token + ']' : token;
}).join('');
return this.format(momentFormat);
};
if (typeof module !== "undefined" && module !== null) {
module.exports = moment;
} else {
this.moment = moment;
}
}).call(this);