corrade-nucleus-nucleons – Blame information for rev 38
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
38 | office | 1 | import { makeGetSet } from '../moment/get-set'; |
2 | import { addFormatToken } from '../format/format'; |
||
3 | import { addUnitAlias } from './aliases'; |
||
4 | import { addUnitPriority } from './priorities'; |
||
5 | import { addRegexToken, match1to2, match2, match3to4, match5to6 } from '../parse/regex'; |
||
6 | import { addParseToken } from '../parse/token'; |
||
7 | import { HOUR, MINUTE, SECOND } from './constants'; |
||
8 | import toInt from '../utils/to-int'; |
||
9 | import zeroFill from '../utils/zero-fill'; |
||
10 | import getParsingFlags from '../create/parsing-flags'; |
||
11 | |||
12 | // FORMATTING |
||
13 | |||
14 | function hFormat() { |
||
15 | return this.hours() % 12 || 12; |
||
16 | } |
||
17 | |||
18 | function kFormat() { |
||
19 | return this.hours() || 24; |
||
20 | } |
||
21 | |||
22 | addFormatToken('H', ['HH', 2], 0, 'hour'); |
||
23 | addFormatToken('h', ['hh', 2], 0, hFormat); |
||
24 | addFormatToken('k', ['kk', 2], 0, kFormat); |
||
25 | |||
26 | addFormatToken('hmm', 0, 0, function () { |
||
27 | return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2); |
||
28 | }); |
||
29 | |||
30 | addFormatToken('hmmss', 0, 0, function () { |
||
31 | return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) + |
||
32 | zeroFill(this.seconds(), 2); |
||
33 | }); |
||
34 | |||
35 | addFormatToken('Hmm', 0, 0, function () { |
||
36 | return '' + this.hours() + zeroFill(this.minutes(), 2); |
||
37 | }); |
||
38 | |||
39 | addFormatToken('Hmmss', 0, 0, function () { |
||
40 | return '' + this.hours() + zeroFill(this.minutes(), 2) + |
||
41 | zeroFill(this.seconds(), 2); |
||
42 | }); |
||
43 | |||
44 | function meridiem (token, lowercase) { |
||
45 | addFormatToken(token, 0, 0, function () { |
||
46 | return this.localeData().meridiem(this.hours(), this.minutes(), lowercase); |
||
47 | }); |
||
48 | } |
||
49 | |||
50 | meridiem('a', true); |
||
51 | meridiem('A', false); |
||
52 | |||
53 | // ALIASES |
||
54 | |||
55 | addUnitAlias('hour', 'h'); |
||
56 | |||
57 | // PRIORITY |
||
58 | addUnitPriority('hour', 13); |
||
59 | |||
60 | // PARSING |
||
61 | |||
62 | function matchMeridiem (isStrict, locale) { |
||
63 | return locale._meridiemParse; |
||
64 | } |
||
65 | |||
66 | addRegexToken('a', matchMeridiem); |
||
67 | addRegexToken('A', matchMeridiem); |
||
68 | addRegexToken('H', match1to2); |
||
69 | addRegexToken('h', match1to2); |
||
70 | addRegexToken('k', match1to2); |
||
71 | addRegexToken('HH', match1to2, match2); |
||
72 | addRegexToken('hh', match1to2, match2); |
||
73 | addRegexToken('kk', match1to2, match2); |
||
74 | |||
75 | addRegexToken('hmm', match3to4); |
||
76 | addRegexToken('hmmss', match5to6); |
||
77 | addRegexToken('Hmm', match3to4); |
||
78 | addRegexToken('Hmmss', match5to6); |
||
79 | |||
80 | addParseToken(['H', 'HH'], HOUR); |
||
81 | addParseToken(['k', 'kk'], function (input, array, config) { |
||
82 | var kInput = toInt(input); |
||
83 | array[HOUR] = kInput === 24 ? 0 : kInput; |
||
84 | }); |
||
85 | addParseToken(['a', 'A'], function (input, array, config) { |
||
86 | config._isPm = config._locale.isPM(input); |
||
87 | config._meridiem = input; |
||
88 | }); |
||
89 | addParseToken(['h', 'hh'], function (input, array, config) { |
||
90 | array[HOUR] = toInt(input); |
||
91 | getParsingFlags(config).bigHour = true; |
||
92 | }); |
||
93 | addParseToken('hmm', function (input, array, config) { |
||
94 | var pos = input.length - 2; |
||
95 | array[HOUR] = toInt(input.substr(0, pos)); |
||
96 | array[MINUTE] = toInt(input.substr(pos)); |
||
97 | getParsingFlags(config).bigHour = true; |
||
98 | }); |
||
99 | addParseToken('hmmss', function (input, array, config) { |
||
100 | var pos1 = input.length - 4; |
||
101 | var pos2 = input.length - 2; |
||
102 | array[HOUR] = toInt(input.substr(0, pos1)); |
||
103 | array[MINUTE] = toInt(input.substr(pos1, 2)); |
||
104 | array[SECOND] = toInt(input.substr(pos2)); |
||
105 | getParsingFlags(config).bigHour = true; |
||
106 | }); |
||
107 | addParseToken('Hmm', function (input, array, config) { |
||
108 | var pos = input.length - 2; |
||
109 | array[HOUR] = toInt(input.substr(0, pos)); |
||
110 | array[MINUTE] = toInt(input.substr(pos)); |
||
111 | }); |
||
112 | addParseToken('Hmmss', function (input, array, config) { |
||
113 | var pos1 = input.length - 4; |
||
114 | var pos2 = input.length - 2; |
||
115 | array[HOUR] = toInt(input.substr(0, pos1)); |
||
116 | array[MINUTE] = toInt(input.substr(pos1, 2)); |
||
117 | array[SECOND] = toInt(input.substr(pos2)); |
||
118 | }); |
||
119 | |||
120 | // LOCALES |
||
121 | |||
122 | export function localeIsPM (input) { |
||
123 | // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays |
||
124 | // Using charAt should be more compatible. |
||
125 | return ((input + '').toLowerCase().charAt(0) === 'p'); |
||
126 | } |
||
127 | |||
128 | export var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i; |
||
129 | export function localeMeridiem (hours, minutes, isLower) { |
||
130 | if (hours > 11) { |
||
131 | return isLower ? 'pm' : 'PM'; |
||
132 | } else { |
||
133 | return isLower ? 'am' : 'AM'; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | |||
138 | // MOMENTS |
||
139 | |||
140 | // Setting the hour should keep the time, because the user explicitly |
||
141 | // specified which hour he wants. So trying to maintain the same hour (in |
||
142 | // a new timezone) makes sense. Adding/subtracting hours does not follow |
||
143 | // this rule. |
||
144 | export var getSetHour = makeGetSet('Hours', true); |