MCPcopy Index your code
hub / github.com/angular/angular / isoStringToDate

Function isoStringToDate

packages/common/src/i18n/format_date.ts:973–997  ·  view source on GitHub ↗
(match: RegExpMatchArray)

Source from the content-addressed store, hash-verified

971 * Used instead of `Date.parse` because of browser discrepancies.
972 */
973export function isoStringToDate(match: RegExpMatchArray): Date {
974 const date = new Date(0);
975 let tzHour = 0;
976 let tzMin = 0;
977
978 // match[8] means that the string contains "Z" (UTC) or a timezone like "+01:00" or "+0100"
979 const dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear;
980 const timeSetter = match[8] ? date.setUTCHours : date.setHours;
981
982 // if there is a timezone defined like "+01:00" or "+0100"
983 if (match[9]) {
984 tzHour = Number(match[9] + match[10]);
985 tzMin = Number(match[9] + match[11]);
986 }
987 dateSetter.call(date, Number(match[1]), Number(match[2]) - 1, Number(match[3]));
988 const h = Number(match[4] || 0) - tzHour;
989 const m = Number(match[5] || 0) - tzMin;
990 const s = Number(match[6] || 0);
991 // The ECMAScript specification (https://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.11)
992 // defines that `DateTime` milliseconds should always be rounded down, so that `999.9ms`
993 // becomes `999ms`.
994 const ms = Math.floor(parseFloat('0.' + (match[7] || 0)) * 1000);
995 timeSetter.call(date, h, m, s, ms);
996 return date;
997}
998
999export function isDate(value: any): value is Date {
1000 return value instanceof Date && !isNaN(value.valueOf());

Callers 1

toDateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…