This is a discussion on mktime()'s is_dst deprecated, but needed? within the PHP General forums, part of the PHP Programming Forums category; Hi all, (first time I send an email here, so please be forgiving if something doesn't follow expected rules.) ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi all,
(first time I send an email here, so please be forgiving if something doesn't follow expected rules.) My web application allows users to enter time stamps (date and time) given as local times. The time stamp is to be stored as UTC into the data base. Since we have summer and winter times (dst) there's an hour in the autumn which exists twice in local time (it's 2:00 - 3:00 at the last sunday in october here). Only the user knows which of these two hour is intended to be stored into the data base, no program ever can decide that by itself. Thus, the user has to add a character to the supplied time stamp. E.g. "<last sunday in october>, 02:30 A" is summer time (e.g. GMT +02:00), "<last sunday in october>, 02:30 B" is winter time (e.g. GMT +01:00). My php function used the "is_dst" parameter of mktime() responding to the user given "A" or "B". How's that to solve in the future if "is_dst" doesn't exist any more? (For now, it still works but gives a log line everytime the function is called - E_STRICT is set). Thanks for your help, Zora |
|
|||
|
Zora wrote: > Hi all, > > (first time I send an email here, so please be forgiving if something > doesn't follow expected rules.) > > My web application allows users to enter time stamps (date and time) > given as local times. The time stamp is to be stored as UTC into the > data base. > > Since we have summer and winter times (dst) there's an hour in the > autumn which exists twice in local time (it's 2:00 - 3:00 at the last > sunday in october here). Only the user knows which of these two hour is > intended to be stored into the data base, no program ever can decide > that by itself. Thus, the user has to add a character to the supplied > time stamp. > > E.g. > "<last sunday in october>, 02:30 A" is summer time (e.g. GMT +02:00), > "<last sunday in october>, 02:30 B" is winter time (e.g. GMT +01:00). > > My php function used the "is_dst" parameter of mktime() responding to > the user given "A" or "B". > > How's that to solve in the future if "is_dst" doesn't exist any more? > (For now, it still works but gives a log line everytime the function is > called - E_STRICT is set). > > Thanks for your help, > > Zora > > --------------010002030701000104070607-- Since you're getting that error I'll assume you're using PHP 5.1 or higher. UTC has no concept of DST, so what you really want to be using are strtotime() and date_default_timezone_set(). Here's the idea: $someString = '10/16/2006 5:37 pm'; //this is a string date_default_timezone_set('American/New_York'); //this is the user's timezone. It will determine how the string is turned into UTC $timestamp = strtotime($someString); //$timestamp now has UTC equivalent of 10/16/2006 5:37 pm in New York echo date('Y/m/d H:i:s', $timestamp); //prints out the nicely formatted version of that timestamp, as if you were in New York date_default_timezone_set('American/Los_Angeles'); echo date('Y/m/d H:i:s', $timestamp); //prints out the nicely formatted version of that timestamp, as if you were in LA -- takes care of the conversion and everything So, setting the timezone then using strtotime() and date() takes care of all the DST/non-DST stuff, converting between timezones, etc. |
|
|||
|
On Sun, 15 Oct 2006 13:22:02 +0200, Zora wrote:
> Hi all, > > (first time I send an email here, so please be forgiving if something > doesn't follow expected rules.) > > My web application allows users to enter time stamps (date and time) > given as local times. The time stamp is to be stored as UTC into the > data base. > > Since we have summer and winter times (dst) there's an hour in the > autumn which exists twice in local time (it's 2:00 - 3:00 at the last > sunday in october here). Only the user knows which of these two hour is > intended to be stored into the data base, no program ever can decide > that by itself. Thus, the user has to add a character to the supplied > time stamp. > > E.g. > "<last sunday in october>, 02:30 A" is summer time (e.g. GMT +02:00), > "<last sunday in october>, 02:30 B" is winter time (e.g. GMT +01:00). > > My php function used the "is_dst" parameter of mktime() responding to > the user given "A" or "B". > > How's that to solve in the future if "is_dst" doesn't exist any more? > (For now, it still works but gives a log line everytime the function is > called - E_STRICT is set). > > Thanks for your help, > > Zora Hi Zora, How is the data stored in the database? By the timestamp of your local time? In that case, you could just increment the timestamp by one hour if someone sets summertime. You can also feed the mktime the incremented hour, cause it will calculate the time correctly even with values that are out of range (such as 25 hours, 75 minutes, etc). Hope this helps, Ivo |