Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ const allColors = cssContent
### Date/Time

- <span id="intldatere">__`intlDateRE`__</span>: Matches an international style 'YYYY/MM/DD' string. Accepts separators '.', '/', '-'. Will except 1 or 2 digits for month and day and 1-4 digits for the year. Also accepts a + or - before the year. Provides capture groups 1 (BCE/CE indicator), 2 (year), 3 (month), 4 (day).
- <span id="iso8601datere">__`iso8601DateRE`__</span>: Matches an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date time like '20240101T1212Z. Provides matching groups 1 (year), 3 (month), and 4 (day of month), 5 (week date), 6 (day of week date), and 7 (ordinal or Julian date), 8 (special instant end of day time), 10 (hour), 11 (decimal fraction of hour), 13 (minute), 14 (decimal fraction of minute), 15 (seconds), 16 (decimal fraction of a second), and 17 (timezone designation). (Groups 2, 11, and 13 are internal back references.)
- <span id="iso8601datere">__`iso8601DateRE`__</span>: Matches an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date time like '20240101T1212Z. Provides matching groups 1 (year), 3 (month), and 4 (day of month), 5 (week of year), 6 (day of week date), and 7 (ordinal or Julian date), 8 (special end of day time), 10 (hour), 11 (decimal fraction of hour), 13 (minute), 14 (decimal fraction of minute), 15 (seconds), 16 (decimal fraction of a second), and 17 (timezone designation). (Groups 2, 11, and 13 are internal back references.)
- <span id="iso8601datetimere">__`iso8601DateTimeRE`__</span>: Matches an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) _requiring_ both date and time components. See [`iso8601DateRE`](#iso8601datere) for matching groups.
- <span id="iso8601dayrestring">__`iso8601DayREString`__</span>: (string only) Matches the day designation portion of an ISO 8601 date+time. Provides matching groups 1 (year), 3 (month), and 4 (day of month), 5 (week of year), 6 (day of week date), and 7 (ordinal or Julian date).
- <span id="iso8601timerestring">__`iso8601TimeREString`__</span>: (string only) Matches the time designation portion of an ISO 8601 date+time. Provides matching groups 1 (special end of day time), 3 (hours), 3 (fraction of hour), 5 (minutes), 6 (fraction of minute), 7 (seconds), and 8 (fraction of seconds).
- <span id="militarytimere">__`militaryTimeRE`__</span>: Matches military time style 'HHMM' string. Provides capture groups 1 (special 2400 time), 2 (hour), and 3 (minutes).
- <span id="rfc2822dayrestring">__`rfc2822DayREString`__</span>: (string only) Matches the day designation portion of an RFC 2822 date+time. Provides matching groups 1 (day of week name), 2 (day of month), 3 (year).
- <span id="rfc2822timerestring">__`rfc2822TimeREString`__</span>: (string only) Matches the time designation portion of an RFC 2822 date+time. Provides matching groups 1 (hour), 2 (minutes), 3 (seconds), and 4 (timezone).
- <span id="timere">__`timeRE`__</span>: Matches a twelve hour time designation, requires AM or PM designation. Allows optional leading 0 in hour. Provides matching groups 1 (hour), 2 (minutes), 3 (seconds, without decimal fractions), 4 (decimal fraction seconds), and 5 (AM/PM indicator).
- <span id="timezonerestring">__`timezoneREString`__</span>: (string only) Matches a general timezone designation; compliant with RFC 2822 timezone portion. Provides matching groups 1 (timezone).
- <span id="twentyfourhourtimere">__`twentyFourHourTimeRE`__</span>: Matches a twenty-four hour time designationAllows optional leading 0 in hour. Provides matching groups 1 (special 24:00 designation with optional seconds), 2 (hour), 3 (minutes), 4 (seconds, without decimal fractions), 5 (decimal fraction seconds).
- <span id="usdatere">__`usDateRE`__</span>: Matches a US style 'MM/DD/YYYY' string. Accepts separators '.', '/', '-'. Will except 1 or 2 digits for month and day and 1-4 digits for the year. Also accepts a + or - before the year. Provides capture groups 1 (month), 2 (day of month), 3 (BCE/CE indicator), and 4 (year).

Expand Down
22 changes: 14 additions & 8 deletions src/date-times.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { lockdownRE } from './lib/lockdown-re'
// Started RE based on https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
// Made some corrections, rearranged capture groups.

const iso8601DayOnlyREString = '([+-]?\\d{4})(?:(-?)(?:(0[1-9]|1[0-2])(?:\\2([12]\\d|0[1-9]|3[01])?)?|W([0-4]\\d|5[0-3])\\2([1-7])?|(00[1-9]|0[1-9]\\d|[12]\\d{2}|3(?:[0-5]\\d|6[1-6])))?)?'
// Date/Time: (string only) Matches the day designation portion of an ISO 8601 date+time. Provides matching groups 1 (year), 3 (month), and 4 (day of month), 5 (week of year), 6 (day of week date), and 7 (ordinal or Julian date).
export const iso8601DayREString = '(?:([+-]?\\d{4})(?:(-?)(?:(0[1-9]|1[0-2])(?:\\2([12]\\d|0[1-9]|3[01])?)?|W([0-4]\\d|5[0-3])\\2([1-7])?|(00[1-9]|0[1-9]\\d|[12]\\d{2}|3(?:[0-5]\\d|6[1-6])))?)?)'

const eod = '(24(?<endSep>:?)00\\k<endSep>00)'
const frac = '(?:[.,](\\d+))'
Expand All @@ -27,20 +28,25 @@ const min = `(?:([0-5]\\d)${frac}?)`
const sec = `(?:([0-5]\\d|60)${frac}?)`
const tz = '([zZ]|(?:[+-](?!00(?::?00)?)(?:[01]\\d|2[0-3])(?::?[0-5]\\d)?))'

const iso8601TimeOnlyREString = `(?:${eod}|${hr}(?:(?<timeSep>:?)${min}(?:\\k<timeSep>${sec})?)?)${tz}?`
// Date/Time: (string only) Matches the time designation portion of an ISO 8601 date+time. Provides matching groups 1 (special end of day time), 3 (hours), 3 (fraction of hour), 5 (minutes), 6 (fraction of minute), 7 (seconds), and 8 (fraction of seconds).
export const iso8601TimeREString = `(?:(?:${eod}|${hr}(?:(?<timeSep>:?)${min}(?:\\k<timeSep>${sec})?)?)${tz}?)`

export const iso8601DateREString = `${iso8601DayOnlyREString}(?:T${iso8601TimeOnlyREString})?`
// Date/Time: Matches an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date time like '20240101T1212Z. Provides matching groups 1 (year), 3 (month), and 4 (day of month), 5 (week date), 6 (day of week date), and 7 (ordinal or Julian date), 8 (special instant end of day time), 10 (hour), 11 (decimal fraction of hour), 13 (minute), 14 (decimal fraction of minute), 15 (seconds), 16 (decimal fraction of a second), and 17 (timezone designation). (Groups 2, 11, and 13 are internal back references.)
export const iso8601DateREString = `${iso8601DayREString}(?:T${iso8601TimeREString})?`
// Date/Time: Matches an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date time like '20240101T1212Z. Provides matching groups 1 (year), 3 (month), and 4 (day of month), 5 (week of year), 6 (day of week date), and 7 (ordinal or Julian date), 8 (special end of day time), 10 (hour), 11 (decimal fraction of hour), 13 (minute), 14 (decimal fraction of minute), 15 (seconds), 16 (decimal fraction of a second), and 17 (timezone designation). (Groups 2, 11, and 13 are internal back references.)
export const iso8601DateRE = lockdownRE(iso8601DateREString)

export const iso8601DateTimeREString = `${iso8601DayOnlyREString}T${iso8601TimeOnlyREString}`
export const iso8601DateTimeREString = `${iso8601DayREString}T${iso8601TimeREString}`
// Date/Time: Matches an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) _requiring_ both date and time components. See [`iso8601DateRE`](#iso8601datere) for matching groups.
export const iso8601DateTimeRE = lockdownRE(iso8601DateTimeREString)

const rfc2822DayOnlyREString = '(?:(Sun|Mon|Tue|Wed|Thu|Fri|Sat),\\s+)?(0[1-9]|[1-2]?[0-9]|3[01])\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(\\d{2,4})'
const rfc2822TimeOnlyREString = '(2[0-3]|[0-1][0-9]):([0-5][0-9])(?::(60|[0-5][0-9]))?(?:\\s+([+-][0-9]{2}[0-5][0-9]|(?:UT|GMT|[A-Z]{3,5}|[A-IK-Z])))?'
// Date/Time: (string only) Matches the day designation portion of an RFC 2822 date+time. Provides matching groups 1 (day of week name), 2 (day of month), 3 (year).
export const rfc2822DayREString = '(?:(?:(Sun|Mon|Tue|Wed|Thu|Fri|Sat),\\s+)?(0[1-9]|[1-2]?[0-9]|3[01])\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(\\d{2,4}))'
// Date/Time: (string only) Matches a general timezone designation; compliant with RFC 2822 timezone portion. Provides matching groups 1 (timezone).
export const timezoneREString = '([+-][0-9]{2}[0-5][0-9]|(?:UT|GMT|[A-Z]{3,5}|[A-IK-Z]))'
// Date/Time: (string only) Matches the time designation portion of an RFC 2822 date+time. Provides matching groups 1 (hour), 2 (minutes), 3 (seconds), and 4 (timezone).
export const rfc2822TimeREString = `(?:(2[0-3]|[0-1][0-9]):([0-5][0-9])(?::(60|[0-5][0-9]))?(?:\\s+${timezoneREString})?)`

export const rfc2822DateREString = `${rfc2822DayOnlyREString}\\s+${rfc2822TimeOnlyREString}`
export const rfc2822DateREString = `${rfc2822DayREString}\\s+${rfc2822TimeREString}`
// Date/Tmie: Matches an [RFC 2822](https://datatracker.ietf.org/doc/html/rfc2822#section-3.3) style date like 'Mon, 6 Jan 1992 12:12 UTC'. Provides matching groups 1 (day of week), 2 (day of month), 3 (month), and 4 (year), 5 (hour), 6 (min), 7 (second), and 8 (time zone).
export const rfc2822DateRE = lockdownRE(rfc2822DateREString)

Expand Down
4 changes: 1 addition & 3 deletions src/doc-extractor/doc-extractor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ const addData = ({ description, reName, section }) => {
const contents = await fs.readFile(fsPath.resolve(__dirname, '..', fileName), { encoding : 'utf8' })
const lines = contents.split('\n')
lines.forEach((l, i, a) => {
const exportMatch = l.match(/^\s*export\s+const +([a-zA-Z0-9]+RE(?=[ =]))/)
const exportMatch = l.match(/^\s*export\s+const +([a-zA-Z0-9]+RE(?:String)?(?=[ =]))/)
if (exportMatch !== null) {
const [, reName] = exportMatch
const prevLine = a[i - 1]
const commentMatch = prevLine.match(/\/\/ *([^:]*): *?\s*(.+)/)
if (commentMatch !== null) {
const [, section, description] = commentMatch
addData({ description, reName, section })
} else {
addData({ reName, section : 'Uncategorized' })
}
}
})
Expand Down
Loading