Brought in another asset for Ray's eye form: moment
[openemr.git] / public / assets / moment-2-13-0 / src / lib / units / year.js
blobb86df29be83522e72381747cbb0732a1b29d2d80
1 import { makeGetSet } from '../moment/get-set';
2 import { addFormatToken } from '../format/format';
3 import { addUnitAlias } from './aliases';
4 import { addRegexToken, match1to2, match1to4, match1to6, match2, match4, match6, matchSigned } from '../parse/regex';
5 import { addParseToken } from '../parse/token';
6 import { hooks } from '../utils/hooks';
7 import { YEAR } from './constants';
8 import toInt from '../utils/to-int';
10 // FORMATTING
12 addFormatToken('Y', 0, 0, function () {
13     var y = this.year();
14     return y <= 9999 ? '' + y : '+' + y;
15 });
17 addFormatToken(0, ['YY', 2], 0, function () {
18     return this.year() % 100;
19 });
21 addFormatToken(0, ['YYYY',   4],       0, 'year');
22 addFormatToken(0, ['YYYYY',  5],       0, 'year');
23 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
25 // ALIASES
27 addUnitAlias('year', 'y');
29 // PARSING
31 addRegexToken('Y',      matchSigned);
32 addRegexToken('YY',     match1to2, match2);
33 addRegexToken('YYYY',   match1to4, match4);
34 addRegexToken('YYYYY',  match1to6, match6);
35 addRegexToken('YYYYYY', match1to6, match6);
37 addParseToken(['YYYYY', 'YYYYYY'], YEAR);
38 addParseToken('YYYY', function (input, array) {
39     array[YEAR] = input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
40 });
41 addParseToken('YY', function (input, array) {
42     array[YEAR] = hooks.parseTwoDigitYear(input);
43 });
44 addParseToken('Y', function (input, array) {
45     array[YEAR] = parseInt(input, 10);
46 });
48 // HELPERS
50 export function daysInYear(year) {
51     return isLeapYear(year) ? 366 : 365;
54 function isLeapYear(year) {
55     return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
58 // HOOKS
60 hooks.parseTwoDigitYear = function (input) {
61     return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
64 // MOMENTS
66 export var getSetYear = makeGetSet('FullYear', true);
68 export function getIsLeapYear () {
69     return isLeapYear(this.year());