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

Function jsonStringToDate

test/angular/1.6/angular-mocks.js:586–608  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

584
585
586function jsonStringToDate(string) {
587 // The R_ISO8061_STR regex is never going to fit into the 100 char limit!
588 // eslit-disable-next-line max-len
589 var R_ISO8061_STR = /^(-?\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
590
591 var match;
592 if ((match = string.match(R_ISO8061_STR))) {
593 var date = new Date(0),
594 tzHour = 0,
595 tzMin = 0;
596 if (match[9]) {
597 tzHour = toInt(match[9] + match[10]);
598 tzMin = toInt(match[9] + match[11]);
599 }
600 date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
601 date.setUTCHours(toInt(match[4] || 0) - tzHour,
602 toInt(match[5] || 0) - tzMin,
603 toInt(match[6] || 0),
604 toInt(match[7] || 0));
605 return date;
606 }
607 return string;
608}
609
610function toInt(str) {
611 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