registration
This commit is contained in:
52
frontend/style/node_modules/date-fns/parseJSON.js
generated
vendored
52
frontend/style/node_modules/date-fns/parseJSON.js
generated
vendored
@@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
exports.parseJSON = parseJSON; /**
|
||||
* @name parseJSON
|
||||
* @category Common Helpers
|
||||
* @summary Parse a JSON date string
|
||||
*
|
||||
* @description
|
||||
import { toDate } from "./toDate.js";
|
||||
|
||||
/**
|
||||
* The {@link parseJSON} function options.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts a complete ISO date string in UTC time, the typical format for transmitting
|
||||
* a date in JSON, to a JavaScript `Date` instance.
|
||||
*
|
||||
@@ -29,27 +29,33 @@ exports.parseJSON = parseJSON; /**
|
||||
*
|
||||
* Any other input type or invalid date strings will return an `Invalid Date`.
|
||||
*
|
||||
* @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 dateStr - A fully formed ISO8601 date string to convert
|
||||
* @param options - An object with options
|
||||
*
|
||||
* @returns The parsed date in the local time zone
|
||||
*/
|
||||
function parseJSON(dateStr) {
|
||||
export function parseJSON(dateStr, options) {
|
||||
const parts = dateStr.match(
|
||||
/(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d{0,7}))?(?:Z|(.)(\d{2}):?(\d{2})?)?/,
|
||||
);
|
||||
if (parts) {
|
||||
// Group 8 matches the sign
|
||||
return new Date(
|
||||
Date.UTC(
|
||||
+parts[1],
|
||||
+parts[2] - 1,
|
||||
+parts[3],
|
||||
+parts[4] - (+parts[9] || 0) * (parts[8] == "-" ? -1 : 1),
|
||||
+parts[5] - (+parts[10] || 0) * (parts[8] == "-" ? -1 : 1),
|
||||
+parts[6],
|
||||
+((parts[7] || "0") + "00").substring(0, 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
return new Date(NaN);
|
||||
|
||||
if (!parts) return toDate(NaN, options?.in);
|
||||
|
||||
return toDate(
|
||||
Date.UTC(
|
||||
+parts[1],
|
||||
+parts[2] - 1,
|
||||
+parts[3],
|
||||
+parts[4] - (+parts[9] || 0) * (parts[8] == "-" ? -1 : 1),
|
||||
+parts[5] - (+parts[10] || 0) * (parts[8] == "-" ? -1 : 1),
|
||||
+parts[6],
|
||||
+((parts[7] || "0") + "00").substring(0, 3),
|
||||
),
|
||||
options?.in,
|
||||
);
|
||||
}
|
||||
|
||||
// Fallback for modularized imports:
|
||||
export default parseJSON;
|
||||
|
||||
Reference in New Issue
Block a user