Datetime formats¶
ITk needs to define a consistent way of ensure that users follow a consistent datetime specification and do't give confusing results to the database.
The ITk Production database is following the ISO8601 format for datetime strings. This means that test run results should be uploaded with the appropriate format and the database should be returning results with datetime strings in this same format.
Interpretation
The standard does not assign any specific meaning to elements of the date/time to be represented; the meaning will depend on the context of its use.
Note however that the ISO8601 format is first, and foremost, a formatting specification. It also contains a specification on how one should interpret a datetime string consistently, but that is not as strictly (or easily) enforced. For this project, there is an agreement to require the timezone information to be included explicitly in an expanded format.
Recommendation
The recommendation is to use the explicit timezone offset in ISO8601
formatted strings. Zulu designation (Z
) is acceptable if one is not able
to provide an offset-formatted string. Most modern libraries should be able
to provide timezone-offsetted strings by default.
The best formatted example of a datetime following the recommendations is
1 |
|
which is an expanded datetime format (contains colons and dashes), with T
designation for time, and an explicit timezone offset at the end -07:00
. The following should not be accepted due to: using microseconds and not milliseconds, implicitly meaning UTC, or not including a timezone offset at all:
1 2 3 4 |
|
In these two cases, they are meant to represent local time
and should not be uploaded to the database. They would need to be converted to UTC, or have the timezone offset explicitly added such as:
2021-06-04T15:43:04.264Z
: addition ofZ
states that the time is represented in UTC2021-06-04T15:43:04+00:00
: addition of timezone offset states that the time is represented in UTC
This is what is meant by not implicitly assuming a timezone (which can be dangerous if the datetime library you're using is not enforcing this consistently). Otherwise, the following datetime formats should be accepted:
1 2 3 4 5 6 |
|
Please note that all of the correct solutions do not require Zulu. In fact, this is by far the default that generally happens with most standard libraries these days as the Zulu identifier does not add any additional information.
Zulu time
The addition of Zulu to satisfy the stricter format required by the database is discouraged unless you know that your datetime string is in UTC. It is always recommended to add an offset.
There are cases where simply added the Z
(for Zulu time) identifier does not automatically make a datetime string valid as it could still be represented in the wrong timezone.
Code Snippets¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
arrow is a 3rd-party python
library that is available via pip install arrow
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Additional Notes¶
The 2004 document had widely known issues with the interpretation and the 2019 had to clarify it further into two separate documents which are hard to access. If you want to see a similar profile online without access -- the RFC3339 is similar and the only difference is that RFC3339 mandates the requirement of the T
character for indication of times.
Time precision¶
There is no strict requirement on how precise the datetime can be. The default supported in ISO8601 is acceptable for our purposes. In many cases however, one should discourage only dates. Having at least minute-level precision is encouraged.
Thus a date 2021-06-04Z
is generally discouraged but 2021-06-04T15:45Z
and 2021-06-04T15:45-07:00
are acceptable.
JavaScript really only supports up to millisecond precision so we will disallow microsecond precision for datetime strings.