A Simple Explanation of Postgres' <Code>Timestamp with Time Zone</Code>

1 pointsposted 12 hours ago
by speckx

2 Comments

Terr_

12 hours ago

Worth reiterating in all these discussions:

1. All times in the future are best-understood as a set of triggering-rules, based on world-conditions that are neither constant nor wholly predictable.

2. Converting future times means guessing that one set of conditions will be met in N seconds, and then guessing that N seconds from now will be when another set of conditions triggers. (Yes, to-UTC or from-UTC.)

This mental model will help contextualize all the various timezone advice out there, and guides away from nasty deep design-bugs.

______________

A brief ramble on the spectrum of predictability.

On one extreme, International Atomic Time (TAI) [0] means "X seconds from now" is conditioned on waiting for a cesium atom to vibrate a certain number of times. So intervals are very highly predictable... unless some Star Trek engineer decides to Reverse the Polarity on something. But everyone except experimental physicists strongly hopes it won't happen.

Adjacent to it is good old UTC, which has an additional wrinkle where some United Nations folks may choose to add/remove a leap second [1], so your future event can "move" around, and the interval between "now" and the event can change over time. But we try to avoid caring about +/-1 second.

Much further away towards the other end, imagine: "Our after-work picnic for the Doomstadt office will be on June 7th at 5:30PM Latverian Standard Time." How many seconds from now until then? Well, it depends on whenever the LST officials arbitrarily decide it happens. They might even do a time-adjustment that skips an hour (4:59PM then 6:00PM) so that the picnic time never technically occurs, or do the inverse so that 5:30PM pops up twice that day. They might switch to a totally incompatible national calendar. The nation itself might vanish.

______________

Anyway, back to database columns, your design will depend a bit on "what conditional contract am I really capturing here", plus "which layer(s) of my design will need to do time logic to guess intervals or convert through intervals."

[0] https://en.wikipedia.org/wiki/International_Atomic_Time

[1] https://en.wikipedia.org/wiki/Leap_second

user

12 hours ago

[deleted]