Does anyone have any advice or a good tutorial for working with timestamps, and
user configurable timezones within Drupal 6?
I have analytics data being recorded, each event with a timestamp generated via
time(), so it's a standard Unix timestamp.
Previously, I think I had the analytics being reported correctly for each user
in their local timezone via:
$timeStr = format_date($action->timestamp, 'custom', $customTimeFormatStr,
variable_get('date_default_timezone', 0));
But when I added analytics exporting, with the user being able to specify a
start and end date/time string, I began to suspect that the above timezone
handling is incorrect.
Given:
$start = '7 am';
$timecode = strtotime( $start );
$start = format_date( $timecode, 'custom', 'h:i:s a, d M Y',
variable_get('date_default_timezone', 0));
I get $start is "11:00:00 pm, 10 Mar 2011' <- wrong time, correct date
However, changing the format_date() call to be like this:
$start = format_date( $timecode, 'custom', 'h:i:s a, d M Y', 0); <- changed
variable_get() to 0
Gives me "07:00:00 am, 11 Mar 2011" <- correct time, but one day in the future
Leaving the timezone parameter off, letting it's default NULL value be used
like this:
$start = format_date( $timecode, 'custom', 'h:i:s a, d M Y');
Gives me "12:00:00 am, 11 Mar 2011" <- wrong time plus one day in the future
I guess I could just use the second form, with the timezone parameter set to
zero, and recommend that users include the date, but it sure is convenient to
just say "12:00:00 am" and "12:59:59 pm" to capture the analytics thus far for
the day.
Perhaps my date time configuration for the site is incorrect? At
admin/settings/date-time I have the time zone set correctly, and user
configurable timezones are enabled. BTW, the users of the site are
international, with people on both east & west coast US, London, Israel, and
India. So the timezone handling is important.
Sincerely,
-Blake
[email protected]
www.BlakeSenftner.com
www.MissingUbercartManual.com