Scheduler should persist timestamps in UTC
skiminki - April 28, 2008 - 10:30
| Project: | Scheduler |
| Version: | 5.x-1.13 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Scheduler saves timestamps as seconds after 1970-01-01 00:00:00 UTC plus timezone. So, if you want the real seconds since 1970-01-01 00:00:00 UTC, you need to subtract seconds by timezone from it. There are few drawbacks in this:
- Breaks consistency. The common method to persist localized time is to save the timestamp in UTC and the timezone information. This also results in extra shifting/deshifting here and there. See, e.g.,
scheduler_cron(),scheduler_nodeapi()/submit. Unfortunately, the shifting is not there in all places, e.g.,scheduler_nodeapi()/load - Breaks views support. Without further workaround code, scheduler fields display wrong times (shifted by timezone) and scheduler filters do not work as supposed (shifted by timezone also). See also #197114: views filter and argument integration.
So, let's fix this in 5.x-1.14.

#1
I am going give it a hit if you don't want to do it yourself.
#2
Please, be my guest ;)
BTW, I'm going to release 5.13 today if no last-minute blockers show up. This means we should have a clean table for this.
#3
Subscribing.
#4
subscribing to thread.
So does this mean that the "unpublish" time still doesn't work and won't until 5.x-1.14? My "schedule to publish" date now works, but "unpublish" reverts to 1969.
I was going to edit the data in the mysql table, but I don't understand the format, e.g.,
publish_on: 1209821588
unpublish_on: -28800
timezone: -28800
#5
Unpublish should work in 5.x-1.13. At least, it works for me. If you think it's still broken in 5.x-1.13, please file an issue with steps to replicate.
#6
Hmmmm...I don't know what to think now. It works on my test server, but not production. I'll won't file a bug report since it looks like it's my system. I've attached a file that includes the steps I'm taking. Let me know if you prefer this as a bug report. More importantly, do you have suggestions for fixing????
Thanks,
Stinky
#7
Ok, I confirm that this is a real issue, although not exactly related with this. The new issue is here: #255010: Publish and unpublish fields are not validated
#8
The patch is rather large, because I touched a lot of code.
The publish_on and unpublish_on times are converted from the users timezone to utc prior to saving to the scheduler table. Since the users timezone is used I diked the timezone selection. We might even consider removing the timezone column from the scheduler table. I still don't understand, why this was implemented this way. The whole time management is now pretty straightforward. You can even use format_date() now, since you don't need to fake around the timezone shift.
Please test the patch as soon as possible. I am eager to commit, since this patch makes any upcoming features easier to implement.
#9
Tested and reviewed the patch above and it seems solid to me. In addition to simplifying the code, it fixes views support as a side effect as expected. I tested it mainly on MySQL, but made some runs on PostgreSQL too.
I made two changes to the patch:
If someone confirms that the db update process works, I think this patch is ready for commit.
#10
Update works as expected.
Committed scheduler-module-252116-9a.patch:
http://drupal.org/cvs?commit=116285
#11
Here's what happens when I apply the patch:
[root@library scheduler]# patch -b < scheduler-module-252116-9a.patch
patching file scheduler.install
patching file scheduler.module
Hunk #1 succeeded at 1 with fuzz 2.
Hunk #2 succeeded at 80 (offset -3 lines).
Hunk #4 FAILED at 112.
Hunk #5 succeeded at 151 (offset -53 lines).
Hunk #6 FAILED at 168.
Hunk #8 succeeded at 201 (offset -53 lines).
Hunk #10 succeeded at 249 (offset -53 lines).
2 out of 10 hunks FAILED -- saving rejects to file scheduler.module.rej
Should I just overwrite my directory with the files in http://drupal.org/cvs?commit=116285
It looks like the patch worked, when I update my module, I get:
Update #3
* UPDATE {scheduler} SET publish_on=publish_on-timezone WHERE publish_on<>0
* UPDATE {scheduler} SET unpublish_on=unpublish_on-timezone WHERE unpublish_on<>0
* ALTER TABLE {scheduler} DROP COLUMN timezone
But, here's what I get when I try to schedule something:
user warning: Unknown column 'timezone' in 'field list' query: INSERT INTO scheduler (nid, publish_on, unpublish_on, timezone) VALUES (632, 0, 1211842800, -28800) in /usr/local/apache2/htdocs/drupal-5.6/includes/database.mysql.inc on line 172.
#12
The patch needs to be applied to file revision 1.46.4.30. I guess you applied it to an earlier version like 1.46.4.29, which is the revision that corresponds to release 5.x-1.13.
You can overwrite your directory with the files from the commit, check out the current cvs version from branch DRUPAL-5 or wait for release 5.x-1.14 which will be ready as soon as #254212: Use different date format is fixed.
#13
Automatically closed -- issue fixed for two weeks with no activity.