@firestitch/date
Advanced tools
Comparing version 12.0.2 to 12.1.0
import { isValid } from 'date-fns'; | ||
import { utcToZonedTime } from 'date-fns-tz'; | ||
import { parse } from './parse'; | ||
import { sanitizeDate } from './sanitize-date'; | ||
export function parseLocal(date) { | ||
let date1 = date; | ||
if (typeof date === 'string') { | ||
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
date = utcToZonedTime(sanitizeDate(date), timeZone); | ||
if (!date.match(/[+-]\d{2}:\d{2}$/)) { | ||
date += '+00:00'; | ||
} | ||
date1 = parse(sanitizeDate(date)); | ||
date1 = new Date(date1.getUTCFullYear(), date1.getUTCMonth(), date1.getUTCDate(), date1.getUTCHours(), date1.getUTCMinutes(), date1.getUTCSeconds(), date1.getUTCMilliseconds()); | ||
} | ||
return isValid(date) ? date : null; | ||
return isValid(date1) ? date1 : null; | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFyc2UtbG9jYWwuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGlicy9wYXJzZS1sb2NhbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBQ25DLE9BQU8sRUFBRSxjQUFjLEVBQUUsTUFBTSxhQUFhLENBQUE7QUFDNUMsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBRy9DLE1BQU0sVUFBVSxVQUFVLENBQUMsSUFBSTtJQUMzQixJQUFJLE9BQU8sSUFBSSxLQUFLLFFBQVEsRUFBRTtRQUMxQixNQUFNLFFBQVEsR0FBRyxJQUFJLENBQUMsY0FBYyxFQUFFLENBQUMsZUFBZSxFQUFFLENBQUMsUUFBUSxDQUFDO1FBQ2xFLElBQUksR0FBRyxjQUFjLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxFQU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BkYXRlO1xyXG4gICAgaWYgKHR5cGVvZiBkYXRlID09PSAnc3RyaW5nJykge1xyXG4gICAgICAgIGlmKCFkYXRlLm1hdGNoKC9bKy1dXFxkezJ9OlxcZHsyfSQvKSkge1xyXG4gICAgICAgICAgICBkYXRlICs9ICcrMDA6MDAnO1xyXG4gICAgICAgIH0gICAgICAgIFxyXG5cclxuICAgICAgICBkYXRlMSA9IHBhcnNlKHNhbml0aXplRGF0ZShkYXRlKSk7XHJcbiAgICAgICAgXHJcbiAgICAgICAgZGF0ZTEgPSBuZXcgRGF0ZShkYXRlMS5nZXRVVENGdWxsWWVhcigpLCBkYXRlMS5nZXRVVENNb250aCgpLCBkYXRlMS5nZXRVVENEYXRlKCksIGRhdGUxLmdldFVUQ0hvdXJzKCksIGRhdGUxLmdldFVUQ01pbnV0ZXMoKSwgZGF0ZTEuZ2V0VVRDU2Vjb25kcygpLCBkYXRlMS5nZXRVVENNaWxsaXNlY29uZHMoKSk7XHJcbiAgICB9XHJcblxyXG5cclxuICAgIHJldHVybiBpc1ZhbGlkKGRhdGUxKSA/IGRhdGUxIDogbnVsbDtcclxufVxyXG5cclxuIl19 |
@@ -9,3 +9,3 @@ import * as i0 from '@angular/core'; | ||
import { isSameYear, parseISO, isValid, differenceInSeconds, differenceInMinutes, format as format$2, differenceInMilliseconds } from 'date-fns'; | ||
import { format as format$1, utcToZonedTime } from 'date-fns-tz'; | ||
import { format as format$1 } from 'date-fns-tz'; | ||
import { of, Subject, interval } from 'rxjs'; | ||
@@ -480,7 +480,11 @@ import { takeWhile, takeUntil } from 'rxjs/operators'; | ||
function parseLocal(date) { | ||
let date1 = date; | ||
if (typeof date === 'string') { | ||
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
date = utcToZonedTime(sanitizeDate(date), timeZone); | ||
if (!date.match(/[+-]\d{2}:\d{2}$/)) { | ||
date += '+00:00'; | ||
} | ||
date1 = parse(sanitizeDate(date)); | ||
date1 = new Date(date1.getUTCFullYear(), date1.getUTCMonth(), date1.getUTCDate(), date1.getUTCHours(), date1.getUTCMinutes(), date1.getUTCSeconds(), date1.getUTCMilliseconds()); | ||
} | ||
return isValid(date) ? date : null; | ||
return isValid(date1) ? date1 : null; | ||
} | ||
@@ -487,0 +491,0 @@ |
{ | ||
"name": "@firestitch/date", | ||
"version": "12.0.2", | ||
"version": "12.1.0", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
457939
3775