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

Function jsonStringToDate

test/angular/1.5/angular.js:21199–21221  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

21197 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
21198 // 1 2 3 4 5 6 7 8 9 10 11
21199 function jsonStringToDate(string) {
21200 var match;
21201 if ((match = string.match(R_ISO8601_STR))) {
21202 var date = new Date(0),
21203 tzHour = 0,
21204 tzMin = 0,
21205 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
21206 timeSetter = match[8] ? date.setUTCHours : date.setHours;
21207
21208 if (match[9]) {
21209 tzHour = toInt(match[9] + match[10]);
21210 tzMin = toInt(match[9] + match[11]);
21211 }
21212 dateSetter.call(date, toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
21213 var h = toInt(match[4] || 0) - tzHour;
21214 var m = toInt(match[5] || 0) - tzMin;
21215 var s = toInt(match[6] || 0);
21216 var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
21217 timeSetter.call(date, h, m, s, ms);
21218 return date;
21219 }
21220 return string;
21221 }
21222
21223
21224 return function(date, format, timezone) {

Callers 1

dateFilterFunction · 0.70

Calls 2

matchMethod · 0.80
toIntFunction · 0.70

Tested by

no test coverage detected