Skip to content

[ENH] Accept UTC offsets in datetimes #2001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 6 additions & 7 deletions src/common-principles.md
Original file line number Diff line number Diff line change
Expand Up @@ -1014,16 +1014,15 @@ For additional rules, see below:
Describing dates and timestamps:

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

- Time stamp information MUST be expressed in the following format:
`hh:mm:ss[.000000]`
Expand Down
22 changes: 18 additions & 4 deletions src/schema/objects/formats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,24 @@ date:
datetime:
display_name: Datetime
description: |
A datetime in the form `"YYYY-MM-DDThh:mm:ss[.000000][Z]"`,
where [.000000] is an optional subsecond resolution between 1 and 6 decimal points,
and [Z] is an optional, valid timezone code.
pattern: '[0-9]{4}-[0-9]{2}-[0-9]{2}T(?:2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9](\.[0-9]{1,6})?([A-Z]{2,4})?'
An [RFC 3339](https://doi.org/10.17487/RFC3339) timestamp, with OPTIONAL time offset.
Datetimes take the form `"YYYY-MM-DDThh:mm:ss[.000000][Z|+hh:mm|-hh:mm]"`,
where `[.000000]` is an OPTIONAL subsecond resolution between 1 and 6 decimal points,
and `[Z|+hh:mm|-hh:mm]` is a time offset.
The character `Z` indicates Coordinated Universal Time (UTC),
or else an integral number of minutes may be specified.

For simplicity, this format validates RFC3339-invalid dates such as 2024-02-31,
but implementations SHOULD error on non-existent dates and times.
pattern: "\
[0-9]{4}\
-(?:0[1-9]|1[0-2])\
-(?:0[1-9]|[12][0-9]|3[01])\
T(?:2[0-3]|[01][0-9])\
:[0-5][0-9]\
:(?:[0-5][0-9]|60)\
(?:\\.[0-9]{1,6})?\
(?:Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?"
file_relative:
display_name: Path relative to the parent file
description: |
Expand Down
6 changes: 4 additions & 2 deletions tools/schemacode/src/bidsschematools/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def test_formats(schema_obj):
"2022-01-05T13:16:30",
"2022-01-05T13:16:30.5", # subsecond resolution is allowed
"2022-01-05T13:16:30.000005", # up to 6 decimal points
"2022-01-05T13:16:30UTC", # timezones are allowed
"2022-01-05T13:16:30.05UTC",
"2022-01-05T13:16:30Z", # UTC indicator is allowed
"2022-01-05T13:16:30.05Z",
"2022-01-05T13:16:30+01:00", # integral offsets are allowed
"2022-01-05T13:16:30-05:00",
],
"time": [
"13:16:30",
Expand Down
Loading