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

Function jsonStringToDate

test/angular/1.6/angular.js:22141–22163  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

22139 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
22140 // 1 2 3 4 5 6 7 8 9 10 11
22141 function jsonStringToDate(string) {
22142 var match;
22143 if ((match = string.match(R_ISO8601_STR))) {
22144 var date = new Date(0),
22145 tzHour = 0,
22146 tzMin = 0,
22147 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
22148 timeSetter = match[8] ? date.setUTCHours : date.setHours;
22149
22150 if (match[9]) {
22151 tzHour = toInt(match[9] + match[10]);
22152 tzMin = toInt(match[9] + match[11]);
22153 }
22154 dateSetter.call(date, toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
22155 var h = toInt(match[4] || 0) - tzHour;
22156 var m = toInt(match[5] || 0) - tzMin;
22157 var s = toInt(match[6] || 0);
22158 var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
22159 timeSetter.call(date, h, m, s, ms);
22160 return date;
22161 }
22162 return string;
22163 }
22164
22165
22166 return function(date, format, timezone) {

Callers 1

dateFilterFunction · 0.70

Calls 2

matchMethod · 0.80
toIntFunction · 0.70

Tested by

no test coverage detected