Closed (fixed)
Project:
Date
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
6 Mar 2007 at 20:59 UTC
Updated:
22 Mar 2007 at 15:17 UTC
Jump to comment: Most recent file
This is related to http://drupal.org/node/122801
I found some possible mistakes in date module > date.inc > date_sql() function. First there is no $db_type 'postgres' but 'pgsql'. Second for compatibility with PostgreSQL older than version 8 (7.4 is still in use) we need another approach into unix timestamp (in postgresql terminology 'epoch' or 'unixtime'). I now experimenting with code...
Some examples:
-- there is no function TIMESTAMP in postgresql but there is TO_TIMESTAMP(double precission) (for PostgreSQL 8 & >)
-- for get unix timestamp (epoch) from postgresql timestamp >
SELECT EXTRACT('epoch' FROM NOW()) AS unixtime;
-- for get postgresql timestamp from unix timestamp (epoch)
-- - with local timezone (actual time)
SELECT TIMESTAMPTZ 'epoch' + EXTRACT('epoch' FROM NOW()) * INTERVAL '1 second';
-- where is EXTRACT('epoch' FROM NOW()) actual unix timestamp (or column with unix timestamp)
-- - without local timezone (timezone 0)
SELECT TIMESTAMP 'epoch' + EXTRACT('epoch' FROM NOW()) * INTERVAL '1 second';
-- where is EXTRACT('epoch' FROM NOW()) actual unix timestamp (or column with unix timestamp)
I have tried this queries in PostgreSQL version 7.4.15 and 8.2.1 and it's working.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | date.inc__0.patch | 968 bytes | havran |
| #2 | date.inc_.patch | 3.02 KB | havran |
Comments
Comment #1
havran commentedFor converting unix timestamp to postgresql timezone is much simpler way which work both on PostgreSQL 7.4 and 8. For example:
Comment #2
havran commentedHere is first, partialy working patch for this issue.
Comment #3
karens commentedI knew there were probably problems in the Postgres code. I created it by looking at postgres documentation and digging around in postgres forums but had no way to test it. I'm glad to get some help on this and will gladly commit any fixes needed. The 'postgres' instead of 'pgsql' mistake was a dumb mistake on my part. I probably made it in one place then just copied it everywhere instead of going back to the source. I may have this mistake elsewhere, so I'll have to look around my other code.
The patch looks good to me. Let me know when you're ready for me to commit something.
Comment #4
havran commentedFor me work patch (for year) ok. But because here http://drupal.org/node/125509 is some bad dates in query, i get still some error PostgreSQL.
I think here is one more thing: in date.inc > function date_server_zone_adj() im not sure for this lines:
PostgreSQL have no TIMEZONE function. This
return 'The time zone offset from UTC, measured in seconds. Positive values correspond to time zones east of UTC, negative values to zones west of UTC.' - maybe this useful for date_server_zone_adj() (if i understood funcionality this function :)).
Comment #5
karens commentedWhat's the difference between $field::ABSTIME::INT4 and $field::ABSTIME? Something I read somewhere seemed to indicate that 'INT4' was important. I can believe I got the TIMESTAMP part wrong since I deduced that rather than finding something specific that used it.
Comment #6
karens commentedYes, that's what I was trying to get, I'll make that change.
Comment #7
karens commentedThere are going to be some related adjustments, like the need fix the SQL in the issue you point to, but I'm going ahead and committing this much of the code since it almost certainly is better than what was there.
Still outstanding is the question about whether or not ::INT4 belongs in the conversion from unixtime.
Comment #8
havran commentedI think node fields with dates is always int type (unix timestamp) - 0::ABSTIME::INT4 convert from int through postgre timestamp into int. I think you need postgre timestamp in this step.
Comment #9
karens commentedOK, sounds like we do not want INT4 in there, so I just committed a fix for that. I think that is all the fixes for the basic postgres sql handling, the other issue is a Calendar module issue so I am going to mark this fixed. If we missed anything you can reopen.
Comment #10
havran commentedI have two small PostgreSQL related fixes for DOW (day of week) and DOY (day of year) cases in date.inc > in date_sql() function... Patch attached.
Now i get correct year view http://www.fem.uniag.sk/havran/testcalendar/2007, month view (like januar) http://www.fem.uniag.sk/havran/testcalendar/2007/1, day view http://www.fem.uniag.sk/havran/testcalendar/2007/02/27.
But still is problem with februar http://www.fem.uniag.sk/havran/testcalendar/2007/1 and i have problem with showing correct weeks - like this (week 9 in februar) http://www.fem.uniag.sk/havran/testcalendar/2007/W09.
How can i help with this?
Comment #11
havran commentedAnd i have latest copy for calendar 5.x.1.x and date 5.x.1.x - i get it (through cvs up) 5 minuts ago.
Comment #12
karens commentedI committed the patch, thanks!
Not sure what is the February problem, can't tell from your link.
The doubled up week is a separate issue that has come up before (I thought it was fixed). Please report that in a separate thread since it has nothing to do with postgres. I think it is related to using Monday as the first day of the week. See if it goes away if you set Sunday as the first day of the week in your site configuration.
I'm marking this fixed, meaning I think the postgres issues are fixed.
Comment #13
havran commented> The doubled up week is a separate issue that has come up before (I thought it was fixed). Please report that in a separate thread since it has nothing to do with postgres. I think it is related to using Monday as the first day of the week. See if it goes away if you set Sunday as the first day of the week in your site configuration.
You get it. I set first day into Sunday and now week show correct...
Comment #14
(not verified) commented