<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Does anyone have any advice or a good tutorial for working with timestamps, and user configurable timezones within Drupal 6?<div><br></div><div>I have analytics data being recorded, each event with a timestamp generated via time(), so it's a standard Unix timestamp.</div><div><br></div><div>Previously, I think I had the analytics being reported correctly for each user in their local timezone via:</div><div><br></div><div>$timeStr = format_date($action-&gt;timestamp, 'custom', $customTimeFormatStr, variable_get('date_default_timezone', 0));</div><div><br></div><div>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.</div><div><br></div><div>Given:&nbsp;</div><div>$start = '7 am';</div><div>$timecode = strtotime( $start );</div><div>$start = format_date( $timecode, 'custom',&nbsp;'h:i:s a, d M Y',&nbsp;variable_get('date_default_timezone', 0));</div><div>&nbsp;</div><div>I get $start is "11:00:00 pm, 10 Mar 2011' &lt;- wrong time, correct date</div><div><br></div><div>However, changing the format_date() call to be like this:</div><div><br><div>
<span class="Apple-style-span" style="font-family: Helvetica; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div><span class="Apple-style-span" style="font-family: Arial; font-size: medium; ">$start = format_date( $timecode, 'custom',&nbsp;'h:i:s a, d M Y', 0); &nbsp; &lt;- changed variable_get() to 0</span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: medium; "><br></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: medium; ">Gives me "07:00:00 am, 11 Mar 2011" &nbsp;&lt;- correct time, but one day in the future</span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: medium; "><br></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: medium; ">Leaving the timezone parameter off, letting it's default NULL value be used like this:</span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: medium; "><br></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: medium; ">$start = format_date( $timecode, 'custom',&nbsp;'h:i:s a, d M Y');</span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: medium; "><br></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: medium; ">Gives me "12:00:00 am, 11 Mar 2011" &nbsp;&lt;- wrong time plus one day in the future</span></div><div><font class="Apple-style-span" face="Arial"><span class="Apple-style-span" style="font-size: medium;"><br></span></font></div><div><font class="Apple-style-span" face="Arial"><span class="Apple-style-span" style="font-size: medium;">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.</span></font></div><div><font class="Apple-style-span" face="Arial"><span class="Apple-style-span" style="font-size: medium;"><br></span></font></div><div><font class="Apple-style-span" face="Arial"><span class="Apple-style-span" style="font-size: medium;">Perhaps my date time configuration for the site is incorrect? At&nbsp;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 &amp; west coast US, London, Israel, and India. So the timezone handling is important.&nbsp;</span></font></div><div><font class="Apple-style-span" face="Arial"><span class="Apple-style-span" style="font-size: medium;">&nbsp;<br class="Apple-interchange-newline"></span></font>Sincerely,</div><div>-Blake</div><div><a href="mailto:bsenftner@earthlink.net">bsenftner@earthlink.net</a></div><div><a href="http://www.BlakeSenftner.com">www.BlakeSenftner.com</a></div><div><a href="http://www.MissingUbercartManual.com">www.MissingUbercartManual.com</a></div></span></span></div></span>
</div>
<br></div></body></html>