Results 1 to 7 of 7

Thread: Incorrect Julian Day

  1. #1
    Join Date
    Jan 2006
    Location
    Third rock from the sun
    Posts
    106
    Thanks
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Incorrect Julian Day

    Given the following code:
    Qt Code:
    1. QDate test( 2009, 2, 10 );
    2.  
    3. qDebug( ) << test.toJulianDay( ) << " " << QDate::fromJulianDay( 41 );
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. QDate test( 2009, 1, 1 );
    2. test = test.addDays( julianDate - 1 );
    To copy to clipboard, switch view to plain text mode 
    Every little child knows
    if you cant see dreams
    your eyes are blind

    Moxy Fruvous

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Incorrect Julian Day

    Why would you expect test.toJulianDay( ) to give you 41 when test is set to 10 Feb 2009?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Incorrect Julian Day

    Quote Originally Posted by ChrisW67 View Post
    Why would you expect test.toJulianDay( ) to give you 41 when test is set to 10 Feb 2009?
    Yepp!

    Quote Originally Posted by Rayven View Post
    Given the following code:
    Qt Code:
    1. QDate test( 2009, 2, 10 );
    2. qDebug( ) << test.toJulianDay( ) << " " << QDate::fromJulianDay( 41 );
    To copy to clipboard, switch view to plain text mode 
    [...]
    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

  4. #4
    Join Date
    Jan 2006
    Location
    Third rock from the sun
    Posts
    106
    Thanks
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Incorrect Julian Day

    Quote Originally Posted by ChrisW67 View Post
    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?
    Every little child knows
    if you cant see dreams
    your eyes are blind

    Moxy Fruvous

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Incorrect Julian Day

    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:
    Qt Code:
    1. QDate test(2009, 2, 10);
    2. qDebug() << test << test.dayOfYear();
    To copy to clipboard, switch view to plain text mode 
    which gives:
    Qt Code:
    1. QDate("Tue Feb 10 2009") 41
    To copy to clipboard, switch view to plain text mode 
    as you are expecting.

  6. The following user says thank you to ChrisW67 for this useful post:

    Rayven (15th June 2009)

  7. #6
    Join Date
    Jan 2006
    Location
    Third rock from the sun
    Posts
    106
    Thanks
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Incorrect Julian Day

    Ahh, then my understanding of Julian Day is incorrect! Thanks so much, it makes more sense now.
    Every little child knows
    if you cant see dreams
    your eyes are blind

    Moxy Fruvous

  8. #7
    Join Date
    Nov 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Incorrect Julian Day

    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.

Similar Threads

  1. Qt 3 on CentOS 5: page size incorrect
    By agajania in forum Installation and Deployment
    Replies: 0
    Last Post: 30th April 2009, 23:04
  2. incorrect QGraphicsItemGroup mouse drag behavior
    By Gopala Krishna in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2008, 10:05
  3. QSvgRenderer::boundsOnElement returns incorrect QRectF
    By lfranchi in forum Qt Programming
    Replies: 8
    Last Post: 1st August 2007, 09:49
  4. Mysql + QSqlTableModeil: incorrect locale
    By blackliteon in forum Qt Programming
    Replies: 5
    Last Post: 10th February 2006, 16:07
  5. QTextEdit produces incorrect html
    By ccf_h in forum Qt Programming
    Replies: 5
    Last Post: 8th February 2006, 15:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.