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

Function jsonStringToDate

test/angular/1.3/angular-mocks.js:577–595  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

575var R_ISO8061_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?:\:?(\d\d)(?:\:?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
576
577function jsonStringToDate(string) {
578 var match;
579 if (match = string.match(R_ISO8061_STR)) {
580 var date = new Date(0),
581 tzHour = 0,
582 tzMin = 0;
583 if (match[9]) {
584 tzHour = int(match[9] + match[10]);
585 tzMin = int(match[9] + match[11]);
586 }
587 date.setUTCFullYear(int(match[1]), int(match[2]) - 1, int(match[3]));
588 date.setUTCHours(int(match[4] || 0) - tzHour,
589 int(match[5] || 0) - tzMin,
590 int(match[6] || 0),
591 int(match[7] || 0));
592 return date;
593 }
594 return string;
595}
596
597function int(str) {
598 return parseInt(str, 10);

Callers 1

angular-mocks.jsFile · 0.70

Calls 2

matchMethod · 0.80
intFunction · 0.70

Tested by

no test coverage detected