From 325965fbefaab35231af0dc21ecdd493ac66a92d Mon Sep 17 00:00:00 2001 From: Olaf Tomalka Date: Mon, 14 Oct 2024 22:46:31 +0200 Subject: [PATCH] Rename and export from index --- src/index.ts | 1 + src/iso8601-date.test.ts | 8 ++++---- src/iso8601-date.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index d3f0813ce..5b1c7950f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,3 +18,4 @@ export * from './promise'; export * from './time'; export * from './transaction-types'; export * from './versions'; +export * from './iso8601-date'; diff --git a/src/iso8601-date.test.ts b/src/iso8601-date.test.ts index 172a5034d..dd63cb396 100644 --- a/src/iso8601-date.test.ts +++ b/src/iso8601-date.test.ts @@ -1,7 +1,7 @@ import { TZDate } from '@date-fns/tz'; import assert from 'assert'; -import { InvalidIso8601Date, parseDateTime } from './iso8601-date'; +import { InvalidIso8601Date, parseIso8601DateTime } from './iso8601-date'; describe('parseDateTime', () => { it.each([ @@ -19,7 +19,7 @@ describe('parseDateTime', () => { ['20300606T0603', new Date(2030, 5, 6, 6, 3)], ['20310707T070402', new Date(2031, 6, 7, 7, 4, 2)], ])('parses %s local-time correctly', (testIso, expectedDate) => { - const result = parseDateTime(testIso); + const result = parseIso8601DateTime(testIso); expect(result).toBeInstanceOf(Date); expect(result.toISOString()).toStrictEqual(expectedDate.toISOString()); @@ -44,7 +44,7 @@ describe('parseDateTime', () => { ['2023-04-04T04:04:04-01:01', new TZDate(2023, 3, 4, 4, 4, 4, '-01:01')], ['2023-04-04T04:04:04+02:02', new TZDate(2023, 3, 4, 4, 4, 4, '+02:02')], ])('parses %s with time-zone correctly', (testIso, expectedDate) => { - const result = parseDateTime(testIso); + const result = parseIso8601DateTime(testIso); assert(result instanceof TZDate); expect(result.timeZone).toStrictEqual(expectedDate.timeZone); @@ -92,6 +92,6 @@ describe('parseDateTime', () => { '2020-01-01T23:59:59-11:60', '2020-01-01T23:59:59a', ])('throws on invalid date time "%s"', (testIso) => { - expect(() => parseDateTime(testIso)).toThrow(InvalidIso8601Date); + expect(() => parseIso8601DateTime(testIso)).toThrow(InvalidIso8601Date); }); }); diff --git a/src/iso8601-date.ts b/src/iso8601-date.ts index 8f232f1f1..d031b30a9 100644 --- a/src/iso8601-date.ts +++ b/src/iso8601-date.ts @@ -32,7 +32,7 @@ export const InvalidIso8601Date = new Error('Invalid ISO-8601 date'); * @param value - An ISO-8601 formatted string. * @returns A date if value is in local-time, a TZDate if timezone data provided. */ -export function parseDateTime(value: string): Date | TZDate { +export function parseIso8601DateTime(value: string): Date | TZDate { let at = 0; let hasSeparators: boolean | null = null; let state: ParseDateState = ParseDateState.YEAR;