سؤال

I'm currently writing some php code to convert dates from the Gregorian Calendar to the Hebrew Calendar. Looking at the php calendar functions, I found that it has functions to convert from Gregorian to Julian days and Julian days to Hebrew. However, there is no function I could find to directly convert from Gregorian to Hebrew.

Out of curiousity, I wanted to see if a direct conversion was possible. While researching this though, I found that it seems to be standard to convert dates to Julian days, and then to the desired calendar system.

I found this in a few libraries like: http://www.php.net/manual/en/ref.calendar.php http://www.fourmilab.ch/documents/calendar/calendar.js

and mentioned on a forum post here: http://www.physicsforums.com/showthread.php?t=173119

Whats bugging me is why! Is it a standard decided on by some group? Is it just done this way historically?

Wouldn't it be more efficient to come up with algorithms to directly convert dates? or conversely, what makes Julian days so efficient?

هل كانت مفيدة؟

المحلول

If you want to convert between n different calendars and you implemented algorithms to go from any one format to any other format, you would need n^2 - n conversion algorithms. However if instead wrote algorithms to convert any calendar format to one baseline calendar format and then wrote algorithms to convert from the baseline format to any other format you only need to write 2(n-1) algorithms.

These calendar formats are all representing the same thing, time. The most basic way to represent a time is as the amount of time elapsed since some reference point, so that makes the most sense as a baseline format. This is exactly what Julian Date is, the number of days since January 1, 4713 BC Greenwich noon.

You might think that it would be slower converting from one format to Julian Date then to another format, however any specialized conversion algorithm is essentially going to take the input date, convert it to some neutral go between date representation and then convert that to the desired calendar format. However since Julian Date is a simple single number format this is effectively the same as converting to Julian Date and then converting to some other format so the performance gain would be negligible. Also calendar conversions are probably not the bottleneck of any application's performance so squeezing the most possible performance out of them is probably not a good use of anyone's time.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top