Hi!
Problem:
Here is what I have seen:
When a coupon is saved with a given date, next time the coupon is edited and saved and edited and saved (without making any changes, just clicking edit and save), the valid until date is changing to the previous day, e.g. 4 March, 3 March, 2 March, etc.
I am sure that this problem does not occur on certain servers, in certain timezones, etc., otherwise it would have been noticed.
But it happens in my case, so it might happen for others as well.
Possible reason:
I suspect that the reason of the problem is:
- sometimes mktime() is used to handle the valid_until value
- sometimes format_date() is used to handle the valid_until value
Please note the difference between gmmktime() and mktime()
Please note that format_date() calls gmdate().
As a result of this 00:00 can easily become 23:00 of the previous day.
Solution:
Replace mktime() with gmmktime() in uc_coupon_add_form_submit(), and all other places.
When I replaced mktime() with gmmktime(), the date remained the same after repeated saving of the coupon code, so I suggest this change in the next release.
Thank you.
Comments
Comment #1
longwaveFix committed to HEAD, thanks for the report.
Comment #3
aether commentedReopening.
This is still problematic and is not resolved in my case. I suspect the issue lies with the fact that when format_date() is used to display date values in forms (and set defaults), a timezone offset is not being specified. Drupal is therefore applying the user timezone or site timezone as an offset to the stored value retrieved from the db. Couple this with the fact that h/m/s data is not being saved when valid from/until dates are submitted and the potential to be off by a day is still there. This could be remedied by explicitly setting the timezone offset in format_date() to 0 whenever dates are formatted without h/m/s granularity. As in:
I'd be happy to create a patch if this seems like the proper solution.
Comment #4
longwavePlease do create a patch; I am in the UK with timezone GMT or GMT+1 and hence find it difficult to test timezone-related issues, but http://api.drupal.org/api/function/format_date#comment-1318 suggests your solution is correct.
Comment #5
longwave#771268: Coupon Usage Report Dates confusing is likely related to this date formatting issue as well.
Comment #6
scarr commentedSubscribing
Comment #7
ptoly commentedsubscribe
Comment #8
gradynoonen commentedsubscribe
Comment #9
longwaveCommitted the suggestion from #3 to CVS, please reopen (again) if this is still a problem with coupons themselves. Reports are not yet fixed, not sure what the solution is here.