MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / jsonStringToDate

Function jsonStringToDate

web/static/bower_components/angular/angular.js:18960–18982  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

18958 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
18959 // 1 2 3 4 5 6 7 8 9 10 11
18960 function jsonStringToDate(string) {
18961 var match;
18962 if (match = string.match(R_ISO8601_STR)) {
18963 var date = new Date(0),
18964 tzHour = 0,
18965 tzMin = 0,
18966 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
18967 timeSetter = match[8] ? date.setUTCHours : date.setHours;
18968
18969 if (match[9]) {
18970 tzHour = toInt(match[9] + match[10]);
18971 tzMin = toInt(match[9] + match[11]);
18972 }
18973 dateSetter.call(date, toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
18974 var h = toInt(match[4] || 0) - tzHour;
18975 var m = toInt(match[5] || 0) - tzMin;
18976 var s = toInt(match[6] || 0);
18977 var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
18978 timeSetter.call(date, h, m, s, ms);
18979 return date;
18980 }
18981 return string;
18982 }
18983
18984
18985 return function(date, format, timezone) {

Callers 1

dateFilterFunction · 0.85

Calls 1

toIntFunction · 0.85

Tested by

no test coverage detected