Skip to content

Instantly share code, notes, and snippets.

@lancejpollard
Last active April 23, 2024 09:12
Show Gist options
  • Save lancejpollard/4f2823c0046c1758dfae2bf133717c70 to your computer and use it in GitHub Desktop.
Save lancejpollard/4f2823c0046c1758dfae2bf133717c70 to your computer and use it in GitHub Desktop.
Universal Time Representation (Idea)

A DateTime should really be treated as a TimeSpan which is taken as the difference from a standard reference point (like Jan 1, 1970). Something like that:

// 2024
const y2024 = { year: 2024 } | { thousand: 2, year: 24 }
// 2000BCE = -2000 - 1970
const y2000bce = { year: -3970 }
// 13.8bya
const t13_8bya = { billion: -13, million: -8 }

Something along these lines perhaps?:

type int2 = number // really, 2 bytes

type TimeSpan = {
  nanosecond: int2
  microsecond: int2
  millisecond: int2
  second: int2
  minute: int2
  hour: int2
  day: int2
  week: int2
  month: int2
  year: int2
  decade: int2
  century: int2
  // You only need to store up to 999 thousand before doing million: 1
  thousand: int2
  million: int2
  billion: int2
}

// circa 1900 ± 100y
// { mark: { year: 1900 }, fuzz: { start: { year: 1800 }, end: { year: 2000 } } }
type TimePoint = {
  mark: TimeSpan
  fuzz: {
    start: TimeSpan
    end: TimeSpan
  }
}

type TimeRange = {
  start: TimePoint
  end: TimePoint
}

If it was compacted toward the largest value (so { thousand: 2, decade: 2, year: 4 } instead of { year: 2024 }), then each value would have a unique representation.

https://twitter.com/growing_daniel/status/1781922919893057790

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment