MCPcopy Create free account
hub / github.com/11ty/parse-date-strings / getParts

Method getParts

parse.js:47–57  ·  view source on GitHub ↗

@param {string} str An [RFC 9557](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime#rfc_9557_format)-compatible string

(str = "")

Source from the content-addressed store, hash-verified

45
46 /** @param {string} str An [RFC 9557](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime#rfc_9557_format)-compatible string */
47 static getParts(str = "") {
48 let dateTimeMatch = str.match(this.FULL_DATE_REGEX) ?? str.match(this.DATETIME_REGEX);
49 if(!dateTimeMatch) {
50 throw new Error(`Unsupported date format: ${str}`);
51 }
52 if(dateTimeMatch.slice(4,6).some(part => !!part?.match(this.IS_FRACTIONAL_REGEX))) {
53 throw new Error(`Unsupported date format (fractional hours or minutes): ${str}`);
54 }
55
56 return this.getByDateTime(...dateTimeMatch);
57 }
58}
59
60export class IsoDate {

Callers 1

parseMethod · 0.80

Calls 1

getByDateTimeMethod · 0.95

Tested by

no test coverage detected