{
  "$type": "site.standard.document",
  "canonicalUrl": "https://unnecessary.tech/posts/tzif",
  "path": "/posts/tzif",
  "publishedAt": "2025-09-21T13:55:03.000Z",
  "site": "at://did:plc:jx54v4rmscfwzit7fmgz24ba/site.standard.publication/3mnrsqmzz3w2e",
  "textContent": "I have been building a time zone database library\nwhich uses the IANA Time Zone Database\nfor the gleam programming language. When you start working\nwith programming and time zones you realize that time is strangely complicated\nfor computers. What seems simple to\nus—hours, days, years—is built on a foundation of physics, astronomical quirks,\nand human convention that creates enormous complexity. This post is a little\ncontext for a new time zone library I'm creating.\n\nPhysics Time vs. Human Time\n\nFrom a physics perspective, if we ignore time dialation, time is straightforward.\nIt's a dimension we use to\ndetermine when events happen. We can pick a unit, the second, and measure the\ninterval between any two events. If this were all we needed, we'd be done. We\ncould simply count the number of seconds since a starting point (an \"epoch\") and\nknow exactly when anything occurred. For computers, this epoch is often midnight\non January 1, 1970.\n\nBut we don't live our lives in seconds-from-an-epoch. We organize our society\naround recurring natural cycles: the day and the year. We schedule meetings,\nopen stores, and plan our lives based on concepts like \"8:00 AM tomorrow.\" This\nis where it starts to get complicated.\n\nThe Problem with the Earth's Motion\n\nOur primary cycle is the day: the time it takes for the sun to go from its\nhighest point in the sky back to that same point. This period is approximately\n86,400 seconds.\n\nI say \"approximately\" because the Earth's orbit around the sun is not a perfect\ncircle; it's an ellipse. This means the length of an apparent solar day (the\nactual time from one solar noon to the next) can vary by up to 30 seconds from\nthe average. To smooth this out, we use the mean solar day, which is exactly\n86,400 seconds.\n\nTo make this useful, we divide the day into 24 hours, hours into 60 minutes, and\nminutes into 60 seconds. This system, based on the position of the sun, is what\nwe use for our daily lives.\n\nThe Rise of Time Zones\n\nThis system worked well enough until travel became fast. When every town set\nits clock by its own local solar noon, the time could differ by several minutes\nfrom the next town over. This was fine when travel was by horse, but it became a\nlogistical nightmare for scheduling trains. A 30-minute train ride could result\nin a 22-minute time shift in one direction and a 38-minute shift in the other.\n\nThe solution was to coordinate. The world was divided into 24 time zones, each\ntheoretically spanning 15 degrees of longitude and differing by one hour from\nits neighbors. Everyone within a zone would agree to use the same time.\n\nOf course, political and geographic boundaries don't follow neat longitude\nlines. Countries, states, and municipalities chose which time zone to belong to,\ncreating the irregular, jagged time zone map we have today. To make things even\nmore complex:\n\n Some regions, like India and parts of Australia, are on a 30-minute offset\n  from their neighbors.\n A few places are even on 15 or 45-minute offsets.\n\nDaylight Saving Time\n\nAnother layer of complexity is Daylight Saving Time (DST). Because the length\nof a day changes with the seasons, some regions decided to shift their clocks\nforward by an hour in the summer. The goal was to better align waking hours with\ndaylight hours.\n\nThis means that twice a year, time abruptly shifts by an hour. But not everyone\nparticipates. Many countries near the equator don't observe it, and even within\nthe United States, states like Arizona and parts of Indiana opt out. This adds\nanother set of rules to an already complicated system.\n\nLeap Seconds\n\nHere is the final, and most technical, wrinkle. The idea that a mean solar day\nis exactly 86,400 seconds is also just an approximation. The Earth's rotation\nis not perfectly regular; it's gradually slowing down, but in an unpredictable\nway.\n\nTo keep our civil time (Coordinated Universal Time, or UTC) in sync with the\nEarth's actual rotation, the International Earth Rotation Service occasionally\ninserts an extra second into the clock. This is called a leap second. Since\n1970, 27 days have actually been 86,401 seconds long.\n\nMost computer systems, including Unix time, ignore this. They assume every day\nis exactly 86,400 seconds long. This makes calculating the duration between\ntwo dates simple, but it means the clock is not a true measure of the seconds\nthat have passed in the physical world. For applications that require that\nlevel of precision, you must account for these leap seconds. The official time\nzone database (the IANA database) includes special time zones (prefixed with\nright/, like right/UTC) that correctly account for every leap second ever\ninserted.\n\nConclusion\n\nSo, measuring time requires us to reconcile a precise, atomic unit (the second)\nwith a messy, irregular planet and universe. We deal with:\n\n The difference between mean and apparent solar time.\n Irregular, politically-defined time zones.\n Twice-yearly shifts for Daylight Saving Time, which aren't universally applied.\n The unpredictable insertion of leap seconds to align our clocks with the\n  Earth's wobbly rotation.\n\nHopefully, this gives you a new appreciation for the complexity\nhidden behind something as simple as looking at a clock—and why a robust\nsoftware library is necessary to manage it all.\n\n> Note: This entry was written with the assistance of a large language model.\n> I provided a 20 minute audio file of what I wanted to present, and the language\n> model transcribed the recording and organized it into an article which I\n> subsequently edited.",
  "title": "Why is Time so Complicated?"
}