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

Function jsonStringToDate

lib/test/angular/1.5.0/angular.js:19952–19974  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

19950 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
19951 // 1 2 3 4 5 6 7 8 9 10 11
19952 function jsonStringToDate(string) {
19953 var match;
19954 if (match = string.match(R_ISO8601_STR)) {
19955 var date = new Date(0),
19956 tzHour = 0,
19957 tzMin = 0,
19958 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
19959 timeSetter = match[8] ? date.setUTCHours : date.setHours;
19960
19961 if (match[9]) {
19962 tzHour = toInt(match[9] + match[10]);
19963 tzMin = toInt(match[9] + match[11]);
19964 }
19965 dateSetter.call(date, toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
19966 var h = toInt(match[4] || 0) - tzHour;
19967 var m = toInt(match[5] || 0) - tzMin;
19968 var s = toInt(match[6] || 0);
19969 var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
19970 timeSetter.call(date, h, m, s, ms);
19971 return date;
19972 }
19973 return string;
19974 }
19975
19976
19977 return function(date, format, timezone) {

Callers 1

dateFilterFunction · 0.70

Calls 1

toIntFunction · 0.70

Tested by

no test coverage detected