MCPcopy Index your code
hub / github.com/angular-ui/ui-router / jsonStringToDate

Function jsonStringToDate

test/angular/1.4/angular.js:19478–19500  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

19476 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
19477 // 1 2 3 4 5 6 7 8 9 10 11
19478 function jsonStringToDate(string) {
19479 var match;
19480 if (match = string.match(R_ISO8601_STR)) {
19481 var date = new Date(0),
19482 tzHour = 0,
19483 tzMin = 0,
19484 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
19485 timeSetter = match[8] ? date.setUTCHours : date.setHours;
19486
19487 if (match[9]) {
19488 tzHour = toInt(match[9] + match[10]);
19489 tzMin = toInt(match[9] + match[11]);
19490 }
19491 dateSetter.call(date, toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
19492 var h = toInt(match[4] || 0) - tzHour;
19493 var m = toInt(match[5] || 0) - tzMin;
19494 var s = toInt(match[6] || 0);
19495 var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
19496 timeSetter.call(date, h, m, s, ms);
19497 return date;
19498 }
19499 return string;
19500 }
19501
19502
19503 return function(date, format, timezone) {

Callers 1

dateFilterFunction · 0.70

Calls 2

matchMethod · 0.80
toIntFunction · 0.70

Tested by

no test coverage detected