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

Function jsonStringToDate

test/angular/1.4/angular-mocks.js:557–575  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

555var R_ISO8061_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?:\:?(\d\d)(?:\:?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
556
557function jsonStringToDate(string) {
558 var match;
559 if (match = string.match(R_ISO8061_STR)) {
560 var date = new Date(0),
561 tzHour = 0,
562 tzMin = 0;
563 if (match[9]) {
564 tzHour = toInt(match[9] + match[10]);
565 tzMin = toInt(match[9] + match[11]);
566 }
567 date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
568 date.setUTCHours(toInt(match[4] || 0) - tzHour,
569 toInt(match[5] || 0) - tzMin,
570 toInt(match[6] || 0),
571 toInt(match[7] || 0));
572 return date;
573 }
574 return string;
575}
576
577function toInt(str) {
578 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