1 | import { FORMAT_DEFAULT } from '../../constant';
|
2 | export default (function (o, c) {
|
3 |
|
4 | var proto = c.prototype;
|
5 | var oldFormat = proto.format;
|
6 |
|
7 | proto.format = function (formatStr) {
|
8 | var _this = this;
|
9 |
|
10 | var locale = this.$locale();
|
11 |
|
12 | if (!this.isValid()) {
|
13 | return oldFormat.bind(this)(formatStr);
|
14 | }
|
15 |
|
16 | var utils = this.$utils();
|
17 | var str = formatStr || FORMAT_DEFAULT;
|
18 | var result = str.replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g, function (match) {
|
19 | switch (match) {
|
20 | case 'Q':
|
21 | return Math.ceil((_this.$M + 1) / 3);
|
22 |
|
23 | case 'Do':
|
24 | return locale.ordinal(_this.$D);
|
25 |
|
26 | case 'gggg':
|
27 | return _this.weekYear();
|
28 |
|
29 | case 'GGGG':
|
30 | return _this.isoWeekYear();
|
31 |
|
32 | case 'wo':
|
33 | return locale.ordinal(_this.week(), 'W');
|
34 |
|
35 |
|
36 | case 'w':
|
37 | case 'ww':
|
38 | return utils.s(_this.week(), match === 'w' ? 1 : 2, '0');
|
39 |
|
40 | case 'W':
|
41 | case 'WW':
|
42 | return utils.s(_this.isoWeek(), match === 'W' ? 1 : 2, '0');
|
43 |
|
44 | case 'k':
|
45 | case 'kk':
|
46 | return utils.s(String(_this.$H === 0 ? 24 : _this.$H), match === 'k' ? 1 : 2, '0');
|
47 |
|
48 | case 'X':
|
49 | return Math.floor(_this.$d.getTime() / 1000);
|
50 |
|
51 | case 'x':
|
52 | return _this.$d.getTime();
|
53 |
|
54 | case 'z':
|
55 | return "[" + _this.offsetName() + "]";
|
56 |
|
57 | case 'zzz':
|
58 | return "[" + _this.offsetName('long') + "]";
|
59 |
|
60 | default:
|
61 | return match;
|
62 | }
|
63 | });
|
64 | return oldFormat.bind(this)(result);
|
65 | };
|
66 | }); |
\ | No newline at end of file |