{time}

You are not a victim

You just scream with boredom

You are not evicting time

-- Time by David Bowie

Alex Songe <a@songe.me>

What is time?

what?

What is time? -- simple

still...not helping

Why is time?

Time is what prevents everything from happening at once.

Space is what prevents everything from happening to me.

-- John Wheeler, Theoretical Physicist

My 🐂💩: Time is deeply linked with our notions of causation. Fundamental physical laws and our notions of cause and effect seem to be time-asymmetric. If you knock one billiard ball against another and replay it in reverse, it looks just as plausible. Our sense of time might not be a feature of the universe. The future is just as real as the past, and the present isn't very special ("B Theory of Time" in philosophy). Quantum indeterminacy doesn't actually change this. Change my mind.

There is no time

only clocks

(or calendars)

Whence clocks?

Time/Clock Categories

  • Fundamental Unit Time is good for measuring durations, which is why it is pegged to a Cesium rather than the uneven rotation of the earth (good for high-precision timing)
  • Solar Time seeks to base dates/time on Earth's rotation or position relative to the sun (good for agricultural and most human reasons)
  • Siderial Time seeks to base dates/time on Earth's rotation or position relative to the stars (relevant for celestial navigation)
  • Ephemeris Time adds in relativistic effects based on a body's trajectory, and uhhhhh, not sure what exactly this is useful for except GPS corrections?

Solar Time

Sidereal Time

Duration

Whence standard clocks?

TRAINS

  • Town had a big clock everyone used to set their time
  • Sync big clocks to sun zenith
  • ...or don't! Who's to know who is right, let's just enjoy the anarchy
  • Trains have schedules to keep, but how do we know if the train is on time or if the town has a shitty clock
  • We can now travel at speeds and distances where one city might have a celestial noon more than an hour off

UTC (Coordinated Universal Time)

  • Everyone else wanted CUT, but France wanted temps universel coordonné, so nobody's happy. Thanks, France! You tried to make revolutionary time happen, but nobody listened, get over it
  • GMT is no longer an international standard, but a British timezone, and may change without international coordination. Don't say GMT!
  • There are multiple kinds (UT0, UT1, UT2, UT1R, ...)

Modern/Standardized Time

  • Second 9,192,631,770 periods of the radiation from Cesium 133 for now
  • Minute 60 seconds
  • Hour 60 minutes
  • Day 1 complete rotation of the earth
  • Week 7 days
  • Year 365 days most years; 366 unless the year is divisible by 4; 365 if the year is divisible by 100; but 366 if divisible by 400...very close to a "solar year" (earth revolving once around the sun)
  • Leap Second Since a day is equal to 1 rotation and seconds have a fixed duration, and the earth's rotation is not constant, the International Earth Rotation and Reference Systems Service announces leap seconds at certain times of year for now

Time Fallacies

  • There are the same number of seconds in a day Daylight Savings, Leap Seconds
  • There are the same number of seconds in a particular clock hour Leap Seconds
  • Every day has 24 hours Daylight Savings
  • Every time is unique to the day Daylight Savings
  • Sometimes the scratched-out things are true DEPENDING ON THE CLOCK!

Computer Timekeeping

  • Conceptually, time to a CPU is based on the clock signal
  • CPU time can fluctuate with the temperature
  • Wall clock time may be kept on a Real Time Clock (RGC) if available
  • RTCs have temperature-compensating functionality, and quartz-based RTCs are accurate on the order of a second per year
  • RTCs might not be in internet-connected devices/servers, or in some embedded environments (cost savings)
  • Modern OSs maintain different levels of time, with some being synchronized to the RTC or to an NTP server, presenting an interface that tries to show a compromise position of all kinds of time
  • When RTCs are not present, weirdness can follow...imagine booting up with a time of 2000 and then network time syncing to 2021...how do you smooth that without being in the wrong decade?

