Fireship · @fireship

Time… a programmer's worst enemy // The Code Report

Uploaded March 17, 2022 · Length 3:06

Time… a programmer's worst enemy // The Code Report

Summary

The video discusses the complexities of time, including time zones, leap seconds, and the Gregorian calendar, and proposes alternatives like the Cotsworth plan.

  • time zones
  • leap seconds
  • gregorian calendar
  • temporal api
  • javascript dates

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:01

    it is march 17 2022 and you're watching

  2. 0:04

    the code report it's about time we had a

  3. 0:06

    talk about time you would think it's a

  4. 0:08

    pretty simple concept time began on

  5. 0:10

    january 1st 1970 with the unix epic at

  6. 0:13

    any moment we can get the number of

  7. 0:15

    milliseconds elapsed from this date on

  8. 0:16

    any computer using a method like date

  9. 0:19

    now this is called incremental time but

  10. 0:21

    one problem is that the earth doesn't

  11. 0:22

    rotate evenly because it's actually flat

  12. 0:24

    and the international earth rotation

  13. 0:26

    service occasionally mandates a leap

  14. 0:28

    second where an additional second is

  15. 0:30

    added to the last minute of the day

  16. 0:31

    things start getting weird when we talk

  17. 0:33

    about time zones which are calculated

  18. 0:35

    relative to greenwich mean time on the

  19. 0:37

    pacific we subtract eight hours but in

  20. 0:39

    newfoundland they only subtract three

  21. 0:40

    and a half hours and in nepal they add

  22. 0:42

    five and three quarters then daylight

  23. 0:44

    savings comes around and all the time

  24. 0:46

    zones change except in places like

  25. 0:48

    arizona and hawaii that don't do a time

  26. 0:50

    change in the south pacific they're 13

  27. 0:52

    hours ahead which requires them to skip

  28. 0:54

    an entire day you could celebrate new

  29. 0:56

    year's on christmas island spend the

  30. 0:57

    entire next day recovering from your

  31. 0:59

    hangover then fly to jarvis island in

  32. 1:01

    time to celebrate new year's eve again

  33. 1:03

    now when it comes to the entire year the

  34. 1:05

    gregorian calendar is a ridiculous

  35. 1:06

    abstraction some months have 28 days

  36. 1:08

    while others have 31 but every other

  37. 1:11

    counting system we use like weeks and

  38. 1:12

    days have consistent intervals it

  39. 1:14

    doesn't have to be this way the

  40. 1:16

    cotsworth plan which was presented in

  41. 1:17

    1902 divides the year into 13 months

  42. 1:20

    each month with four weeks or 28 days

  43. 1:23

    with one rest day somewhere in the

  44. 1:24

    middle it makes so much more sense and

  45. 1:26

    aligns better with the lunar cycle for

  46. 1:28

    developers it would make the complicated

  47. 1:29

    matter of finding the duration of

  48. 1:31

    multiple months a simple matter of

  49. 1:33

    multiplying by 28 but there may be some

  50. 1:35

    good news when it comes to keeping track

  51. 1:36

    of time there's a bill going through

  52. 1:38

    congress right now to get rid of

  53. 1:39

    daylight savings honestly it doesn't go

  54. 1:41

    far enough and i wish they would also

  55. 1:42

    get rid of the gregorian calendar this

  56. 1:44

    could be bad news though for low-level

  57. 1:46

    systems programmers who figured out all

  58. 1:47

    these weird rules with time zones i

  59. 1:49

    imagine this is the type of code that

  60. 1:50

    nobody wants to touch but if we get rid

  61. 1:52

    of daylight savings somebody will have

  62. 1:54

    to go in there and change things

  63. 1:55

    speaking of changes there is a stage 3

  64. 1:57

    proposal for the temporal api in

  65. 1:59

    javascript which would make it much