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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 6 additions & 7 deletions src/common-principles.md
Original file line number Diff line number Diff line change
Expand Up @@ -1017,16 +1017,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
15 changes: 10 additions & 5 deletions src/schema/objects/formats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ 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 literal character `Z` that indicates
Coordinated Universal Time (UTC).
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])\
Expand All @@ -89,7 +94,7 @@ datetime:
:[0-5][0-9]\
:(?:[0-5][0-9]|60)\
(?:\\.[0-9]{1,6})?\
Z?"
(?:Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?"
file_relative:
display_name: Path relative to the parent file
description: |
Expand Down
2 changes: 2 additions & 0 deletions tools/schemacode/src/bidsschematools/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def test_formats(schema_obj):
"2022-01-05T13:16:30.000005", # up to 6 decimal points
"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