Skip to content

Commit

Permalink
toDate implementation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
leshakoss committed Apr 4, 2017
1 parent 57c0bfb commit fefcf91
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/toDate/index.js
Expand Up @@ -62,6 +62,7 @@ var patterns = {
* @param {Options} [options] - the object with options. See [Options]{@link docs/Options}
* @param {0|1|2} [options.additionalDigits=2] - the additional number of digits in the extended year format
* @returns {Date} the parsed date in the local time zone
* @throws {RangeError} additionalDigits must be 0, 1 or 2
*
* @example
* // Convert string '2014-02-11T11:30:30' to date:
Expand All @@ -75,6 +76,13 @@ var patterns = {
* //=> Fri Apr 11 2014 00:00:00
*/
export default function toDate (argument, dirtyOptions) {
var options = dirtyOptions || {}

var additionalDigits = options.additionalDigits === undefined ? DEFAULT_ADDITIONAL_DIGITS : Number(options.additionalDigits)
if (additionalDigits !== 2 && additionalDigits !== 1 && additionalDigits !== 0) {
throw new RangeError('additionalDigits must be 0, 1 or 2')
}

// Clone the date
if (isDate(argument)) {
// Prevent the date to lose the milliseconds when passed to new Date() in IE10
Expand All @@ -83,14 +91,6 @@ export default function toDate (argument, dirtyOptions) {
return new Date(argument)
}

var options = dirtyOptions || {}
var additionalDigits = options.additionalDigits
if (additionalDigits == null) {
additionalDigits = DEFAULT_ADDITIONAL_DIGITS
} else {
additionalDigits = Number(additionalDigits)
}

var dateStrings = splitDateString(argument)

var parseYearResult = parseYear(dateStrings.date, additionalDigits)
Expand Down

0 comments on commit fefcf91

Please sign in to comment.