All files / validator/yupSource/util isodate.js

73.68% Statements 14/19
45.83% Branches 11/24
100% Functions 1/1
75% Lines 12/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                      3x     2x 2x       2x   14x     2x 2x     2x     2x                           2x           2x                       2x    
/* eslint-disable */
/**
 *
 * Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
 * NON-CONFORMANT EDITION.
 * © 2011 Colin Snover <http://zetafleet.com>
 * Released under MIT license.
 */
 
//              1 YYYY                 2 MM        3 DD              4 HH     5 mm        6 ss            7 msec         8 Z 9 ±    10 tzHH    11 tzmm
var isoReg =
  /^(\d{4}|[+\-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,\.](\d{1,}))?)?(?:(Z)|([+\-])(\d{2})(?::?(\d{2}))?)?)?$/
 
export default function parseIsoDate(date) {
  var numericKeys = [1, 4, 5, 6, 7, 10, 11],
    minutesOffset = 0,
    timestamp,
    struct
 
  if ((struct = isoReg.exec(date))) {
    // avoid NaN timestamps caused by “undefined” values being passed to Date.UTC
    for (var i = 0, k; (k = numericKeys[i]); ++i) struct[k] = +struct[k] || 0
 
    // allow undefined days and months
    struct[2] = (+struct[2] || 1) - 1
    struct[3] = +struct[3] || 1
 
    // allow arbitrary sub-second precision beyond milliseconds
    struct[7] = struct[7] ? String(struct[7]).substr(0, 3) : 0
 
    // timestamps without timezone identifiers should be considered local time
    Iif (
      (struct[8] === undefined || struct[8] === '') &&
      (struct[9] === undefined || struct[9] === '')
    )
      timestamp = +new Date(
        struct[1],
        struct[2],
        struct[3],
        struct[4],
        struct[5],
        struct[6],
        struct[7],
      )
    else {
      Iif (struct[8] !== 'Z' && struct[9] !== undefined) {
        minutesOffset = struct[10] * 60 + struct[11]
 
        if (struct[9] === '+') minutesOffset = 0 - minutesOffset
      }
 
      timestamp = Date.UTC(
        struct[1],
        struct[2],
        struct[3],
        struct[4],
        struct[5] + minutesOffset,
        struct[6],
        struct[7],
      )
    }
  } else Etimestamp = Date.parse ? Date.parse(date) : NaN
 
  return timestamp
}