In Apache Thrift How to Represent Object Objects

IDL Trift does not have a Date type. What is the best cross language mechanism for representing a date object. I think there are two ideal candidates, but I would like to hear other ideas.

  • String - in each language, you can use something like strftime to convert the date.
  • i32 - Time elapsed from an era can be converted back.

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

+6
source share
2 answers

TL; DR; use a string with the appropriate encoding if there is no reason for this.

It depends on what is required. Here are some differences - keep in mind that modern computers are fast, and conversion probably only accounts for a small fraction of the total application time, so “big processing” usually cannot be measurable!

String (with ISO 8601 or more stringent XML dateTime ):

  • "more space" / "more processing" (see above) / fixed size or variable size
  • standardized cultural neutral format
  • easy to read and easily identifiable
  • supports time zones
  • more range (-9999 to 9999)
  • greater / arbitrary accuracy (up to 1us)
  • lexicographically ordered (in the same time zone and compatible format)

Age (UNIX variant):

  • "less space" / "less processing" / fixed size
  • standardized neutral neutral format
  • not readable by humans (a conscientious coder should be able to identify "now")
  • no timezones (cannot even distinguish between "local" and UTC)
  • smaller range (from 1970 to 2034 with a signed 32-bit number)
  • less / fixed accuracy (1 second)
  • numerical ordering

( Julian Day is another encoding with many similarities to the time of the era.)

Conclusion:

If space / performance is not a proven issue, this requires performance analysis and functional requirements - I would choose the first one. Today computers are a little faster than computers just a few years ago, and much, much faster than computers decades ago.

+8
source

For posterity only, you may be interested in timeenc ( http://temporenc.org ), the full binary encoding format for dates and times.

+1
source

All Articles