1

In a side project I have to manage, compare and display dates from different formats. What's the best design strategy to follow?

I planned:

  1. All dates are parsed according their format and stored in the db in 9-tuple python format using UTC
  2. When I have to do calculations and compares I transform 9-tuple in datetime object (using UTC). If I have to store back some date calculation I use again 9 tuple format
  3. On user interface time is display converting from UTC to user's timezone

Have you any feedback about this strategy?

pierocampanelli
  • 960
  • 5
  • 19

1 Answers1

2

I'd use the DB's native datetime format rather than this "9-tuple" format. It'll make queries easier, and it's probably more space-efficient too.

Shouldn't be too hard to convert from that back into a Python datetime object. You can use the dateutil module if you're having trouble.

I think you're right about keeping a consistent timezone throughout the DB though, and the convert it to the user's timezone when you need to.

mpen
  • 272,448
  • 266
  • 850
  • 1,236