Brought in another asset for Ray's eye form: moment
[openemr.git] / public / assets / moment-2-13-0 / src / lib / units / hour.js
blob86f18abe40f8472218fd66b2c28b0d06a5ac9021
1 import { makeGetSet } from '../moment/get-set';
2 import { addFormatToken } from '../format/format';
3 import { addUnitAlias } from './aliases';
4 import { addRegexToken, match1to2, match2, match3to4, match5to6 } from '../parse/regex';
5 import { addParseToken } from '../parse/token';
6 import { HOUR, MINUTE, SECOND } from './constants';
7 import toInt from '../utils/to-int';
8 import zeroFill from '../utils/zero-fill';
9 import getParsingFlags from '../create/parsing-flags';
11 // FORMATTING
13 function hFormat() {
14     return this.hours() % 12 || 12;
17 function kFormat() {
18     return this.hours() || 24;
21 addFormatToken('H', ['HH', 2], 0, 'hour');
22 addFormatToken('h', ['hh', 2], 0, hFormat);
23 addFormatToken('k', ['kk', 2], 0, kFormat);
25 addFormatToken('hmm', 0, 0, function () {
26     return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
27 });
29 addFormatToken('hmmss', 0, 0, function () {
30     return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
31         zeroFill(this.seconds(), 2);
32 });
34 addFormatToken('Hmm', 0, 0, function () {
35     return '' + this.hours() + zeroFill(this.minutes(), 2);
36 });
38 addFormatToken('Hmmss', 0, 0, function () {
39     return '' + this.hours() + zeroFill(this.minutes(), 2) +
40         zeroFill(this.seconds(), 2);
41 });
43 function meridiem (token, lowercase) {
44     addFormatToken(token, 0, 0, function () {
45         return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
46     });
49 meridiem('a', true);
50 meridiem('A', false);
52 // ALIASES
54 addUnitAlias('hour', 'h');
56 // PARSING
58 function matchMeridiem (isStrict, locale) {
59     return locale._meridiemParse;
62 addRegexToken('a',  matchMeridiem);
63 addRegexToken('A',  matchMeridiem);
64 addRegexToken('H',  match1to2);
65 addRegexToken('h',  match1to2);
66 addRegexToken('HH', match1to2, match2);
67 addRegexToken('hh', match1to2, match2);
69 addRegexToken('hmm', match3to4);
70 addRegexToken('hmmss', match5to6);
71 addRegexToken('Hmm', match3to4);
72 addRegexToken('Hmmss', match5to6);
74 addParseToken(['H', 'HH'], HOUR);
75 addParseToken(['a', 'A'], function (input, array, config) {
76     config._isPm = config._locale.isPM(input);
77     config._meridiem = input;
78 });
79 addParseToken(['h', 'hh'], function (input, array, config) {
80     array[HOUR] = toInt(input);
81     getParsingFlags(config).bigHour = true;
82 });
83 addParseToken('hmm', function (input, array, config) {
84     var pos = input.length - 2;
85     array[HOUR] = toInt(input.substr(0, pos));
86     array[MINUTE] = toInt(input.substr(pos));
87     getParsingFlags(config).bigHour = true;
88 });
89 addParseToken('hmmss', function (input, array, config) {
90     var pos1 = input.length - 4;
91     var pos2 = input.length - 2;
92     array[HOUR] = toInt(input.substr(0, pos1));
93     array[MINUTE] = toInt(input.substr(pos1, 2));
94     array[SECOND] = toInt(input.substr(pos2));
95     getParsingFlags(config).bigHour = true;
96 });
97 addParseToken('Hmm', function (input, array, config) {
98     var pos = input.length - 2;
99     array[HOUR] = toInt(input.substr(0, pos));
100     array[MINUTE] = toInt(input.substr(pos));
102 addParseToken('Hmmss', function (input, array, config) {
103     var pos1 = input.length - 4;
104     var pos2 = input.length - 2;
105     array[HOUR] = toInt(input.substr(0, pos1));
106     array[MINUTE] = toInt(input.substr(pos1, 2));
107     array[SECOND] = toInt(input.substr(pos2));
110 // LOCALES
112 export function localeIsPM (input) {
113     // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
114     // Using charAt should be more compatible.
115     return ((input + '').toLowerCase().charAt(0) === 'p');
118 export var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
119 export function localeMeridiem (hours, minutes, isLower) {
120     if (hours > 11) {
121         return isLower ? 'pm' : 'PM';
122     } else {
123         return isLower ? 'am' : 'AM';
124     }
128 // MOMENTS
130 // Setting the hour should keep the time, because the user explicitly
131 // specified which hour he wants. So trying to maintain the same hour (in
132 // a new timezone) makes sense. Adding/subtracting hours does not follow
133 // this rule.
134 export var getSetHour = makeGetSet('Hours', true);