MCPcopy Create free account
hub / github.com/bclinkinbeard/angular / jsonStringToDate

Function jsonStringToDate

test/fixtures/foo.js:15207–15229  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

15205 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
15206 // 1 2 3 4 5 6 7 8 9 10 11
15207 function jsonStringToDate(string) {
15208 var match;
15209 if (match = string.match(R_ISO8601_STR)) {
15210 var date = new Date(0),
15211 tzHour = 0,
15212 tzMin = 0,
15213 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
15214 timeSetter = match[8] ? date.setUTCHours : date.setHours;
15215
15216 if (match[9]) {
15217 tzHour = int(match[9] + match[10]);
15218 tzMin = int(match[9] + match[11]);
15219 }
15220 dateSetter.call(date, int(match[1]), int(match[2]) - 1, int(match[3]));
15221 var h = int(match[4]||0) - tzHour;
15222 var m = int(match[5]||0) - tzMin;
15223 var s = int(match[6]||0);
15224 var ms = Math.round(parseFloat('0.' + (match[7]||0)) * 1000);
15225 timeSetter.call(date, h, m, s, ms);
15226 return date;
15227 }
15228 return string;
15229 }
15230
15231
15232 return function(date, format) {

Callers 1

dateFilterFunction · 0.85

Calls 1

intFunction · 0.85

Tested by

no test coverage detected