Skip to content

Commit 89a92d4

Browse files
committed
Add support for 9-digit millisecond precision to isoTimestamp #348
ISO-8601 does not specify the number of digits in the decimal fraction. JavaScript `new Date().toISOString()` which is compliant to ISO-8601, has a precision of three digits (miliseconds precision). Java `Instant.now().toString()` which is compliant to ISO-8601, has a precision of nine digits (nanoseconds precision). This change will allow timestamps with nanoseconds precision.
1 parent 4b50ce8 commit 89a92d4

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

library/src/regex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const ISO_TIME_SECOND_REGEX = /^(?:0\d|1\d|2[0-3])(?::[0-5]\d){2}$/u;
7979
* [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp regex.
8080
*/
8181
export const ISO_TIMESTAMP_REGEX =
82-
/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])T(?:0\d|1\d|2[0-3])(?::[0-5]\d){2}\.\d{3}Z$/u;
82+
/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])T(?:0\d|1\d|2[0-3])(?::[0-5]\d){2}\.\d{3,9}Z$/u;
8383

8484
/**
8585
* [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) week regex.

library/src/validations/isoTimestamp/isoTimestamp.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ describe('isoTimestamp', () => {
1010
expect(validate._parse(value2).output).toBe(value2);
1111
const value3 = '9999-12-31T23:59:59.999Z';
1212
expect(validate._parse(value3).output).toBe(value3);
13+
const value4 = '2024-01-04T17:40:21.157953900Z';
14+
expect(validate._parse(value4).output).toBe(value4);
1315

1416
expect(validate._parse('').issues).toBeTruthy();
1517
expect(validate._parse('2023-07-11T17:26:27.243').issues).toBeTruthy();

library/src/validations/isoTimestamp/isoTimestamp.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ export type IsoTimestampValidation<TInput extends string> =
2020
/**
2121
* Creates a pipeline validation action that validates a timestamp.
2222
*
23-
* Format: yyyy-mm-ddThh:mm:ss.sssZ
23+
* Format: yyyy-mm-ddThh:mm:ss.sssssssssZ
24+
* - yyyy: 4-digit year
25+
* - mm: 2-digit month
26+
* - dd: 2-digit day
27+
* - hh: 2-digit hour (00-23)
28+
* - mm: 2-digit minute (00-59)
29+
* - ss: 2-digit second (00-59)
30+
* - sssssssss: Up to 9-digit millisecond precision
31+
* - Z: Timezone offset (e.g., +00:00 or -07:00, Z=UTC+0)
2432
*
2533
* Hint: The regex used cannot validate the maximum number of days based on
2634
* year and month. For example, "2023-06-31T00:00:00.000Z" is valid although

0 commit comments

Comments
 (0)