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

Function jsonStringToDate

test/angular/1.7/angular-mocks.js:734–756  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

732
733
734function jsonStringToDate(string) {
735 // The R_ISO8061_STR regex is never going to fit into the 100 char limit!
736 // eslit-disable-next-line max-len
737 var R_ISO8061_STR = /^(-?\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
738
739 var match;
740 if ((match = string.match(R_ISO8061_STR))) {
741 var date = new Date(0),
742 tzHour = 0,
743 tzMin = 0;
744 if (match[9]) {
745 tzHour = toInt(match[9] + match[10]);
746 tzMin = toInt(match[9] + match[11]);
747 }
748 date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
749 date.setUTCHours(toInt(match[4] || 0) - tzHour,
750 toInt(match[5] || 0) - tzMin,
751 toInt(match[6] || 0),
752 toInt(match[7] || 0));
753 return date;
754 }
755 return string;
756}
757
758function toInt(str) {
759 return parseInt(str, 10);

Callers 1

angular-mocks.jsFile · 0.70

Calls 2

matchMethod · 0.80
toIntFunction · 0.70

Tested by

no test coverage detected