PDA

View Full Version : Incorrect Julian Day



Rayven
13th June 2009, 03:30
Given the following code:


QDate test( 2009, 2, 10 );

qDebug( ) << test.toJulianDay( ) << " " << QDate::fromJulianDay( 41 );


I would expect the results to be:
41 QDate( "Sat Feb 10 -4713" )

Instead I get the results
2452873 QDate( "Sun Feb 11 -4713" )

I know this result is not correct and I have submitted a bug to the Trolls (or is it Nokias now?). Here is a quick workaround, if you know the Julian Day:



QDate test( 2009, 1, 1 );
test = test.addDays( julianDate - 1 );

ChrisW67
14th June 2009, 05:21
Why would you expect test.toJulianDay( ) to give you 41 when test is set to 10 Feb 2009?

Lykurg
14th June 2009, 07:12
Why would you expect test.toJulianDay( ) to give you 41 when test is set to 10 Feb 2009?

Yepp!


Given the following code:


QDate test( 2009, 2, 10 );
qDebug( ) << test.toJulianDay( ) << " " << QDate::fromJulianDay( 41 );

[...]
Instead I get the results
2452873 QDate( "Sun Feb 11 -4713" )

Really? I get 2454873 QDate("Sun Feb 11 -4713")


JD 41.00000 is
BCE 4713 February 11 12:00:00.0 UT Sunday

JD 2454873.00000 is
CE 2009 February 10 12:00:00.0 UT Tuesday

Rayven
15th June 2009, 03:24
Why would you expect test.toJulianDay( ) to give you 41 when test is set to 10 Feb 2009?
Because DOY 41 is Feb 10, not the 11th.

So did you get this error too Lykurg?

ChrisW67
15th June 2009, 04:39
The Julian Day Number is not the day-of-year that you seem to be expecting. It is the whole number of days since January 1, 4713 BC Greenwich noon (Julian proleptic calendar), which is why you get a large number, and not 41. It is useful for calculating intervals between dates without fussing over leap years etc.
http://en.wikipedia.org/wiki/Julian_day_number

For the day of the year you would want something like:
QDate test(2009, 2, 10);
qDebug() << test << test.dayOfYear();which gives:
QDate("Tue Feb 10 2009") 41 as you are expecting.

Rayven
15th June 2009, 13:17
Ahh, then my understanding of Julian Day is incorrect! Thanks so much, it makes more sense now.

Abeshenkov
16th November 2011, 13:10
Julian date is not really correct. If we look to define a, but at least the same wikipedia, the Julian date is from half a day. In this era a new date begins at midnight. Correspondingly, at the beginning of our day Julian date is not a whole!
This is not to say that the need of local time zones go to Greenwich's time. And it may happen that even in Greenwich yesterday or tomorrow already.