-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathdate.js
77 lines (69 loc) · 1.96 KB
/
date.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
72
73
74
75
76
77
var moment = require('moment');
/**
* Format dates
*
* Since 1.2.0, by default, it considers the input format is "ISO 8601"
*
* @exampleContext {"lang":"en"}
* @example ["20160131", "L"]
* @example ["20160131", "LL"]
* @example ["20160131", "LLLL"]
* @example ["20160131", "dddd"]
*
* @exampleContext {"lang":"fr"}
* @example ["2017-05-10T15:57:23.769561+03:00", "LLLL"]
* @example ["2017-05-10 15:57:23.769561+03:00", "LLLL"]
* @example ["20160131", "LLLL"]
* @example ["20160131", "dddd"]
*
* @exampleContext {"lang":"fr"}
* @example ["20160131", "dddd", "YYYYMMDD"]
* @example [1410715640, "LLLL", "X" ]
*
* @param {String|Number} d date to format
* @param {String} patternOut output format
* @param {String} patternIn [optional] input format, ISO8601 by default
* @return {String} return formatted date
*/
function formatD (d, patternOut, patternIn) {
if (d !== null && typeof d !== 'undefined') {
moment.locale(this.lang);
if (patternIn) {
return moment(d + '', patternIn).format(patternOut);
}
return moment(d + '').format(patternOut);
}
return d;
}
/**
* Format dates
*
* @deprecated
*
* @exampleContext {"lang":"en"}
* @example ["20160131", "YYYYMMDD", "L"]
* @example ["20160131", "YYYYMMDD", "LL"]
* @example ["20160131", "YYYYMMDD", "LLLL"]
* @example ["20160131", "YYYYMMDD", "dddd"]
* @example [1410715640, "X", "LLLL"]
*
* @exampleContext {"lang":"fr"}
* @example ["20160131", "YYYYMMDD", "LLLL"]
* @example ["20160131", "YYYYMMDD", "dddd"]
*
* @param {String|Number} d date to format
* @param {String} patternIn input format
* @param {String} patternOut output format
* @return {String} return formatted date
*/
function convDate (d, patternIn, patternOut) {
if (d !== null && typeof d !== 'undefined') {
moment.locale(this.lang);
return moment(d + '', patternIn).format(patternOut);
}
return d;
}
module.exports = {
formatD : formatD,
convDate : convDate
};