dbTalk Databases Forums  

[BUGS] "Julian day" date format is off by 12 hours

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] "Julian day" date format is off by 12 hours in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David Lee Lambert
 
Posts: n/a

Default [BUGS] "Julian day" date format is off by 12 hours - 12-08-2006 , 04:48 PM






Postgres version: 8.0.6
Operating system: Ubuntu GNU/Linux

I executed the following query while trying to build some date-conversion
functions for data that was represented as milliseconds since the Unix epoch:

davidl=# SELECT to_char(timestamp '1970-01-01 00:00:00 GMT','J SSSS MS');
to_char
---------------
2440588 0 000
(1 row)

However, Postgres's notion of a "Julian Day" does not match the
generally-accepted definition. According to the generally-accepted
definition, the result of the query above should be

2440587 43200 000

; that is, 12 hours past noon on Julian day 2440687, which started at noon
on December 31st, 1969, GMT.

I'm not sure if this should be regarded as a database bug or a documentation
bug. Table 9-21 in the manual only says that a Julian day is "days since
January 1, 4712 BC", so Postgres is consistent with the manual; but every
other definition of a Julian day I've found says that it starts at noon.

The Wikipedia article has several good references:

http://en.wikipedia.org/wiki/Julian_day

--

Software Developer, Precision Motor Transport Group, LLC
Work phone 517-349-3011 x215
Cell phone 586-873-8813

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Reply With Quote
  #2  
Old   
Bruce Momjian
 
Posts: n/a

Default Re: [BUGS] "Julian day" date format is off by 12 hours - 02-03-2007 , 05:57 PM







Since to_char() is supposed to be Oracle-compatible, would someone test
this query in Oracle?

---------------------------------------------------------------------------

David Lee Lambert wrote:
Quote:
Postgres version: 8.0.6
Operating system: Ubuntu GNU/Linux

I executed the following query while trying to build some date-conversion
functions for data that was represented as milliseconds since the Unix epoch:

davidl=# SELECT to_char(timestamp '1970-01-01 00:00:00 GMT','J SSSS MS');
to_char
---------------
2440588 0 000
(1 row)

However, Postgres's notion of a "Julian Day" does not match the
generally-accepted definition. According to the generally-accepted
definition, the result of the query above should be

2440587 43200 000

; that is, 12 hours past noon on Julian day 2440687, which started at noon
on December 31st, 1969, GMT.

I'm not sure if this should be regarded as a database bug or a documentation
bug. Table 9-21 in the manual only says that a Julian day is "days since
January 1, 4712 BC", so Postgres is consistent with the manual; but every
other definition of a Julian day I've found says that it starts at noon.

The Wikipedia article has several good references:

http://en.wikipedia.org/wiki/Julian_day

--

Software Developer, Precision Motor Transport Group, LLC
Work phone 517-349-3011 x215
Cell phone 586-873-8813

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq
--
Bruce Momjian bruce (AT) momjian (DOT) us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq


Reply With Quote
  #3  
Old   
Shelby Cain
 
Posts: n/a

Default Re: [BUGS] "Julian day" date format is off by 12 hours - 02-04-2007 , 12:19 AM



Oracle (9.2.0.7) doesn't seem to like the date format string...

SQL> SELECT to_char(timestamp '1970-01-01 00:00:00 GMT','J SSSS MS') from d=
ual;
SELECT to_char(timestamp '1970-01-01 00:00:00 GMT','J SSSS MS') from dual
*
ERROR at line 1:
ORA-01821: date format not recognized

Regards,

Shelby Cain

----- Original Message ----
From: Bruce Momjian <bruce (AT) momjian (DOT) us>
To: David Lee Lambert <dlambert (AT) bmtcarhaul (DOT) com>
Cc: pgsql-bugs (AT) postgresql (DOT) org
Sent: Saturday, February 3, 2007 5:56:00 PM
Subject: Re: [BUGS] "Julian day" date format is off by 12 hours


Since to_char() is supposed to be Oracle-compatible, would someone test
this query in Oracle?
Quote:
=20
davidl=3D# SELECT to_char(timestamp '1970-01-01 00:00:00 GMT','J SSSS MS'=
);
to_char
---------------
2440588 0 000
(1 row)
=20





=20
__________________________________________________ _________________________=
_________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


Reply With Quote
  #4  
Old   
Bruce Momjian
 
Posts: n/a

Default Re: [BUGS] "Julian day" date format is off by 12 hours - 02-19-2007 , 04:57 PM




I did some research on this, and because Oracle fails with that query,
we can't use them as a guide.

What is happening in the code is that the "J" is independent from the
"SSSS" and "MS", so you are getting a "J" based on the date (assuming
midnight start/stop), and not on the actual time in the rest of the
timestamp.

As you stated, to do this correctly 11:59am would have a different
Julian date from 12:01pm. However, I think this would make "J" much
less useful because the most common use assumes midnight to 11:59pm is
the same day number. What I did was to update the documentation to say
explicitly "midnight":

Julian Day (days since midnight, January 1, 4712 BC)

I didn't document that we don't follow the specification, but the
"midnight" should be a hint for those who know about it.

---------------------------------------------------------------------------

bruce wrote:
Quote:
Since to_char() is supposed to be Oracle-compatible, would someone test
this query in Oracle?

---------------------------------------------------------------------------

David Lee Lambert wrote:
Postgres version: 8.0.6
Operating system: Ubuntu GNU/Linux

I executed the following query while trying to build some date-conversion
functions for data that was represented as milliseconds since the Unix epoch:

davidl=# SELECT to_char(timestamp '1970-01-01 00:00:00 GMT','J SSSS MS');
to_char
---------------
2440588 0 000
(1 row)

However, Postgres's notion of a "Julian Day" does not match the
generally-accepted definition. According to the generally-accepted
definition, the result of the query above should be

2440587 43200 000

; that is, 12 hours past noon on Julian day 2440687, which started at noon
on December 31st, 1969, GMT.

I'm not sure if this should be regarded as a database bug or a documentation
bug. Table 9-21 in the manual only says that a Julian day is "days since
January 1, 4712 BC", so Postgres is consistent with the manual; but every
other definition of a Julian day I've found says that it starts at noon.

The Wikipedia article has several good references:

http://en.wikipedia.org/wiki/Julian_day

--

Software Developer, Precision Motor Transport Group, LLC
Work phone 517-349-3011 x215
Cell phone 586-873-8813

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

--
Bruce Momjian bruce (AT) momjian (DOT) us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +
--
Bruce Momjian <bruce (AT) momjian (DOT) us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.