8

In the Thrift IDL there isn't a Date type. What's the best cross language mechanism to represent a date object. I think there are 2 ideal candidates but I'd love to hear other ideas.

  1. String - in each language you could use something like strftime to convert the date back.
  2. i32 - Time since epoch can be converted back.

I'm sure there are other things to think about besides conversion. Hoping people out there have some good feedback.

JensG
  • 13,148
  • 4
  • 45
  • 55
Bryan M
  • 183
  • 1
  • 6

2 Answers2

11

tldr; use an appropriate-encoded string unless there is a reason to do otherwise.

It depends on what is required. Here are some differences - keep in mind that modern computers are fast and conversion is likely only a small fraction of overall application time so "more processing" is generally not even be applicably measurable!

String (with ISO 8601 or the stricter XML dateTime):

  • "more space" / "more processing" (see above) / fixed size or variable size
  • standardized culture-neutal format
  • human readable and easily identifiable
  • supports timezones
  • more range (-9999 to 9999)
  • more/arbitrary precision (up to 1us)
  • lexicographically ordered (within same timezone and compatible format)

Epoch (UNIX variant):

  • "less space" / "less processing" / fixed size
  • standardized culture-neutral format
  • not human readable (a diligent coder should be able to identify "about now")
  • no timezones (can't even distinguish between "local" and UTC)
  • less range (1970 to 2034 with a signed 32-bit number)
  • less/fixed precision (1 second)
  • numerically ordered

(The Julian day is another encoding with many similarities to an Epoch time.)

Conclusion:

Unless space/performance is a proven issue - this requires a performance analysis and functional requirements - I'd pick the former. Computers today are a good bit faster than computers just a few years ago and much, much faster than computers decades old.

  • like this answer. human readable date time representation saves lots of debug time. – misaxi Jul 15 '13 at 05:10
  • This is likely to never get read, but "no timezones" is one of the *benefits* of a UNIX timestamp. All times are always represented in UTC. Simple, easy, effective, no ambiguity. – Colin M Aug 18 '13 at 12:54
0

Just for posterity, you may be interested in temporenc (http://temporenc.org), a comprehensive binary encoding format for dates and times.

wouter bolsterlee
  • 3,879
  • 22
  • 30