Skip to content

Commit 3817877

Browse files
authored
[ENH] Accept UTC offsets in datetimes (#2001)
* enh: Accept UTC offsets in datetimes * test: Fix expected datetime patterns
1 parent 9570a6a commit 3817877

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/common-principles.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,16 +1027,15 @@ For additional rules, see below:
10271027
Describing dates and timestamps:
10281028

10291029
- Date time information MUST be expressed in the following format
1030-
`YYYY-MM-DDThh:mm:ss[.000000][Z]` (year, month, day, hour (24h), minute,
1031-
second, optional fractional seconds, and optional UTC time indicator).
1030+
`YYYY-MM-DDThh:mm:ss[.000000][Z|+hh:mm|-hh:mm]` (year, month, day, hour (24h),
1031+
minute, second, optional fractional seconds, and optional time offset).
10321032
This is almost equivalent to the [RFC3339](https://tools.ietf.org/html/rfc3339)
1033-
"date-time" format, with the exception that UTC indicator `Z` is optional and
1034-
non-zero UTC offsets are not indicated.
1035-
If `Z` is not indicated, time zone is always assumed to be the local time of the
1036-
dataset viewer.
1033+
"date-time" format, with the exception that UTC offsets are OPTIONAL.
1034+
If no time offset is indicated,
1035+
time zone is always assumed to be the local time of the dataset viewer.
10371036
No specific precision is required for fractional seconds, but the precision
10381037
SHOULD be consistent across the dataset.
1039-
For example `2009-06-15T13:45:30`.
1038+
For example `2009-06-15T13:45:30+01:00`.
10401039

10411040
- Time stamp information MUST be expressed in the following format:
10421041
`hh:mm:ss[.000000]`

src/schema/objects/formats.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,15 @@ date:
7575
datetime:
7676
display_name: Datetime
7777
description: |
78-
A datetime in the form `"YYYY-MM-DDThh:mm:ss[.000000][Z]"`,
79-
where `[.000000]` is an optional subsecond resolution between 1 and 6 decimal points,
80-
and `[Z]` is an optional literal character `Z` that indicates
81-
Coordinated Universal Time (UTC).
78+
An [RFC 3339](https://doi.org/10.17487/RFC3339) timestamp, with OPTIONAL time offset.
79+
Datetimes take the form `"YYYY-MM-DDThh:mm:ss[.000000][Z|+hh:mm|-hh:mm]"`,
80+
where `[.000000]` is an OPTIONAL subsecond resolution between 1 and 6 decimal points,
81+
and `[Z|+hh:mm|-hh:mm]` is a time offset.
82+
The character `Z` indicates Coordinated Universal Time (UTC),
83+
or else an integral number of minutes may be specified.
84+
85+
For simplicity, this format validates RFC3339-invalid dates such as 2024-02-31,
86+
but implementations SHOULD error on non-existent dates and times.
8287
pattern: "\
8388
[0-9]{4}\
8489
-(?:0[1-9]|1[0-2])\
@@ -87,7 +92,7 @@ datetime:
8792
:[0-5][0-9]\
8893
:(?:[0-5][0-9]|60)\
8994
(?:\\.[0-9]{1,6})?\
90-
Z?"
95+
(?:Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?"
9196
file_relative:
9297
display_name: Path relative to the parent file
9398
description: |

tools/schemacode/src/bidsschematools/tests/test_schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def test_formats(schema_obj):
9090
"2022-01-05T13:16:30.000005", # up to 6 decimal points
9191
"2022-01-05T13:16:30Z", # UTC indicator is allowed
9292
"2022-01-05T13:16:30.05Z",
93+
"2022-01-05T13:16:30+01:00", # integral offsets are allowed
94+
"2022-01-05T13:16:30-05:00",
9395
],
9496
"time": [
9597
"13:16:30",

0 commit comments

Comments
 (0)