From 98ad301f975a8ea8d8888262934863dd2a23aa43 Mon Sep 17 00:00:00 2001 From: Xotic750 Date: Mon, 16 Sep 2013 18:02:34 +0200 Subject: [PATCH] Improve dateFromObject to utilise the normalizedUnits method. User object will now handle any acceptable capitalisation, aliasing or pluralisation. --- moment.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/moment.js b/moment.js index 34f22fcc2..de252f803 100644 --- a/moment.js +++ b/moment.js @@ -854,20 +854,32 @@ } function dateFromObject(config) { - var o = config._i; + var normalizedInput = {}, + normalizedProp, + prop, + index; if (config._d) { return; } + for (prop in config._i) { + if (config._i.hasOwnProperty(prop)) { + normalizedProp = normalizeUnits(prop); + if (normalizedProp) { + normalizedInput[normalizedProp] = config._i[prop]; + } + } + } + config._a = [ - o.years || o.year || o.y, - o.months || o.month || o.M, - o.days || o.day || o.d, - o.hours || o.hour || o.h, - o.minutes || o.minute || o.m, - o.seconds || o.second || o.s, - o.milliseconds || o.millisecond || o.ms + normalizedInput.year, + normalizedInput.month, + normalizedInput.day, + normalizedInput.hour, + normalizedInput.minute, + normalizedInput.second, + normalizedInput.millisecond ]; dateFromArray(config); -- 2.47.2