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

Function jsonStringToDate

lib/test/angular/1.8.0/angular.js:23038–23060  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

23036 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
23037 // 1 2 3 4 5 6 7 8 9 10 11
23038 function jsonStringToDate(string) {
23039 var match;
23040 if ((match = string.match(R_ISO8601_STR))) {
23041 var date = new Date(0),
23042 tzHour = 0,
23043 tzMin = 0,
23044 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
23045 timeSetter = match[8] ? date.setUTCHours : date.setHours;
23046
23047 if (match[9]) {
23048 tzHour = toInt(match[9] + match[10]);
23049 tzMin = toInt(match[9] + match[11]);
23050 }
23051 dateSetter.call(date, toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
23052 var h = toInt(match[4] || 0) - tzHour;
23053 var m = toInt(match[5] || 0) - tzMin;
23054 var s = toInt(match[6] || 0);
23055 var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
23056 timeSetter.call(date, h, m, s, ms);
23057 return date;
23058 }
23059 return string;
23060 }
23061
23062
23063 return function(date, format, timezone) {

Callers 1

dateFilterFunction · 0.70

Calls 1

toIntFunction · 0.70

Tested by

no test coverage detected