registration

This commit is contained in:
User
2025-02-02 16:08:03 +03:00
parent 7f6495eb4d
commit 78afbaed71
6334 changed files with 196774 additions and 165754 deletions

View File

@@ -1,6 +1,9 @@
"use strict";
exports.parseISO = parseISO;
var _index = require("./constants.js");
import {
millisecondsInHour,
millisecondsInMinute,
} from "./constants.js";
import { constructFrom } from "./constructFrom.js";
import { toDate } from "./toDate.js";
/**
* The {@link parseISO} function options.
@@ -21,6 +24,7 @@ var _index = require("./constants.js");
* the values are invalid, it returns Invalid Date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
*
* @param argument - The value to convert
* @param options - An object with options
@@ -38,7 +42,9 @@ var _index = require("./constants.js");
* const result = parseISO('+02014101', { additionalDigits: 1 })
* //=> Fri Apr 11 2014 00:00:00
*/
function parseISO(argument, options) {
export function parseISO(argument, options) {
const invalidDate = () => constructFrom(options?.in, NaN);
const additionalDigits = options?.additionalDigits ?? 2;
const dateStrings = splitDateString(argument);
@@ -48,49 +54,38 @@ function parseISO(argument, options) {
date = parseDate(parseYearResult.restDateString, parseYearResult.year);
}
if (!date || isNaN(date.getTime())) {
return new Date(NaN);
}
if (!date || isNaN(+date)) return invalidDate();
const timestamp = date.getTime();
const timestamp = +date;
let time = 0;
let offset;
if (dateStrings.time) {
time = parseTime(dateStrings.time);
if (isNaN(time)) {
return new Date(NaN);
}
if (isNaN(time)) return invalidDate();
}
if (dateStrings.timezone) {
offset = parseTimezone(dateStrings.timezone);
if (isNaN(offset)) {
return new Date(NaN);
}
if (isNaN(offset)) return invalidDate();
} else {
const dirtyDate = new Date(timestamp + time);
// JS parsed string assuming it's in UTC timezone
// but we need it to be parsed in our timezone
// so we use utc values to build date in our timezone.
// Year values from 0 to 99 map to the years 1900 to 1999
// so set year explicitly with setFullYear.
const result = new Date(0);
const tmpDate = new Date(timestamp + time);
const result = toDate(0, options?.in);
result.setFullYear(
dirtyDate.getUTCFullYear(),
dirtyDate.getUTCMonth(),
dirtyDate.getUTCDate(),
tmpDate.getUTCFullYear(),
tmpDate.getUTCMonth(),
tmpDate.getUTCDate(),
);
result.setHours(
dirtyDate.getUTCHours(),
dirtyDate.getUTCMinutes(),
dirtyDate.getUTCSeconds(),
dirtyDate.getUTCMilliseconds(),
tmpDate.getUTCHours(),
tmpDate.getUTCMinutes(),
tmpDate.getUTCSeconds(),
tmpDate.getUTCMilliseconds(),
);
return result;
}
return new Date(timestamp + time + offset);
return toDate(timestamp + time + offset, options?.in);
}
const patterns = {
@@ -216,9 +211,7 @@ function parseTime(timeString) {
}
return (
hours * _index.millisecondsInHour +
minutes * _index.millisecondsInMinute +
seconds * 1000
hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * 1000
);
}
@@ -240,10 +233,7 @@ function parseTimezone(timezoneString) {
return NaN;
}
return (
sign *
(hours * _index.millisecondsInHour + minutes * _index.millisecondsInMinute)
);
return sign * (hours * millisecondsInHour + minutes * millisecondsInMinute);
}
function dayOfISOWeekYear(isoWeekYear, week, day) {
@@ -299,3 +289,6 @@ function validateTime(hours, minutes, seconds) {
function validateTimezone(_hours, minutes) {
return minutes >= 0 && minutes <= 59;
}
// Fallback for modularized imports:
export default parseISO;