time
Notes about time technologies.
ISO 8601
ISO 8601 Data elements and interchange formats - Information interchange - Representation of dates and times is an international standard covering the exchange of date and time-related data.
ISO 8601 format examples
See the ISO 8601 wikipedia page for many examples. Much of the content in this section was taken from that article.
There are a ton of examples on this page: https://ijmacd.github.io/rfc3339-iso8601
One notable syntax is that the letter T should always precede times. This aids in parsing, and distinguishes between month and minute, which are both shortened to M.
Another notable syntax is the use of Z to mean a timezone offset of 0 hours, or GMT.
Single points in time
$ for fmt in date hours minutes seconds ns ; do
bash -x -c "
TZ=$(
awk '$1 !~ /^#/ {print $3}' /usr/share/zoneinfo/zone.tab |
sort -R |
head -n 1
) \
date --iso-8601=${fmt}
" ;
done ;
+ TZ=America/Paramaribo
+ date --iso-8601=date
2016-08-09
+ TZ=Africa/Dakar
+ date --iso-8601=hours
2016-08-09T21+00:00
+ TZ=Indian/Kerguelen
+ date --iso-8601=minutes
2016-08-10T02:58+05:00
+ TZ=Pacific/Saipan
+ date -Iseconds
2016-08-10T07:58:48+10:00
+ TZ=Pacific/Midway
+ date --iso-8601=ns
2016-08-09T10:58:48,503878101-11:00
- Week: 2016-W32
- Date with week number: 2016-W32-2
- Month and day without year: -12-31
Durations, or ranges of time
Durations are a component of time intervals and define the amount of intervening time in a time interval.
Examples
- P10Y - a duration of ten years.
- P5DT12H - a duration of five days and twelve hours.
- P3Y6M4DT12H30M5S - a duration of three years, six months, four days, twelve hours, thirty minutes, and five seconds.
- P1M - one month.
- PT1M - one minute.
Time intervals
A time interval is the intervening time between two time points. There are four ways to express a time interval:
- Start and end, such as
2007-03-01T13:00:00Z/2008-05-11T15:30:00Z
- Start and duration, such as
2007-03-01T13:00:00Z/P1Y2M10DT2H30M
- Duration and end, such as
P1Y2M10DT2H30M/2008-05-11T15:30:00Z
- Duration only, such as
P1Y2M10DT2H30M
, with additional context information
Repeating intervals
Repeating intervals are formed by adding R[n]/
to the beginning of an interval expression. Such as R5/2007-03-01T13:00:00Z/2008-05-11T15:30:00Z
. The n
can be omitted if the interval should repeat forever.
RFC 3339
RFC 3339 is considered a profile of ISO 8601. It defines a profile of ISO 8601 for use in Internet protocols and standards. It explicitly excludes durations and dates before the common era. The more complex formats such as week numbers and ordinal days are not permitted.
Leap Seconds
"A leap second is a one-second adjustment that is occasionally applied to Coordinated Universal Time (UTC) in order to keep its time of day close to the mean solar time, or UT1." - https://en.wikipedia.org/wiki/Leap_second
Leap seconds are scheduled by the international earth rotation and reference systems service (See also: https://en.wikipedia.org/wiki/International_Earth_Rotation_and_Reference_Systems_Service) Leap seconds cause a variety of problems in computer systems, and complicate time tracking in general.
Public time server handling of leap seconds
- https://developers.google.com/time/: Google time servers do leap second smearing
- https://aws.amazon.com/about-aws/whats-new/2017/11/introducing-the-amazon-time-sync-service: AWS time servers do leap second smearing
- https://docs.ntpsec.org/latest/leapsmear.html: ntp.org servers do not leap smear: "Leap Second Smearing MUST NOT be used for public servers, e.g. servers provided by metrology institutes, or servers participating in the NTP pool project."
Leap Second Links
- https://www.nature.com/articles/d41586-022-03783-5: "The leap second’s time is up: world votes to stop pausing clocks"
- https://datacenter.iers.org/data/latestVersion/bulletinC.txt: When is the next leap second?
- https://access.redhat.com/articles/15145: Resolve Leap Second Issues in Red Hat Enterprise Linux 4-8
- https://developers.google.com/time/smear: Google Public NTP: Leap Smear
- https://developers.redhat.com/blog/2015/06/01/five-different-ways-handle-leap-seconds-ntp/: Five different ways to handle leap seconds with NTP
- http://www.madore.org/~david/computers/unix-leap-seconds.html: The Unix leap second mess
- http://www.ntp.org/ntpfaq/NTP-s-algo-real.htm#AEN2499: ntp.org FAQ: What happens during a Leap Second?
Code snips and examples
Quick and dirty time sync in Linux for when NTP is blocked.
date -s $(curl -s -D - google.com | sed '/Date:/s/.*Date: //p ; d')
Links
Reading
- https://en.wikipedia.org/wiki/ISO_8601: "ISO 8601 is an international standard covering the worldwide exchange and communication of date and time related data."
- https://tools.ietf.org/html/rfc3339: Date and Time on the Internet: Timestamps - RFC 3339
- https://www.gnu.org/software/coreutils/manual/html_node/Examples-of-date.html: Examples of date (GNU)
- https://man7.org/linux/man-pages/man1/date.1.html:
man date
(linux) - https://man.freebsd.org/cgi/man.cgi?date:
man date
(freebsd) - https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time: Falsehoods programmers believe about time
- https://infiniteundo.com/post/25509354022/more-falsehoods-programmers-believe-about-time: More falsehoods programmers believe about time; "wisdom of the crowd" edition
- https://www.iers.org: International Earth Rotation and Reference Systems Service
- https://ijmacd.github.io/rfc3339-iso8601/: RFC 3339 vs ISO 8601 format visualizer
- https://blog.healthchecks.io/2021/10/how-debian-cron-handles-dst-transitions/
- https://everytimezone.com: Tool for coordinating across many time zones. Great for coordinating shift coverage across geographically distributed teams.
- http://timesched.pocoo.org: A simpler tool for coordinating across many time zones.
- https://blog.poormansmath.net/the-time-it-takes-to-change-the-time: Contains a map showing the difference in solar time and local time.
Videos
- https://youtu.be/-5wpm-gesOY: The Problem with Time & Timezones - Computerphile