Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a benefit to using Julian Dates in code?

Tags:

date

php

flash

I maintain a PHP/Flash app that uses Julian dates within the code and only converts to Gregorian for display. Before I replace the integer Julian dates with a Date data-type I was wondering if there was a benefit to using the Julian? Should this even be changed?

One of the problems is being able to quickly look at dates in the database. I added a Date-Time Stamp to one of the tables to correct this but now we are moving to a new DB and have the opportunity to make improvements so moving away from the Julian date seems like the thing to do. So why would I not want to do this? The original developer is no longer here.

like image 856
Todd Moses Avatar asked Feb 27 '23 13:02

Todd Moses


1 Answers

For date/time management, you want all your instants to use a simple, monotonous, linear scale. Human calendars, time zones, daylight saving time, these make things more complex and are best kept in the display layer.

A common scale is to encode instants as a number of seconds (or milliseconds) since a specific origin. In Java, you would use milliseconds since January 1st, 1970, at 00:00:00 UTC (also known as "the Epoch"); you would also ignore leap seconds, so that conversions to any date and time in any calendar are purely algorithmic. That scale is what System.currentTimeMillis() returns. In a Unix world, you may use the number of seconds since the Epoch, since this is what the Unix kernel is prone to return (through the time() system call).

Such linear scales make it easy to compare dates and compute time intervals, while anything calendar-based makes such computations more difficult.

So my advice would be to move away from Julian dates, but certainly not to convert them to Gregorian dates. Quite the opposite, actually.

like image 102
Thomas Pornin Avatar answered Mar 05 '23 16:03

Thomas Pornin