Skip to content

Commit

Permalink
Finish a bunch of TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood authored and ichernev committed Mar 25, 2015
1 parent e76a66b commit eb4c014
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lib/units/day-of-month.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/units/hour.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
});

Expand Down
3 changes: 2 additions & 1 deletion lib/units/millisecond.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/units/minute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions lib/units/month.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/units/quarter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/units/second.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions lib/units/year.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit eb4c014

Please sign in to comment.