From: Tim Wood Date: Thu, 22 Jan 2015 16:49:38 +0000 (-0800) Subject: Finish a bunch of TODOs X-Git-Tag: 2.10.2~15^2~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb4c014f46f3bf9291b3658efcfddade95a939b9;p=thirdparty%2Fmoment.git Finish a bunch of TODOs --- diff --git a/lib/units/day-of-month.js b/lib/units/day-of-month.js index bd58d5cdc..bc50abee2 100644 --- a/lib/units/day-of-month.js +++ b/lib/units/day-of-month.js @@ -3,6 +3,7 @@ import { addFormatToken } from "../format/format"; import { addUnitAlias } from "./aliases"; import { addRegexToken, match1to2, match2 } from "../parse/regex"; import { addParseToken } from "../parse/token"; +import { DATE } from "./constants"; import toInt from "../utils/to-int"; // FORMATTING @@ -21,9 +22,9 @@ addRegexToken("Do", function (isStrict, locale) { return isStrict ? locale._ordinalParse : locale._ordinalParseLenient; }); -addParseToken(["D", "DD"], 2); // TODO: use a constant for DATE +addParseToken(["D", "DD"], DATE); addParseToken("Do", function (input, array) { - array[2] = toInt(input.match(match1to2)[0], 10); // TODO: use a constant for DATE + array[DATE] = toInt(input.match(match1to2)[0], 10); }); // MOMENTS diff --git a/lib/units/hour.js b/lib/units/hour.js index d8d7c6015..0b926ee49 100644 --- a/lib/units/hour.js +++ b/lib/units/hour.js @@ -3,6 +3,7 @@ import { addFormatToken } from "../format/format"; import { addUnitAlias } from "./aliases"; import { addRegexToken, match1to2, match2 } from "../parse/regex"; import { addParseToken } from "../parse/token"; +import { HOUR } from "./constants"; import toInt from "../utils/to-int"; // FORMATTING @@ -38,13 +39,13 @@ addRegexToken("h", match1to2); addRegexToken("HH", match1to2, match2); addRegexToken("hh", match1to2, match2); -addParseToken(["H", "HH"], 3); // TODO: use a constant for HOUR +addParseToken(["H", "HH"], HOUR); addParseToken(["a", "A"], function (input, array, config) { config._isPm = config._locale.isPM(input); config._meridiem = input; }); addParseToken(["h", "hh"], function (input, array, config) { - array[3] = toInt(input); // TODO: use a constant for HOUR + array[HOUR] = toInt(input); config._pf.bigHour = true; }); diff --git a/lib/units/millisecond.js b/lib/units/millisecond.js index 2dac76916..3e9c3793d 100644 --- a/lib/units/millisecond.js +++ b/lib/units/millisecond.js @@ -3,6 +3,7 @@ import { addFormatToken } from "../format/format"; import { addUnitAlias } from "./aliases"; import { addRegexToken, match1, match2, match3, match1to3, matchUnsigned } from "../parse/regex"; import { addParseToken } from "../parse/token"; +import { MILLISECOND } from "./constants"; import toInt from "../utils/to-int"; // FORMATTING @@ -33,7 +34,7 @@ addRegexToken("SS", match1to3, match2); addRegexToken("SSS", match1to3, match3); addRegexToken("SSSS", matchUnsigned); addParseToken(["S", "SS", "SSS", "SSSS"], function (input, array) { - array[6] = toInt(('0.' + input) * 1000); // TODO: use a constant for MILLISECOND + array[MILLISECOND] = toInt(('0.' + input) * 1000); }); // MOMENTS diff --git a/lib/units/minute.js b/lib/units/minute.js index c3b681f79..dfea040c2 100644 --- a/lib/units/minute.js +++ b/lib/units/minute.js @@ -3,6 +3,7 @@ import { addFormatToken } from "../format/format"; import { addUnitAlias } from "./aliases"; import { addRegexToken, match1to2, match2 } from "../parse/regex"; import { addParseToken } from "../parse/token"; +import { MINUTE } from "./constants"; // FORMATTING @@ -16,7 +17,7 @@ addUnitAlias("minute", "m"); addRegexToken("m", match1to2); addRegexToken("mm", match1to2, match2); -addParseToken(["m", "mm"], 4); // TODO: use a constant for MINUTE +addParseToken(["m", "mm"], MINUTE); // MOMENTS diff --git a/lib/units/month.js b/lib/units/month.js index b183e875b..d59eb35af 100644 --- a/lib/units/month.js +++ b/lib/units/month.js @@ -4,6 +4,7 @@ import { addUnitAlias } from "./aliases"; import { addRegexToken, match1to2, match2, matchWord } from "../parse/regex"; import { addParseToken } from "../parse/token"; import { hooks } from "../utils/hooks"; +import { MONTH } from "./constants"; import toInt from "../utils/to-int"; import { createUTC } from "../create/utc"; @@ -37,14 +38,14 @@ addRegexToken("MMM", matchWord); addRegexToken("MMMM", matchWord); addParseToken(["M", "MM"], function (input, array) { - array[1] = toInt(input) - 1; // TODO: use a constant for MONTH + array[MONTH] = toInt(input) - 1; }); addParseToken(["MMM", "MMMM"], function (input, array, config, token) { var month = config._locale.monthsParse(input, token, config._strict); // if we didn't find a month name, mark the date as invalid. if (month != null) { - array[1] = month; // TODO: use a constant for MONTH + array[MONTH] = month; } else { config._pf.invalidMonth = input; } diff --git a/lib/units/quarter.js b/lib/units/quarter.js index d7df2582c..c0dc4214b 100644 --- a/lib/units/quarter.js +++ b/lib/units/quarter.js @@ -2,6 +2,7 @@ import { addFormatToken } from "../format/format"; import { addUnitAlias } from "./aliases"; import { addRegexToken, match1 } from "../parse/regex"; import { addParseToken } from "../parse/token"; +import { MONTH } from "./constants"; import toInt from "../utils/to-int"; // FORMATTING @@ -16,7 +17,7 @@ addUnitAlias("quarter", "Q"); addRegexToken("Q", match1); addParseToken("Q", function (input, array) { - array[1] = (toInt(input) - 1) * 3; // TODO: use a constant for MONTH + array[MONTH] = (toInt(input) - 1) * 3; }); // MOMENTS diff --git a/lib/units/second.js b/lib/units/second.js index 8cab5af6d..8eaa35a7b 100644 --- a/lib/units/second.js +++ b/lib/units/second.js @@ -3,6 +3,7 @@ import { addFormatToken } from "../format/format"; import { addUnitAlias } from "./aliases"; import { addRegexToken, match1to2, match2 } from "../parse/regex"; import { addParseToken } from "../parse/token"; +import { SECOND } from "./constants"; // FORMATTING @@ -16,7 +17,7 @@ addUnitAlias("second", "s"); addRegexToken("s", match1to2); addRegexToken("ss", match1to2, match2); -addParseToken(["s", "ss"], 5); // TODO: use a constant for SECOND +addParseToken(["s", "ss"], SECOND); // MOMENTS diff --git a/lib/units/year.js b/lib/units/year.js index 8b85b86a9..94dd0ca72 100644 --- a/lib/units/year.js +++ b/lib/units/year.js @@ -4,6 +4,7 @@ import { addUnitAlias } from "./aliases"; import { addRegexToken, match1to2, match1to4, match1to6, match2, match4, match6, matchSigned } from "../parse/regex"; import { addParseToken } from "../parse/token"; import { hooks } from "../utils/hooks"; +import { YEAR } from "./constants"; import toInt from "../utils/to-int"; // FORMATTING @@ -28,9 +29,9 @@ addRegexToken("YYYY", match1to4, match4); addRegexToken("YYYYY", match1to6, match6); addRegexToken("YYYYYY", match1to6, match6); -addParseToken(["YYYY", "YYYYY", "YYYYYY"], 0); +addParseToken(["YYYY", "YYYYY", "YYYYYY"], YEAR); addParseToken("YY", function (input, array) { - array[0] = hooks.parseTwoDigitYear(input); + array[YEAR] = hooks.parseTwoDigitYear(input); }); // HELPERS