MCPcopy
hub / github.com/angular-ui/ui-router / jsonStringToDate

Function jsonStringToDate

test/angular/1.5/angular-mocks.js:561–583  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

559
560
561function jsonStringToDate(string) {
562 // The R_ISO8061_STR regex is never going to fit into the 100 char limit!
563 // eslit-disable-next-line max-len
564 var R_ISO8061_STR = /^(-?\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
565
566 var match;
567 if ((match = string.match(R_ISO8061_STR))) {
568 var date = new Date(0),
569 tzHour = 0,
570 tzMin = 0;
571 if (match[9]) {
572 tzHour = toInt(match[9] + match[10]);
573 tzMin = toInt(match[9] + match[11]);
574 }
575 date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
576 date.setUTCHours(toInt(match[4] || 0) - tzHour,
577 toInt(match[5] || 0) - tzMin,
578 toInt(match[6] || 0),
579 toInt(match[7] || 0));
580 return date;
581 }
582 return string;
583}
584
585function toInt(str) {
586 return parseInt(str, 10);

Callers 1

angular-mocks.jsFile · 0.70

Calls 2

matchMethod · 0.80
toIntFunction · 0.70

Tested by

no test coverage detected