corrade-nucleus-nucleons – Blame information for rev 10

Subversion Repositories:
Rev:
Rev Author Line No. Line
10 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, match1to4, match1to6, match2, match4, match6, matchSigned } from '../parse/regex';
6 import { addParseToken } from '../parse/token';
7 import { hooks } from '../utils/hooks';
8 import { YEAR } from './constants';
9 import toInt from '../utils/to-int';
10  
11 // FORMATTING
12  
13 addFormatToken('Y', 0, 0, function () {
14 var y = this.year();
15 return y <= 9999 ? '' + y : '+' + y;
16 });
17  
18 addFormatToken(0, ['YY', 2], 0, function () {
19 return this.year() % 100;
20 });
21  
22 addFormatToken(0, ['YYYY', 4], 0, 'year');
23 addFormatToken(0, ['YYYYY', 5], 0, 'year');
24 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
25  
26 // ALIASES
27  
28 addUnitAlias('year', 'y');
29  
30 // PRIORITIES
31  
32 addUnitPriority('year', 1);
33  
34 // PARSING
35  
36 addRegexToken('Y', matchSigned);
37 addRegexToken('YY', match1to2, match2);
38 addRegexToken('YYYY', match1to4, match4);
39 addRegexToken('YYYYY', match1to6, match6);
40 addRegexToken('YYYYYY', match1to6, match6);
41  
42 addParseToken(['YYYYY', 'YYYYYY'], YEAR);
43 addParseToken('YYYY', function (input, array) {
44 array[YEAR] = input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
45 });
46 addParseToken('YY', function (input, array) {
47 array[YEAR] = hooks.parseTwoDigitYear(input);
48 });
49 addParseToken('Y', function (input, array) {
50 array[YEAR] = parseInt(input, 10);
51 });
52  
53 // HELPERS
54  
55 export function daysInYear(year) {
56 return isLeapYear(year) ? 366 : 365;
57 }
58  
59 function isLeapYear(year) {
60 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
61 }
62  
63 // HOOKS
64  
65 hooks.parseTwoDigitYear = function (input) {
66 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
67 };
68  
69 // MOMENTS
70  
71 export var getSetYear = makeGetSet('FullYear', true);
72  
73 export function getIsLeapYear () {
74 return isLeapYear(this.year());
75 }