MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / jsonStringToDate

Function jsonStringToDate

code/songhop/www/lib/angular/angular.js:17151–17173  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

17149 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
17150 // 1 2 3 4 5 6 7 8 9 10 11
17151 function jsonStringToDate(string) {
17152 var match;
17153 if (match = string.match(R_ISO8601_STR)) {
17154 var date = new Date(0),
17155 tzHour = 0,
17156 tzMin = 0,
17157 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
17158 timeSetter = match[8] ? date.setUTCHours : date.setHours;
17159
17160 if (match[9]) {
17161 tzHour = int(match[9] + match[10]);
17162 tzMin = int(match[9] + match[11]);
17163 }
17164 dateSetter.call(date, int(match[1]), int(match[2]) - 1, int(match[3]));
17165 var h = int(match[4] || 0) - tzHour;
17166 var m = int(match[5] || 0) - tzMin;
17167 var s = int(match[6] || 0);
17168 var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
17169 timeSetter.call(date, h, m, s, ms);
17170 return date;
17171 }
17172 return string;
17173 }
17174
17175
17176 return function(date, format, timezone) {

Callers 1

dateFilterFunction · 0.70

Calls 1

intFunction · 0.70

Tested by

no test coverage detected