153 return false; |
153 return false; |
154 }; |
154 }; |
155 } |
155 } |
156 |
156 |
157 function isValid(m) { |
157 function isValid(m) { |
158 if (m._isValid == null) { |
158 var flags = null, |
159 var flags = getParsingFlags(m), |
159 parsedParts = false, |
160 parsedParts = some.call(flags.parsedDateParts, function (i) { |
160 isNowValid = m._d && !isNaN(m._d.getTime()); |
161 return i != null; |
161 if (isNowValid) { |
162 }), |
162 flags = getParsingFlags(m); |
163 isNowValid = |
163 parsedParts = some.call(flags.parsedDateParts, function (i) { |
164 !isNaN(m._d.getTime()) && |
164 return i != null; |
165 flags.overflow < 0 && |
165 }); |
166 !flags.empty && |
166 isNowValid = |
167 !flags.invalidEra && |
167 flags.overflow < 0 && |
168 !flags.invalidMonth && |
168 !flags.empty && |
169 !flags.invalidWeekday && |
169 !flags.invalidEra && |
170 !flags.weekdayMismatch && |
170 !flags.invalidMonth && |
171 !flags.nullInput && |
171 !flags.invalidWeekday && |
172 !flags.invalidFormat && |
172 !flags.weekdayMismatch && |
173 !flags.userInvalidated && |
173 !flags.nullInput && |
174 (!flags.meridiem || (flags.meridiem && parsedParts)); |
174 !flags.invalidFormat && |
175 |
175 !flags.userInvalidated && |
|
176 (!flags.meridiem || (flags.meridiem && parsedParts)); |
176 if (m._strict) { |
177 if (m._strict) { |
177 isNowValid = |
178 isNowValid = |
178 isNowValid && |
179 isNowValid && |
179 flags.charsLeftOver === 0 && |
180 flags.charsLeftOver === 0 && |
180 flags.unusedTokens.length === 0 && |
181 flags.unusedTokens.length === 0 && |
181 flags.bigHour === undefined; |
182 flags.bigHour === undefined; |
182 } |
183 } |
183 |
184 } |
184 if (Object.isFrozen == null || !Object.isFrozen(m)) { |
185 if (Object.isFrozen == null || !Object.isFrozen(m)) { |
185 m._isValid = isNowValid; |
186 m._isValid = isNowValid; |
186 } else { |
187 } else { |
187 return isNowValid; |
188 return isNowValid; |
188 } |
|
189 } |
189 } |
190 return m._isValid; |
190 return m._isValid; |
191 } |
191 } |
192 |
192 |
193 function createInvalid(flags) { |
193 function createInvalid(flags) { |
628 function pastFuture(diff, output) { |
628 function pastFuture(diff, output) { |
629 var format = this._relativeTime[diff > 0 ? 'future' : 'past']; |
629 var format = this._relativeTime[diff > 0 ? 'future' : 'past']; |
630 return isFunction(format) ? format(output) : format.replace(/%s/i, output); |
630 return isFunction(format) ? format(output) : format.replace(/%s/i, output); |
631 } |
631 } |
632 |
632 |
633 var aliases = {}; |
633 var aliases = { |
634 |
634 D: 'date', |
635 function addUnitAlias(unit, shorthand) { |
635 dates: 'date', |
636 var lowerCase = unit.toLowerCase(); |
636 date: 'date', |
637 aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit; |
637 d: 'day', |
638 } |
638 days: 'day', |
|
639 day: 'day', |
|
640 e: 'weekday', |
|
641 weekdays: 'weekday', |
|
642 weekday: 'weekday', |
|
643 E: 'isoWeekday', |
|
644 isoweekdays: 'isoWeekday', |
|
645 isoweekday: 'isoWeekday', |
|
646 DDD: 'dayOfYear', |
|
647 dayofyears: 'dayOfYear', |
|
648 dayofyear: 'dayOfYear', |
|
649 h: 'hour', |
|
650 hours: 'hour', |
|
651 hour: 'hour', |
|
652 ms: 'millisecond', |
|
653 milliseconds: 'millisecond', |
|
654 millisecond: 'millisecond', |
|
655 m: 'minute', |
|
656 minutes: 'minute', |
|
657 minute: 'minute', |
|
658 M: 'month', |
|
659 months: 'month', |
|
660 month: 'month', |
|
661 Q: 'quarter', |
|
662 quarters: 'quarter', |
|
663 quarter: 'quarter', |
|
664 s: 'second', |
|
665 seconds: 'second', |
|
666 second: 'second', |
|
667 gg: 'weekYear', |
|
668 weekyears: 'weekYear', |
|
669 weekyear: 'weekYear', |
|
670 GG: 'isoWeekYear', |
|
671 isoweekyears: 'isoWeekYear', |
|
672 isoweekyear: 'isoWeekYear', |
|
673 w: 'week', |
|
674 weeks: 'week', |
|
675 week: 'week', |
|
676 W: 'isoWeek', |
|
677 isoweeks: 'isoWeek', |
|
678 isoweek: 'isoWeek', |
|
679 y: 'year', |
|
680 years: 'year', |
|
681 year: 'year', |
|
682 }; |
639 |
683 |
640 function normalizeUnits(units) { |
684 function normalizeUnits(units) { |
641 return typeof units === 'string' |
685 return typeof units === 'string' |
642 ? aliases[units] || aliases[units.toLowerCase()] |
686 ? aliases[units] || aliases[units.toLowerCase()] |
643 : undefined; |
687 : undefined; |
676 } |
733 } |
677 units.sort(function (a, b) { |
734 units.sort(function (a, b) { |
678 return a.priority - b.priority; |
735 return a.priority - b.priority; |
679 }); |
736 }); |
680 return units; |
737 return units; |
681 } |
|
682 |
|
683 function isLeapYear(year) { |
|
684 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; |
|
685 } |
|
686 |
|
687 function absFloor(number) { |
|
688 if (number < 0) { |
|
689 // -0 -> 0 |
|
690 return Math.ceil(number) || 0; |
|
691 } else { |
|
692 return Math.floor(number); |
|
693 } |
|
694 } |
|
695 |
|
696 function toInt(argumentForCoercion) { |
|
697 var coercedNumber = +argumentForCoercion, |
|
698 value = 0; |
|
699 |
|
700 if (coercedNumber !== 0 && isFinite(coercedNumber)) { |
|
701 value = absFloor(coercedNumber); |
|
702 } |
|
703 |
|
704 return value; |
|
705 } |
|
706 |
|
707 function makeGetSet(unit, keepTime) { |
|
708 return function (value) { |
|
709 if (value != null) { |
|
710 set$1(this, unit, value); |
|
711 hooks.updateOffset(this, keepTime); |
|
712 return this; |
|
713 } else { |
|
714 return get(this, unit); |
|
715 } |
|
716 }; |
|
717 } |
|
718 |
|
719 function get(mom, unit) { |
|
720 return mom.isValid() |
|
721 ? mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() |
|
722 : NaN; |
|
723 } |
|
724 |
|
725 function set$1(mom, unit, value) { |
|
726 if (mom.isValid() && !isNaN(value)) { |
|
727 if ( |
|
728 unit === 'FullYear' && |
|
729 isLeapYear(mom.year()) && |
|
730 mom.month() === 1 && |
|
731 mom.date() === 29 |
|
732 ) { |
|
733 value = toInt(value); |
|
734 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit]( |
|
735 value, |
|
736 mom.month(), |
|
737 daysInMonth(value, mom.month()) |
|
738 ); |
|
739 } else { |
|
740 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value); |
|
741 } |
|
742 } |
|
743 } |
|
744 |
|
745 // MOMENTS |
|
746 |
|
747 function stringGet(units) { |
|
748 units = normalizeUnits(units); |
|
749 if (isFunction(this[units])) { |
|
750 return this[units](); |
|
751 } |
|
752 return this; |
|
753 } |
|
754 |
|
755 function stringSet(units, value) { |
|
756 if (typeof units === 'object') { |
|
757 units = normalizeObjectUnits(units); |
|
758 var prioritized = getPrioritizedUnits(units), |
|
759 i, |
|
760 prioritizedLen = prioritized.length; |
|
761 for (i = 0; i < prioritizedLen; i++) { |
|
762 this[prioritized[i].unit](units[prioritized[i].unit]); |
|
763 } |
|
764 } else { |
|
765 units = normalizeUnits(units); |
|
766 if (isFunction(this[units])) { |
|
767 return this[units](value); |
|
768 } |
|
769 } |
|
770 return this; |
|
771 } |
738 } |
772 |
739 |
773 var match1 = /\d/, // 0 - 9 |
740 var match1 = /\d/, // 0 - 9 |
774 match2 = /\d\d/, // 00 - 99 |
741 match2 = /\d\d/, // 00 - 99 |
775 match3 = /\d{3}/, // 000 - 999 |
742 match3 = /\d{3}/, // 000 - 999 |
788 matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123 |
755 matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123 |
789 // any word (or two) characters or numbers including two/three word month in arabic. |
756 // any word (or two) characters or numbers including two/three word month in arabic. |
790 // includes scottish gaelic two word and hyphenated months |
757 // includes scottish gaelic two word and hyphenated months |
791 matchWord = |
758 matchWord = |
792 /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i, |
759 /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i, |
|
760 match1to2NoLeadingZero = /^[1-9]\d?/, // 1-99 |
|
761 match1to2HasZero = /^([1-9]\d|\d)/, // 0-99 |
793 regexes; |
762 regexes; |
794 |
763 |
795 regexes = {}; |
764 regexes = {}; |
796 |
765 |
797 function addRegexToken(token, regex, strictRegex) { |
766 function addRegexToken(token, regex, strictRegex) { |
868 MINUTE = 4, |
861 MINUTE = 4, |
869 SECOND = 5, |
862 SECOND = 5, |
870 MILLISECOND = 6, |
863 MILLISECOND = 6, |
871 WEEK = 7, |
864 WEEK = 7, |
872 WEEKDAY = 8; |
865 WEEKDAY = 8; |
|
866 |
|
867 // FORMATTING |
|
868 |
|
869 addFormatToken('Y', 0, 0, function () { |
|
870 var y = this.year(); |
|
871 return y <= 9999 ? zeroFill(y, 4) : '+' + y; |
|
872 }); |
|
873 |
|
874 addFormatToken(0, ['YY', 2], 0, function () { |
|
875 return this.year() % 100; |
|
876 }); |
|
877 |
|
878 addFormatToken(0, ['YYYY', 4], 0, 'year'); |
|
879 addFormatToken(0, ['YYYYY', 5], 0, 'year'); |
|
880 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year'); |
|
881 |
|
882 // PARSING |
|
883 |
|
884 addRegexToken('Y', matchSigned); |
|
885 addRegexToken('YY', match1to2, match2); |
|
886 addRegexToken('YYYY', match1to4, match4); |
|
887 addRegexToken('YYYYY', match1to6, match6); |
|
888 addRegexToken('YYYYYY', match1to6, match6); |
|
889 |
|
890 addParseToken(['YYYYY', 'YYYYYY'], YEAR); |
|
891 addParseToken('YYYY', function (input, array) { |
|
892 array[YEAR] = |
|
893 input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input); |
|
894 }); |
|
895 addParseToken('YY', function (input, array) { |
|
896 array[YEAR] = hooks.parseTwoDigitYear(input); |
|
897 }); |
|
898 addParseToken('Y', function (input, array) { |
|
899 array[YEAR] = parseInt(input, 10); |
|
900 }); |
|
901 |
|
902 // HELPERS |
|
903 |
|
904 function daysInYear(year) { |
|
905 return isLeapYear(year) ? 366 : 365; |
|
906 } |
|
907 |
|
908 // HOOKS |
|
909 |
|
910 hooks.parseTwoDigitYear = function (input) { |
|
911 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000); |
|
912 }; |
|
913 |
|
914 // MOMENTS |
|
915 |
|
916 var getSetYear = makeGetSet('FullYear', true); |
|
917 |
|
918 function getIsLeapYear() { |
|
919 return isLeapYear(this.year()); |
|
920 } |
|
921 |
|
922 function makeGetSet(unit, keepTime) { |
|
923 return function (value) { |
|
924 if (value != null) { |
|
925 set$1(this, unit, value); |
|
926 hooks.updateOffset(this, keepTime); |
|
927 return this; |
|
928 } else { |
|
929 return get(this, unit); |
|
930 } |
|
931 }; |
|
932 } |
|
933 |
|
934 function get(mom, unit) { |
|
935 if (!mom.isValid()) { |
|
936 return NaN; |
|
937 } |
|
938 |
|
939 var d = mom._d, |
|
940 isUTC = mom._isUTC; |
|
941 |
|
942 switch (unit) { |
|
943 case 'Milliseconds': |
|
944 return isUTC ? d.getUTCMilliseconds() : d.getMilliseconds(); |
|
945 case 'Seconds': |
|
946 return isUTC ? d.getUTCSeconds() : d.getSeconds(); |
|
947 case 'Minutes': |
|
948 return isUTC ? d.getUTCMinutes() : d.getMinutes(); |
|
949 case 'Hours': |
|
950 return isUTC ? d.getUTCHours() : d.getHours(); |
|
951 case 'Date': |
|
952 return isUTC ? d.getUTCDate() : d.getDate(); |
|
953 case 'Day': |
|
954 return isUTC ? d.getUTCDay() : d.getDay(); |
|
955 case 'Month': |
|
956 return isUTC ? d.getUTCMonth() : d.getMonth(); |
|
957 case 'FullYear': |
|
958 return isUTC ? d.getUTCFullYear() : d.getFullYear(); |
|
959 default: |
|
960 return NaN; // Just in case |
|
961 } |
|
962 } |
|
963 |
|
964 function set$1(mom, unit, value) { |
|
965 var d, isUTC, year, month, date; |
|
966 |
|
967 if (!mom.isValid() || isNaN(value)) { |
|
968 return; |
|
969 } |
|
970 |
|
971 d = mom._d; |
|
972 isUTC = mom._isUTC; |
|
973 |
|
974 switch (unit) { |
|
975 case 'Milliseconds': |
|
976 return void (isUTC |
|
977 ? d.setUTCMilliseconds(value) |
|
978 : d.setMilliseconds(value)); |
|
979 case 'Seconds': |
|
980 return void (isUTC ? d.setUTCSeconds(value) : d.setSeconds(value)); |
|
981 case 'Minutes': |
|
982 return void (isUTC ? d.setUTCMinutes(value) : d.setMinutes(value)); |
|
983 case 'Hours': |
|
984 return void (isUTC ? d.setUTCHours(value) : d.setHours(value)); |
|
985 case 'Date': |
|
986 return void (isUTC ? d.setUTCDate(value) : d.setDate(value)); |
|
987 // case 'Day': // Not real |
|
988 // return void (isUTC ? d.setUTCDay(value) : d.setDay(value)); |
|
989 // case 'Month': // Not used because we need to pass two variables |
|
990 // return void (isUTC ? d.setUTCMonth(value) : d.setMonth(value)); |
|
991 case 'FullYear': |
|
992 break; // See below ... |
|
993 default: |
|
994 return; // Just in case |
|
995 } |
|
996 |
|
997 year = value; |
|
998 month = mom.month(); |
|
999 date = mom.date(); |
|
1000 date = date === 29 && month === 1 && !isLeapYear(year) ? 28 : date; |
|
1001 void (isUTC |
|
1002 ? d.setUTCFullYear(year, month, date) |
|
1003 : d.setFullYear(year, month, date)); |
|
1004 } |
|
1005 |
|
1006 // MOMENTS |
|
1007 |
|
1008 function stringGet(units) { |
|
1009 units = normalizeUnits(units); |
|
1010 if (isFunction(this[units])) { |
|
1011 return this[units](); |
|
1012 } |
|
1013 return this; |
|
1014 } |
|
1015 |
|
1016 function stringSet(units, value) { |
|
1017 if (typeof units === 'object') { |
|
1018 units = normalizeObjectUnits(units); |
|
1019 var prioritized = getPrioritizedUnits(units), |
|
1020 i, |
|
1021 prioritizedLen = prioritized.length; |
|
1022 for (i = 0; i < prioritizedLen; i++) { |
|
1023 this[prioritized[i].unit](units[prioritized[i].unit]); |
|
1024 } |
|
1025 } else { |
|
1026 units = normalizeUnits(units); |
|
1027 if (isFunction(this[units])) { |
|
1028 return this[units](value); |
|
1029 } |
|
1030 } |
|
1031 return this; |
|
1032 } |
873 |
1033 |
874 function mod(n, x) { |
1034 function mod(n, x) { |
875 return ((n % x) + x) % x; |
1035 return ((n % x) + x) % x; |
876 } |
1036 } |
877 |
1037 |
917 |
1077 |
918 addFormatToken('MMMM', 0, 0, function (format) { |
1078 addFormatToken('MMMM', 0, 0, function (format) { |
919 return this.localeData().months(this, format); |
1079 return this.localeData().months(this, format); |
920 }); |
1080 }); |
921 |
1081 |
922 // ALIASES |
|
923 |
|
924 addUnitAlias('month', 'M'); |
|
925 |
|
926 // PRIORITY |
|
927 |
|
928 addUnitPriority('month', 8); |
|
929 |
|
930 // PARSING |
1082 // PARSING |
931 |
1083 |
932 addRegexToken('M', match1to2); |
1084 addRegexToken('M', match1to2, match1to2NoLeadingZero); |
933 addRegexToken('MM', match1to2, match2); |
1085 addRegexToken('MM', match1to2, match2); |
934 addRegexToken('MMM', function (isStrict, locale) { |
1086 addRegexToken('MMM', function (isStrict, locale) { |
935 return locale.monthsShortRegex(isStrict); |
1087 return locale.monthsShortRegex(isStrict); |
936 }); |
1088 }); |
937 addRegexToken('MMMM', function (isStrict, locale) { |
1089 addRegexToken('MMMM', function (isStrict, locale) { |
1180 |
1335 |
1181 var shortPieces = [], |
1336 var shortPieces = [], |
1182 longPieces = [], |
1337 longPieces = [], |
1183 mixedPieces = [], |
1338 mixedPieces = [], |
1184 i, |
1339 i, |
1185 mom; |
1340 mom, |
|
1341 shortP, |
|
1342 longP; |
1186 for (i = 0; i < 12; i++) { |
1343 for (i = 0; i < 12; i++) { |
1187 // make the regex if we don't have it already |
1344 // make the regex if we don't have it already |
1188 mom = createUTC([2000, i]); |
1345 mom = createUTC([2000, i]); |
1189 shortPieces.push(this.monthsShort(mom, '')); |
1346 shortP = regexEscape(this.monthsShort(mom, '')); |
1190 longPieces.push(this.months(mom, '')); |
1347 longP = regexEscape(this.months(mom, '')); |
1191 mixedPieces.push(this.months(mom, '')); |
1348 shortPieces.push(shortP); |
1192 mixedPieces.push(this.monthsShort(mom, '')); |
1349 longPieces.push(longP); |
|
1350 mixedPieces.push(longP); |
|
1351 mixedPieces.push(shortP); |
1193 } |
1352 } |
1194 // Sorting makes sure if one month (or abbr) is a prefix of another it |
1353 // Sorting makes sure if one month (or abbr) is a prefix of another it |
1195 // will match the longer piece. |
1354 // will match the longer piece. |
1196 shortPieces.sort(cmpLenRev); |
1355 shortPieces.sort(cmpLenRev); |
1197 longPieces.sort(cmpLenRev); |
1356 longPieces.sort(cmpLenRev); |
1198 mixedPieces.sort(cmpLenRev); |
1357 mixedPieces.sort(cmpLenRev); |
1199 for (i = 0; i < 12; i++) { |
|
1200 shortPieces[i] = regexEscape(shortPieces[i]); |
|
1201 longPieces[i] = regexEscape(longPieces[i]); |
|
1202 } |
|
1203 for (i = 0; i < 24; i++) { |
|
1204 mixedPieces[i] = regexEscape(mixedPieces[i]); |
|
1205 } |
|
1206 |
1358 |
1207 this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); |
1359 this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); |
1208 this._monthsShortRegex = this._monthsRegex; |
1360 this._monthsShortRegex = this._monthsRegex; |
1209 this._monthsStrictRegex = new RegExp( |
1361 this._monthsStrictRegex = new RegExp( |
1210 '^(' + longPieces.join('|') + ')', |
1362 '^(' + longPieces.join('|') + ')', |
1214 '^(' + shortPieces.join('|') + ')', |
1366 '^(' + shortPieces.join('|') + ')', |
1215 'i' |
1367 'i' |
1216 ); |
1368 ); |
1217 } |
1369 } |
1218 |
1370 |
1219 // FORMATTING |
|
1220 |
|
1221 addFormatToken('Y', 0, 0, function () { |
|
1222 var y = this.year(); |
|
1223 return y <= 9999 ? zeroFill(y, 4) : '+' + y; |
|
1224 }); |
|
1225 |
|
1226 addFormatToken(0, ['YY', 2], 0, function () { |
|
1227 return this.year() % 100; |
|
1228 }); |
|
1229 |
|
1230 addFormatToken(0, ['YYYY', 4], 0, 'year'); |
|
1231 addFormatToken(0, ['YYYYY', 5], 0, 'year'); |
|
1232 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year'); |
|
1233 |
|
1234 // ALIASES |
|
1235 |
|
1236 addUnitAlias('year', 'y'); |
|
1237 |
|
1238 // PRIORITIES |
|
1239 |
|
1240 addUnitPriority('year', 1); |
|
1241 |
|
1242 // PARSING |
|
1243 |
|
1244 addRegexToken('Y', matchSigned); |
|
1245 addRegexToken('YY', match1to2, match2); |
|
1246 addRegexToken('YYYY', match1to4, match4); |
|
1247 addRegexToken('YYYYY', match1to6, match6); |
|
1248 addRegexToken('YYYYYY', match1to6, match6); |
|
1249 |
|
1250 addParseToken(['YYYYY', 'YYYYYY'], YEAR); |
|
1251 addParseToken('YYYY', function (input, array) { |
|
1252 array[YEAR] = |
|
1253 input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input); |
|
1254 }); |
|
1255 addParseToken('YY', function (input, array) { |
|
1256 array[YEAR] = hooks.parseTwoDigitYear(input); |
|
1257 }); |
|
1258 addParseToken('Y', function (input, array) { |
|
1259 array[YEAR] = parseInt(input, 10); |
|
1260 }); |
|
1261 |
|
1262 // HELPERS |
|
1263 |
|
1264 function daysInYear(year) { |
|
1265 return isLeapYear(year) ? 366 : 365; |
|
1266 } |
|
1267 |
|
1268 // HOOKS |
|
1269 |
|
1270 hooks.parseTwoDigitYear = function (input) { |
|
1271 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000); |
|
1272 }; |
|
1273 |
|
1274 // MOMENTS |
|
1275 |
|
1276 var getSetYear = makeGetSet('FullYear', true); |
|
1277 |
|
1278 function getIsLeapYear() { |
|
1279 return isLeapYear(this.year()); |
|
1280 } |
|
1281 |
|
1282 function createDate(y, m, d, h, M, s, ms) { |
1371 function createDate(y, m, d, h, M, s, ms) { |
1283 // can't just apply() to create a date: |
1372 // can't just apply() to create a date: |
1284 // https://stackoverflow.com/q/181348 |
1373 // https://stackoverflow.com/q/181348 |
1285 var date; |
1374 var date; |
1286 // the date constructor remaps years 0-99 to 1900-1999 |
1375 // the date constructor remaps years 0-99 to 1900-1999 |
1382 // FORMATTING |
1471 // FORMATTING |
1383 |
1472 |
1384 addFormatToken('w', ['ww', 2], 'wo', 'week'); |
1473 addFormatToken('w', ['ww', 2], 'wo', 'week'); |
1385 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek'); |
1474 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek'); |
1386 |
1475 |
1387 // ALIASES |
|
1388 |
|
1389 addUnitAlias('week', 'w'); |
|
1390 addUnitAlias('isoWeek', 'W'); |
|
1391 |
|
1392 // PRIORITIES |
|
1393 |
|
1394 addUnitPriority('week', 5); |
|
1395 addUnitPriority('isoWeek', 5); |
|
1396 |
|
1397 // PARSING |
1476 // PARSING |
1398 |
1477 |
1399 addRegexToken('w', match1to2); |
1478 addRegexToken('w', match1to2, match1to2NoLeadingZero); |
1400 addRegexToken('ww', match1to2, match2); |
1479 addRegexToken('ww', match1to2, match2); |
1401 addRegexToken('W', match1to2); |
1480 addRegexToken('W', match1to2, match1to2NoLeadingZero); |
1402 addRegexToken('WW', match1to2, match2); |
1481 addRegexToken('WW', match1to2, match2); |
1403 |
1482 |
1404 addWeekParseToken( |
1483 addWeekParseToken( |
1405 ['w', 'ww', 'W', 'WW'], |
1484 ['w', 'ww', 'W', 'WW'], |
1406 function (input, week, config, token) { |
1485 function (input, week, config, token) { |
1457 return this.localeData().weekdays(this, format); |
1536 return this.localeData().weekdays(this, format); |
1458 }); |
1537 }); |
1459 |
1538 |
1460 addFormatToken('e', 0, 0, 'weekday'); |
1539 addFormatToken('e', 0, 0, 'weekday'); |
1461 addFormatToken('E', 0, 0, 'isoWeekday'); |
1540 addFormatToken('E', 0, 0, 'isoWeekday'); |
1462 |
|
1463 // ALIASES |
|
1464 |
|
1465 addUnitAlias('day', 'd'); |
|
1466 addUnitAlias('weekday', 'e'); |
|
1467 addUnitAlias('isoWeekday', 'E'); |
|
1468 |
|
1469 // PRIORITY |
|
1470 addUnitPriority('day', 11); |
|
1471 addUnitPriority('weekday', 11); |
|
1472 addUnitPriority('isoWeekday', 11); |
|
1473 |
1541 |
1474 // PARSING |
1542 // PARSING |
1475 |
1543 |
1476 addRegexToken('d', match1to2); |
1544 addRegexToken('d', match1to2); |
1477 addRegexToken('e', match1to2); |
1545 addRegexToken('e', match1to2); |
1548 : 'standalone' |
1616 : 'standalone' |
1549 ]; |
1617 ]; |
1550 return m === true |
1618 return m === true |
1551 ? shiftWeekdays(weekdays, this._week.dow) |
1619 ? shiftWeekdays(weekdays, this._week.dow) |
1552 : m |
1620 : m |
1553 ? weekdays[m.day()] |
1621 ? weekdays[m.day()] |
1554 : weekdays; |
1622 : weekdays; |
1555 } |
1623 } |
1556 |
1624 |
1557 function localeWeekdaysShort(m) { |
1625 function localeWeekdaysShort(m) { |
1558 return m === true |
1626 return m === true |
1559 ? shiftWeekdays(this._weekdaysShort, this._week.dow) |
1627 ? shiftWeekdays(this._weekdaysShort, this._week.dow) |
1560 : m |
1628 : m |
1561 ? this._weekdaysShort[m.day()] |
1629 ? this._weekdaysShort[m.day()] |
1562 : this._weekdaysShort; |
1630 : this._weekdaysShort; |
1563 } |
1631 } |
1564 |
1632 |
1565 function localeWeekdaysMin(m) { |
1633 function localeWeekdaysMin(m) { |
1566 return m === true |
1634 return m === true |
1567 ? shiftWeekdays(this._weekdaysMin, this._week.dow) |
1635 ? shiftWeekdays(this._weekdaysMin, this._week.dow) |
1568 : m |
1636 : m |
1569 ? this._weekdaysMin[m.day()] |
1637 ? this._weekdaysMin[m.day()] |
1570 : this._weekdaysMin; |
1638 : this._weekdaysMin; |
1571 } |
1639 } |
1572 |
1640 |
1573 function handleStrictParse$1(weekdayName, format, strict) { |
1641 function handleStrictParse$1(weekdayName, format, strict) { |
1574 var i, |
1642 var i, |
1575 ii, |
1643 ii, |
1913 } |
1982 } |
1914 |
1983 |
1915 meridiem('a', true); |
1984 meridiem('a', true); |
1916 meridiem('A', false); |
1985 meridiem('A', false); |
1917 |
1986 |
1918 // ALIASES |
|
1919 |
|
1920 addUnitAlias('hour', 'h'); |
|
1921 |
|
1922 // PRIORITY |
|
1923 addUnitPriority('hour', 13); |
|
1924 |
|
1925 // PARSING |
1987 // PARSING |
1926 |
1988 |
1927 function matchMeridiem(isStrict, locale) { |
1989 function matchMeridiem(isStrict, locale) { |
1928 return locale._meridiemParse; |
1990 return locale._meridiemParse; |
1929 } |
1991 } |
1930 |
1992 |
1931 addRegexToken('a', matchMeridiem); |
1993 addRegexToken('a', matchMeridiem); |
1932 addRegexToken('A', matchMeridiem); |
1994 addRegexToken('A', matchMeridiem); |
1933 addRegexToken('H', match1to2); |
1995 addRegexToken('H', match1to2, match1to2HasZero); |
1934 addRegexToken('h', match1to2); |
1996 addRegexToken('h', match1to2, match1to2NoLeadingZero); |
1935 addRegexToken('k', match1to2); |
1997 addRegexToken('k', match1to2, match1to2NoLeadingZero); |
1936 addRegexToken('HH', match1to2, match2); |
1998 addRegexToken('HH', match1to2, match2); |
1937 addRegexToken('hh', match1to2, match2); |
1999 addRegexToken('hh', match1to2, match2); |
1938 addRegexToken('kk', match1to2, match2); |
2000 addRegexToken('kk', match1to2, match2); |
1939 |
2001 |
1940 addRegexToken('hmm', match3to4); |
2002 addRegexToken('hmm', match3to4); |
4544 namePieces = [], |
4607 namePieces = [], |
4545 narrowPieces = [], |
4608 narrowPieces = [], |
4546 mixedPieces = [], |
4609 mixedPieces = [], |
4547 i, |
4610 i, |
4548 l, |
4611 l, |
|
4612 erasName, |
|
4613 erasAbbr, |
|
4614 erasNarrow, |
4549 eras = this.eras(); |
4615 eras = this.eras(); |
4550 |
4616 |
4551 for (i = 0, l = eras.length; i < l; ++i) { |
4617 for (i = 0, l = eras.length; i < l; ++i) { |
4552 namePieces.push(regexEscape(eras[i].name)); |
4618 erasName = regexEscape(eras[i].name); |
4553 abbrPieces.push(regexEscape(eras[i].abbr)); |
4619 erasAbbr = regexEscape(eras[i].abbr); |
4554 narrowPieces.push(regexEscape(eras[i].narrow)); |
4620 erasNarrow = regexEscape(eras[i].narrow); |
4555 |
4621 |
4556 mixedPieces.push(regexEscape(eras[i].name)); |
4622 namePieces.push(erasName); |
4557 mixedPieces.push(regexEscape(eras[i].abbr)); |
4623 abbrPieces.push(erasAbbr); |
4558 mixedPieces.push(regexEscape(eras[i].narrow)); |
4624 narrowPieces.push(erasNarrow); |
|
4625 mixedPieces.push(erasName); |
|
4626 mixedPieces.push(erasAbbr); |
|
4627 mixedPieces.push(erasNarrow); |
4559 } |
4628 } |
4560 |
4629 |
4561 this._erasRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); |
4630 this._erasRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); |
4562 this._erasNameRegex = new RegExp('^(' + namePieces.join('|') + ')', 'i'); |
4631 this._erasNameRegex = new RegExp('^(' + namePieces.join('|') + ')', 'i'); |
4563 this._erasAbbrRegex = new RegExp('^(' + abbrPieces.join('|') + ')', 'i'); |
4632 this._erasAbbrRegex = new RegExp('^(' + abbrPieces.join('|') + ')', 'i'); |
4712 |
4765 |
4713 // FORMATTING |
4766 // FORMATTING |
4714 |
4767 |
4715 addFormatToken('D', ['DD', 2], 'Do', 'date'); |
4768 addFormatToken('D', ['DD', 2], 'Do', 'date'); |
4716 |
4769 |
4717 // ALIASES |
|
4718 |
|
4719 addUnitAlias('date', 'D'); |
|
4720 |
|
4721 // PRIORITY |
|
4722 addUnitPriority('date', 9); |
|
4723 |
|
4724 // PARSING |
4770 // PARSING |
4725 |
4771 |
4726 addRegexToken('D', match1to2); |
4772 addRegexToken('D', match1to2, match1to2NoLeadingZero); |
4727 addRegexToken('DD', match1to2, match2); |
4773 addRegexToken('DD', match1to2, match2); |
4728 addRegexToken('Do', function (isStrict, locale) { |
4774 addRegexToken('Do', function (isStrict, locale) { |
4729 // TODO: Remove "ordinalParse" fallback in next major release. |
4775 // TODO: Remove "ordinalParse" fallback in next major release. |
4730 return isStrict |
4776 return isStrict |
4731 ? locale._dayOfMonthOrdinalParse || locale._ordinalParse |
4777 ? locale._dayOfMonthOrdinalParse || locale._ordinalParse |