the board here has some ridiculous idea that I have to make a post before I can message anybody. So - feel free to ignore me, either one of you will answer this or I'll finally have the ability to ask the original post owner the way I had intended.
This code for calculating the julian date:
// Calculate difference in days between the current Julian Day
// and JD 2451545.0, which is noon 1 January 2000 Universal Time
long int liAux1;
long int liAux2;
// Calculate time of the day in UT decimal hours
dDecimalHours = udtTime.dHours + (udtTime.dMinutes
+ udtTime.dSeconds / 60.0 ) / 60.0;
// Calculate current Julian Day
liAux2=(1461*(udtTime.iYear + 4800 + liAux1))/4 + (367*(udtTime.iMonth
- 2-12*liAux1))/12- (3*((udtTime.iYear + 4900
// Calculate difference between current Julian Day and JD 2451545.0
dElapsedJulianDays = dJulianDate-2451545.0;
...is giving me a royal headache. What does liAux1 and liAux2 represent? I'm a seasoned C developer and I just can't seem to follow the logic behind this calculation. Seems it would be easier to just count the days from Jan 1, 2000 - and it would be much easier to verify that you get the correct result.
Anyone who could give me some insight into mowicus's thought process with this would be most appreciated.
The calculation for dJuiianDate in that program converts a Gregorian Calendar date to a Julian day, and is valid for all Gregorian dates after 4800 B.C.E. Maybe it is a bit much.
Anyhow, I (probably) would have used the calculations here: Julian day - Wikipedia
They are similar (but not exactly the same) as what you have in your sketch.
In the wikipedia example, the value of a is equal to 1 for month = 1 or month = 2 and zero for months 3 through 12. That value is subtracted from a bunch of other stuff.
In your program, the value of liAux1 is equal to -1 for month = 1 or month = 2 and is zero for months 3 through 12. That value is added to a bunch of other stuff.
(I'll leave it up to you to decide whether the "other stuff" gives same values for the two methods.)
Now, what is the significance of that particular calculation? That is: What is special about months 1 and 2 compared to months 3 through 12?
Calculations involving months after month 2 (February) have to take into account whether it is a leap year or not.
Have fun with your calendar!
Well that bit of code was basically just stolen from someone else but seemed to work fine so I stuck with it. I have to admit I have not looked into it a massive amount for that reason.
Thanks for the clarification. I did read a wikipedia article describing the julian calendar, but it didn't show the calculation or any algorithms for it. I did actually calculate it a different way, but I wanted to verify my results and that's when I ran into the above piece of code here in the forum - which given the fact that I hadn't seen the other wikipedia article, seemed confusing at best.
My algorithm very simply uses a while loop with a function called isLeapYear(x) to determine whether to add 365 or 366 to the total figure starting from Jan 1st, 2000. From there it's a simple matter to add the days for each month plus the day in the current month to come up with the JDN value.
I'm curious why January is considered special, though. It has the same number of days whether it be a leap year or not, IIRC. My value doesn't exactly match up with some other calculators, so that may explain it.
wikipedia article describing the julian calendar, but it didn't show the calculation
Oh, I get it. Well here's the deal: Julian calendar is not the same as Julian day. The problem with looking things up is that if you don't know specifically what to look for, you might miss out on a lot.
For others who are interested: Click on this link: Julian Day - Wikipedia
Scroll down to where it says "Converting Gregorian calendar date to Julian Day Number." There's the formula. It doesn't explain much, but it gives us something to think about. Reference  on the Wikipedia web page gives more explanation (a lot more) and, maybe, some more insight.
why January is considered special,
January and February are both special. When counting days from January 1 of any given year, for the months of January and February you don't need to know whether or not it is a leap year. For months after February, you (obviously) do need to know whether it is a leap year.
"Converting Gregorian calendar date to Julian Day Number." There's the formula. It doesn't explain much
It's one of those "magic algorithms" from the dawn of the computer age (or before?) I'm pleased that wikipedia has a explanatory reference; I'll have to read it sometime...
The problem I have with the wikipedia calculation for the JDN is that it depends on integer division where numbers are implicitly truncated. In my experience that's a very bad thing to do - it obscures the purpose/intent of the calculation and if someone after the fact tries to reuse that code without knowing about that 'feature', it causes problems down the road.
Maybe I'm being a bit of a purist but I would prefer a calculation that I could put into any environment - floating point or not - and get the right number. Furthermore, it would be nice if the resulting code was easy to understand for others who may use it after me. Getting a result isn't the entire goal, but I would rather help others to understand it as well. I guess I have some reading to do this weekend...
Thanks everyone for the help though - you've all given me a much deeper explanation than I thought I would get.
Furthermore, it would be nice if the resulting code was easy to understand for others who may use it after me. Getting a result isn't the entire goal, but I would rather help others to understand it as well. I guess I have some reading to do this weekend...
I don't know if they are still in fashion or not, but back in the day you could find colleges and universities holding "programming contests", where students could compete for recognition, trophies, etc. Sometimes there would even be a high-school and middle-school levels...
Anyhow - invariably at these contests, one of the challenges (which were timed) was to create some kind of algorithm for calculation of calendars and/or dates given such-and-such parameters. It really wasn't the easiest of tasks, which I imagine is why it was always included...