Computer Time

  • There are different time APIs that prioritize different properties of time, but sometimes the same API behaves different across operating systems
  • The UNIX specifications for time are incomplete, so all sorts of things can happen, seconds may last more or less than a second depending on the OS
  • If you want to truly get into the nitty gritty, you really need to basically write tests and then just change the time of the OS and see what happens
  • The BSDs, being sticklers for correctness, actually have integrated leap second support, Linux tends to just rely on NTP time stretching to just line everything back up together
  • Run any server in UTC only, please
  • Support for these subtle time differences differ a lot between OSs

Time Libraries

  • The best time libraries are written by people who do the reading and have copious documentation, for a good example see Luxon in javascript
  • Generally speaking, doing time arithmetic in time libraries focuses on using durations for seconds, minutes and hours and any units larger than a day increment by a number of "days", rounding up into the next month and year
  • Unix timestamps are tempting, but good time libraries will use a struct or object, libraries using unix timestamps internally will likely not implement the above correctly
  • If you see += or * 86400 or equivalents, this is most certainly a code smell and will break on edge conditions

Time Zones

  • Time Zones are: A geographic area that observes a uniform time for legal, commercial, and social purposes over a period of time
  • There are hundreds of time zones, not all of which are in hourly offsets from UTC, but may be 15 or 30min off
  • IANA maintains the official database, updated several times per year
  • Distributed as 2 different datasets, one for current/future timezones, and one for past timezones that are no longer in use
  • Timezones reference political boundaries that can be downloaded separately as shapefiles so you can convert GPS coordinates to an active timezone
  • They are named after the largest city within the geographic area, since timezone boundaries change as political boundaries change, eg America/Chicago short abbreviations such as EDT, EST, CDT, CST, PST, PDT is discouraged because they're not unique

"Political Boundaries"

Time Zones

Most Important Slide

Properties of Time to Consider When Using Time:

  • Monotonicity: the time returned from a function always increases, is never equal or lesser than a previous value (important for multithreading!)
  • Duration Accuracy vs UTC Accuracy: seconds are actually close approximations to real seconds, rather than time-stretched seconds. Duration hours and minutes are multiples of seconds, but UTC hours and minutes may or may not have equal duration
  • Logging events should always be done in UTC
  • Software that handles dates for human-relevant event planning and coordination should always be explicit about what time zone they use, and should use a user-set timezone. Meeting at a conference a next year at 3pm local time is more accurate than the UTC date because rules can change

Most Important Slide 2

Using time in functions

  • Time is a side effect, not a pure function, multiple calls return different values
  • If your language allows, design functions to receive a date rather than call now() or time() itself, only generating a current time as a default value or if something null or false-y is passed in
  • If you are running periodic reports and rollups, do not assume you will run once per period, but keep track of what last period completed for that job, and then run a report for each completely period between now and the last complete time
  • Most delay/sleep/interval/timeout functionality is an "at least" duration, garbage collection can really stretch out small intervals

Time Sorting

  • One of the more advanced and more important bits about time is sorting events in a consistent way
  • Replaying events or re-evaluating them in a different order because of timestamp inaccuracy or ambiguity can cause consistency problems
  • This is very important for distributed computing

Optimistic Concurrency Ctrl

  • If you read-modify-write data in a cycle that lasts more than a few milliseconds, you can add a timestamp to your as a precondition (WHERE clause or HTTP If-Unmodified-Since header) in order to implement "optimistic concurrency control"
  • But you don't even need to use a timestamp in the data, you can increment a version number...in this case, time is "logical" rather than being tied to a clock

Distributed Computing

  • Time in distributed computing is more logical than it is actual
  • Thanks to relativity, 2 computers synchronization is only so accurate, even with NTP
  • Clock accuracy doesn't matter anyway for those of us not on re
  • You can catch some vendors claiming to violate the laws of physics about their databases if they claim
  • The speed of light in fiberoptic cable is 124,188 miles per second, or 124 miles per millisecond, and databases in different datacenters may only reach consensus with each other as fast as they can communicate...realistic theoretical minimum east to west coast latency is 60ms

Vector Clocks

Fin

Time

By asonge

Time

  • 95