开发者

Is there a benefit to using Julian Dates in code?

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.


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.


Julian Dates, I know, this is php orientated question, would be more suited for large billing systems running on the Mainframes, notably in COBOL, it it purely to make it easier to calculate the days from the start of billing to the end of billing. That is the only thing I can think of where Julian Dates are used, especially in legacy COBOL codes...I am not 100% confident what is used now, I would imagine proper formatted dates (Y2K bug was an non-existant thing that was incredibly hyped up!)...

Hope this helps, Best regards, Tom.


I can't see any reason not to use the Date class. You can go back and forth between unixtime (albeit flash uses milliseconds instead of seconds) very easily using that, so that's what I'd recommend using for communications back and forth.

And another gotcha; If you decide to use regular unixtime, you can't use the int/uint datatypes in Flash because they will overflow, you will have to use Number.


numeric dates, such as Julian Dates or Unix epoch are much easier for calculations ... the time in n hours or the time difference between two arbitrary dates can be calculated extremely easily ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