I'm getting my brain fried on this. Tried to figure out the results of 
you code. I think you're at the point where I really started to get 
worried. So I tried to put it into a more simple question:

Why doesn't gmmktime(15,1,0,11,1,2002) return the SAME number (= epoch 
timestamp) when executed in different timezones and/or in different DST 
settings.


Actually, I found another one just this weekend: I tought epoch time 
started at 00:00 on the 1.1.1970. Well, if I tried gmmktime(0,0,0,1,1,1970)   
last week (not DST) I ended up with undef. If I try it this week, it 
actually works. 


anyone? (please cc:)


greets,
   patrick./








DL Neil wrote:
> 
> Hi Patrick,
> [I have put this back on the list, because greater minds might come up
> with a better explanation!?]
> 
> There appears to be an issue with "gm" time functions. gmmktime() is
> supposed to take a GMT date and return a GMT UNIX TimeStamp (as per
> mktime() but with no DST parameter). Conversely date() and gmdate() take
> a UNIX TimeStamp and format a string representation of the date-time.
> 
> The question is how gmmktime() should perform when working with
> date-times on both sides of the summer time discontinuity.
> 
> Assuming your server is running in a timezone that will change to/from
> Summer Time over the coming weekend (others may be able to adjust
> dates/offsets to run 'backwards' to cover last weekend, where relevant),
> try running the following code; and explaining why the "gm" functions do
> not complement each other (see below (way on down) for Patrick's
> original observations):
> 
> <table border="0" cellpadding=5 width="100%">
>   <tr>
>     <td width="20%"></td>
>     <td width="20%">Time Key Value</td>
>     <td width="20%">Local</td>
>     <td width="20%">GMT</td>
>     <td width="20%">Comment</td>
>   </td>
>   <tr>
>   <tr>
>     <td colspan=5>
>     <hr>
>     </td>
>   </tr>
> 
> <?php
> $tsNow = time();
> $dtLoc = date(   "D d.m.Y H:i I", $tsNow );
> $dtGMT = gmdate( "D d.m.Y H:i I", $tsNow );
> echo "<tr>" .
>    "<td>Now TS<br>produces dates:</td>" .
>    "<td>$tsNow</td>" .
>    "<td><br>$dtLoc</td>" .
>    "<td><br>$dtGMT</td>" .
>      "<td>as expected</td>" .
>    "</tr>" ;
> 
> $ss   = date( "s", $tsNow );
> $hh   = substr($dtLoc, 15, 2);
> $mm   = substr($dtLoc, 18, 2);
> $DD   = substr($dtLoc,  4, 2);
> $MM   = substr($dtLoc,  7, 2);
> $YYYY = substr($dtLoc, 10, 4);
> $DST  = substr($dtLoc, 21, 1);
> $mkLoc   =   mktime( $hh, $mm, $ss, $MM, $DD, $YYYY, $DST );
> $gmmkLoc = gmmktime( $hh, $mm, $ss, $MM, $DD, $YYYY );
> $hh   = substr($dtGMT, 15, 2);
> $mm   = substr($dtGMT, 18, 2);
> $DD   = substr($dtGMT,  4, 2);
> $MM   = substr($dtGMT,  7, 2);
> $YYYY = substr($dtGMT, 10, 4);
> $DST  = substr($dtGMT, 21, 1);
> $mkGMT   =   mktime( $hh, $mm, $ss, $MM, $DD, $YYYY, $DST );
> $gmmkGMT = gmmktime( $hh, $mm, $ss, $MM, $DD, $YYYY );
> echo "<tr>" .
>    "<td colspan=2>Run above dates through mktime() to revert to TS</td>"
> .
>    "<td>$mkLoc</td>" .
>    "<td>$mkGMT</td>" .
>      "<td>both correct</td>" .
>    "</tr>" ;
> echo "<tr>" .
>    "<td colspan=2>Run above dates through gmmktime() to revert to
> TS</td>" .
>    "<td>$gmmkLoc<br></td>" .
>    "<td>$gmmkGMT</td>" .
>      "<td>both incorrect???</td>" .
>    "</tr>" ;
> 
> echo "<tr>" .
>    "<td colspan=2>Run above (incorrect) TS through date()</td>" .
> //$dtLoc = date(   "D d.m.Y H:i I", $tsNow );
> //$dtGMT = gmdate( "D d.m.Y H:i I", $tsNow );
>    "<td>" . date( "D d.m.Y H:i I", $gmmkLoc ) . "<br></td>" .
>    "<td>" . date( "D d.m.Y H:i I", $gmmkGMT ) . "</td>" .
>      "<td>continue incorrect</td>" .
>    "</tr>" ;
> 
> echo "<tr>" .
>    "<td colspan=2>Run above (incorrect) TS through gmdate()</td>" .
>    "<td>" . gmdate( "D d.m.Y H:i I", $gmmkLoc ) . "<br></td>" .
>    "<td>" . gmdate( "D d.m.Y H:i I", $gmmkGMT ) . "</td>" .
>      "<td>continue incorrect</td>" .
>    "</tr>" ;
> 
> echo "<tr><td colspan=5><hr></td></tr>" ;
> 
> $ts1wk = $tsNow + ( 7 * 24 * 60 * 60 );
> $dtLoc = date(   "D d.m.Y H:i I", $ts1wk );
> $dtGMT = gmdate( "D d.m.Y H:i I", $ts1wk );
> echo "<tr>" .
>    "<td>TS in one week's time<br>produces dates:</td>" .
>    "<td>$ts1wk</td>" .
>    "<td><br>$dtLoc</td>" .
>    "<td><br>$dtGMT</td>" .
>      "<td>local clock springs forwards</td>" .
>    "</tr>" ;
> 
> $ss   = date( "s", $ts1wk );
> $hh   = substr($dtLoc, 15, 2);
> $mm   = substr($dtLoc, 18, 2);
> $DD   = substr($dtLoc,  4, 2);
> $MM   = substr($dtLoc,  7, 2);
> $YYYY = substr($dtLoc, 10, 4);
> $DST  = substr($dtLoc, 21, 1);
> $mkLoc   =   mktime( $hh, $mm, $ss, $MM, $DD, $YYYY, $DST );
> $gmmkLoc = gmmktime( $hh, $mm, $ss, $MM, $DD, $YYYY );
> $hh   = substr($dtGMT, 15, 2);
> $mm   = substr($dtGMT, 18, 2);
> $DD   = substr($dtGMT,  4, 2);
> $MM   = substr($dtGMT,  7, 2);
> $YYYY = substr($dtGMT, 10, 4);
> $DST  = substr($dtGMT, 21, 1);
> $mkGMT   =   mktime( $hh, $mm, $ss, $MM, $DD, $YYYY, $DST );
> $gmmkGMT = gmmktime( $hh, $mm, $ss, $MM, $DD, $YYYY );
> echo "<tr>" .
>    "<td colspan=2>Run above dates through mktime() to revert to TS</td>"
> .
>    "<td>$mkLoc</td>" .
>    "<td>$mkGMT</td>" .
>      "<td>both correct - using dst!</td>" .
>    "</tr>" ;
> echo "<tr>" .
>    "<td colspan=2>Run above dates through gmmktime() to revert to
> TS</td>" .
>    "<td>$gmmkLoc<br></td>" .
>    "<td><br>$gmmkGMT</td>" .
>      "<td>local incorrect<br>- GMT correct</td>" .
>    "</tr>" ;
> 
> echo "<tr>" .
>    "<td colspan=2>Run above (correct) gmTS through date()</td>" .
>    "<td>" . date( "D d.m.Y H:i I", $gmmkGMT ) . "</td>" .
>    "<td></td>" .
>      "<td>continues correct</td>" .
>    "</tr>" ;
> 
> echo "<tr>" .
>    "<td colspan=2>Run above (correct) gmTS through gmdate()</td>" .
>    "<td></td>" .
>    "<td>" . gmdate( "D d.m.Y H:i I", $gmmkGMT ) . "</td>" .
>      "<td>continues correct</td>" .
>    "</tr>" ;
> 
> echo "<tr>" .
>    "<td colspan=2>Run above (incorrect) gmTS through date()</td>" .
>    "<td>" . date( "D d.m.Y H:i I", $gmmkLoc ) . "</td>" .
>    "<td></td>" .
>      "<td>continues incorrect</td>" .
>    "</tr>" ;
> 
> echo "<tr>" .
>    "<td colspan=2>Run above (incorrect) gmTS through gmdate()</td>" .
>    "<td></td>" .
>    "<td>" . gmdate( "D d.m.Y H:i I", $gmmkLoc ) . "</td>" .
>      "<td>continues incorrect</td>" .
>    "</tr>" ;
> 
> echo "<tr><td colspan=5><hr></td></tr>" ;
> 
> $tsLoc = mktime( );
> $tsGMT = gmmktime( );
> echo "<tr>" .
>    "<td>*mktime( NOW)</td>" .
>    "<td>" . date( 'D d.m.Y H:i I' ) . "</td>" .
>    "<td>$tsLoc</td>" .
>    "<td>$tsGMT</td>" .
>      "<td>think they should be same?<br>but GMT doesn't like it!</td>" .
>    "</tr>" ;
> 
> $tsLoc = mktime(   0, 0, 0, 3, 31, 2002 );
> $tsGMT = gmmktime( 0, 0, 0, 3, 31, 2002 );
> echo "<tr>" .
>    "<td>put change-over date into *mktime to get TSs</td>" .
>    "<td>Sun 31Mar2002 02:00</td>" .
>    "<td>$tsLoc</td>" .
>    "<td>$tsGMT</td>" .
>    "<td>again<br>not same!?</td>" .
>    "</tr>" ;
> 
> echo "<tr><td colspan=5><hr></td></tr>" ;
> 
> echo "<tr>" .
>    "<td colspan=2>Count from midnight over GMT/BST changeover:</td>" .
>    "</tr>" ;
> 
> echo "<tr>" .
>    "<td colspan=2>by putting LocalTS ($tsLoc) into *date</td>" .
>      "<td>Local time jumps...</td>" .
>      "<td>GMT continues...</td>" .
>    "</tr>" ;
> 
> for ( $iOffset = 0; $iOffset < 5; $iOffset ++ )
> {
>    $iHour = $iOffset * 3600;
> echo "<tr>" .
>    "<td>Midnight+$iOffset</td>" .
>    "<td></td>" .
>    "<td>" .   date( "D d.m.Y H:i I", $tsLoc + $iHour ) . "</td>" .
>    "<td>" . gmdate( "D d.m.Y H:i I", $tsLoc + $iHour ) . "</td>" .
>      "<td></td>" .
>    "</tr>" ;
> }
> 
> echo "<tr>" .
>    "<td colspan=2>by putting GMT TS ($tsGMT) into *date</td>" .
>    "<td></td>" .
>    "<td></td>" .
>      "<td>garbage?!</td>" .
>    "</tr>" ;
> 
> for ( $iOffset = 0; $iOffset < 5; $iOffset ++ )
> {
>    $iHour = $iOffset * 3600;
> echo "<tr>" .
>    "<td>Midnight+$iOffset</td>" .
>    "<td></td>" .
>    "<td>" .   date( "D d.m.Y H:i I", $tsGMT + $iHour ) . "</td>" .
>    "<td>" . gmdate( "D d.m.Y H:i I", $tsGMT + $iHour ) . "</td>" .
>      "<td></td>" .
>    "</tr>" ;
> }
> 
> echo "</table>" ;
> 
> ?>
> 
> Patrick: herewith specific answers to your most recent msg:-
> 
> Yes, as mentioned I am in GMT (London). However the tests run (over the
> next one week period) are valid because during this weekend we
> cross-over into BST (GMT+1) and try (vainly) to catch up with you.
> 
> Thus the tests below ARE valid and illustrate your very point, because
> the date-ranges span the summer time discontinuity. (so I don't need to
> run it on another box/change the server's TZ setting, I simply read the
> second half of the report)
> 
> It is not missing one day, but one hour!
> 
> Regards,
> =dn
> 
> > Fucko. I kicked this pony-style. Yes - typo!!!! Didn't know what hit
> me there.
> > Output is as you said. Gotta have been drunk or something... But
> anyaway,
> > that's not really the point.
> >
> > The point is, that in the count-days-version you're sort of missing a
> day:
> >
> > > 1017529200= gmmktim epoch - Sat 30.03.2002 23:00 0   <<<<<<
> > > 1017532800= mktim epoch - Sun 31.03.2002 00:00 0
> > >
> > > 1017619200= gmmktim epoch - Mon 01.04.2002 00:00 0   <<<<<<
> > > 1017615600= mktim epoch - Mon 01.04.2002 00:00 1
> >
> > Now, for some reason (and I REALLY got this checked for typos now) the
> > 'count second'-version ends up showing me 23:00 0 of the previous day
> > consistently. It IS consistent throughout DST changes. But it's one
> hour
> > off when created with mktime and printed with gmdate. And I can give
> you
> > the reason: Taken from your email-adress you're in TZ+/-0, right. And
> that's
> > the ONLY location where gmmktime(0,0,0,28,3,2002) actually gives you
> the
> > epoch stamp of that date. If I do it, my timezone gets subtracted and
> I
> > end up with the epoch stamp of 23.00 of the last day (my TZ beeing
> +1).
> >
> > ufff - hope I made my point clear. It's just that gmmktime is still
> > somehow localized. So for mew it would mean that I have to subtract
> > my TZ everytime I use gmmktime to get the correct epoch.
> >
> > Just try running the code on a box that's not in TZ 0 and you'll see
> > what I mean.
> >
> >
> > greets,
> >   patrick./
> >
> >
> >
> >
> > DL Neil wrote:
> > >
> > > Hi Patrick,
> > >
> > > > before spamming the group with this, let's see if we're talking
> about
> > > > the same here:
> > >
> > > It would not be "spam"! It is list business, and copying the list
> gives
> > > others the opportunity to answer before I do/offer other ideas - and
> > > others following the discussion the opportunity to learn...
> > >
> > > > I completely agree with your points, but if I execute the two
> lines
> > > you
> > > > propose from here (TZ+1, no DST):
> > > >
> > > > echo gmdate ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
> > > > echo gmdate ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
> > > > I'm getting:
> > > > Dec 31 1997 23:00:00
> > > > Dec 31 1997 23:00:00
> > > > ... so it's the same both times.
> > >
> > > Because of a typo?
> > >
> > > Note that the clock is taken from your server (not your client)
> > > location, and further note that the server administrator can set up
> any
> > > timezone (s)he pleases regardless of physical location. Also we
> depend
> > > upon the server's ToD clock being correctly set! If you're the
> server
> > > admin, then we're ok, if not questions may need to be asked!
> > >
> > > For your interest, I took your code (per your first msg) and ran it
> on
> > > my machine (set to GMT, changing to BST on Sunday morning).  I then
> > > extended it to illustrate the points - after the code, please find
> > > sample output:-
> > >
> > > print "count days:<br>\n";
> > > for($day=0; $day<7; $day++)
> > > {
> > >    $timgmt = gmmktime(0,0,0,3,28+$day,2002);
> > >  $timloc = mktime(0,0,0,3,28+$day,2002);
> > >  print $timgmt . "= gmmktim epoch - " . gmdate("D d.m.Y H:i
> I",$timgmt).
> > > "<br>\n";
> > >  print $timloc . "= mktim epoch - " . date("D d.m.Y H:i  I",$timloc)
> .
> > > "<br>\n";
> > >  print "<BR>\n";
> > > }
> > >
> > > print "<BR>\n";
> > > print "<BR>\n";
> > > print "count seconds:<br>\n";
> > > $baseepoch = $timloc = mktime(0,0,0,3,28,2002);
> > > for($day=0; $day<7; $day++)
> > > {
> > >    $epochnow = $baseepoch + (60 * 60 * 24 * $day);
> > >  print $epochnow . "= gmmktim epoch - " . gmdate("D d.m.Y H:i
> > > I",$epochnow) . "<br>\n";
> > >  print $epochnow . "= mktim epoch - " . date("D d.m.Y H:i
> I",$epochnow)
> > > . "<br>\n";
> > >  print "<BR>\n";
> > > }
> > >
> > > print "<BR>\n";
> > > print "<BR>\n";
> > > print "count hours over GMT/BST changeover:<br>\n";
> > > for( $timestamp = 1017532800; $timestamp < 1017547200; $timestamp =
> > > $timestamp + 3600 )
> > > {
> > >    print $timestamp . " = " .
> > >    date( "D d.m.Y H:i I", $timestamp ) . " = " .
> > >    gmdate( "D d.m.Y H:i I", $timestamp ) . "<br>\n";
> > > }
> > >
> > > print "<BR>\n";
> > > print "<BR>\n";
> > > print "count dates from midnight over GMT/BST changeover:<br>\n";
> > > for( $hour = 0; $hour < 4; $hour ++ )
> > > {
> > >    print $hour . " = " .
> > >    mktime(   $hour, 0, 0, 3, 31, 2002 ) . " = " .
> > >      gmmktime( $hour, 0, 0, 3, 31, 2002 ) . "<br>\n";
> > > }
> > >
> > > -----
> > >
> > > count days:
> > > 1017270000= gmmktim epoch - Wed 27.03.2002 23:00 0
> > > 1017273600= mktim epoch - Thu 28.03.2002 00:00 0
> > >
> > > 1017356400= gmmktim epoch - Thu 28.03.2002 23:00 0
> > > 1017360000= mktim epoch - Fri 29.03.2002 00:00 0
> > >
> > > 1017442800= gmmktim epoch - Fri 29.03.2002 23:00 0
> > > 1017446400= mktim epoch - Sat 30.03.2002 00:00 0
> > >
> > > 1017529200= gmmktim epoch - Sat 30.03.2002 23:00 0
> > > 1017532800= mktim epoch - Sun 31.03.2002 00:00 0
> > >
> > > 1017619200= gmmktim epoch - Mon 01.04.2002 00:00 0
> > > 1017615600= mktim epoch - Mon 01.04.2002 00:00 1
> > >
> > > 1017705600= gmmktim epoch - Tue 02.04.2002 00:00 0
> > > 1017702000= mktim epoch - Tue 02.04.2002 00:00 1
> > >
> > > 1017792000= gmmktim epoch - Wed 03.04.2002 00:00 0
> > > 1017788400= mktim epoch - Wed 03.04.2002 00:00 1
> > >
> > > count seconds:
> > > 1017273600= gmmktim epoch - Thu 28.03.2002 00:00 0
> > > 1017273600= mktim epoch - Thu 28.03.2002 00:00 0
> > >
> > > 1017360000= gmmktim epoch - Fri 29.03.2002 00:00 0
> > > 1017360000= mktim epoch - Fri 29.03.2002 00:00 0
> > >
> > > 1017446400= gmmktim epoch - Sat 30.03.2002 00:00 0
> > > 1017446400= mktim epoch - Sat 30.03.2002 00:00 0
> > >
> > > 1017532800= gmmktim epoch - Sun 31.03.2002 00:00 0
> > > 1017532800= mktim epoch - Sun 31.03.2002 00:00 0
> > >
> > > 1017619200= gmmktim epoch - Mon 01.04.2002 00:00 0
> > > 1017619200= mktim epoch - Mon 01.04.2002 01:00 1
> > >
> > > 1017705600= gmmktim epoch - Tue 02.04.2002 00:00 0
> > > 1017705600= mktim epoch - Tue 02.04.2002 01:00 1
> > >
> > > 1017792000= gmmktim epoch - Wed 03.04.2002 00:00 0
> > > 1017792000= mktim epoch - Wed 03.04.2002 01:00 1
> > >
> > > count hours over GMT/BST changeover:
> > > 1017532800 = Sun 31.03.2002 00:00 0 = Sun 31.03.2002 00:00 0
> > > 1017536400 = Sun 31.03.2002 01:00 0 = Sun 31.03.2002 01:00 0
> > > 1017540000 = Sun 31.03.2002 03:00 1 = Sun 31.03.2002 02:00 0
> > > 1017543600 = Sun 31.03.2002 04:00 1 = Sun 31.03.2002 03:00 0
> > >
> > > count dates from midnight over GMT/BST changeover:
> > > 0 = 1017532800 = 1017529200
> > > 1 = 1017536400 = 1017532800
> > > 2 = 1017536400 = 1017532800
> > > 3 = 1017540000 = 1017543600
> > >
> > > -----
> > >
> > > >From this you can clearly see the impact of the changing local
> clock/TZ
> > > as Britain clicks over into Summer Time. Note how adding 3600
> minutes to
> > > the timestamp results in a jump of two hours in local time over the
> > > 'discontinuity'.
> > >
> > > This also illustrates how a timestamp (integer value) is measured in
> GMT
> > > (see my first response for definition) - thus the GMT progression is
> > > uniform, but the local progression shows a discontinuity.
> > >
> > > > My observation is, that gmmktime(0,0,0,1,1,2002) will in fact not
> > > generate
> > > > the UNIX-epoch timestamp for the 1.1.2002 0:0 GMT time, but it
> will
> > > take
> > > > your time-offset in count and generate the epoch stamp for
> 1.1.2002
> > > > 0:0+TZoffset',
> > > > leaving you with the 'true' stamp of 31.12.2002 23:00.
> > > >
> > > > Now what I'm looking for is a function (I expected gmmktime to do
> so)
> > > that
> > > > will actually generate the 'true' unix epoch for the date I seek.
> So
> > > that
> > > >
> > > > echo gmdate("M d Y H:i:s", "puremktime"(0,0,0,1,1,2002)
> > > >
> > > > WOULD actually return 1.1.2002 0:0 and NOT 31.12.2001 23:00 for
> > > central
> > > > europe.
> > > >
> > > >
> > > > what do you think?
> > >
> > > I think the code/output also illustrates that you are correct in
> what
> > > you say, but I'm feeling a bit woolly-headed so I'm wondering if
> I've
> > > missed something. Are we saying that the date arguments entered into
> > > gmmktime() are considered to be local time, and the answer GMT - the
> > > former subject to TZ/BST considerations but the latter not? Whereas
> you
> > > want to enter a GMT date-time into gmmktime() and get GMT data out?
> > >
> > > For sure we need to understand the PHP (UNIX) definitions in order
> to
> > > make best use of the facilities/functions! In other words I'm
> wondering
> > > if we are (making incorrect assumptions) pushing the 'wrong data'
> into
> > > the function, rather than the function giving us the 'wrong answer'
> > > back!? I've checked my reference book and been unsatisfied with the
> > > bland definitions. Can I leave you to check the online annotated
> manual?
> > >
> > > Regards,
> > > =dn
> > >
> > > > greets,
> > > >   patrick./
> > > >
> > > >
> > > >
> > > >
> > > > Dl Neil wrote:
> > > > >
> > > > > BTW for all who are following this, Patrick has cleverly
> illustrated
> > > > > that most of the northern hemisphere locations where summer time
> is
> > > > > observed will 'spring forward' this weekend. Most of the
> southern
> > > > > hemisphere locations that were in summer time did their 'fall
> back'
> > > last
> > > > > weekend!
> > > > > NB the two uses of the word "most"!
> > > > >
> > > > > Hi Patrick,
> > > > >
> > > > > References from the manual:
> > > > > -----
> > > > > gmmktime -- Get UNIX timestamp for a GMT date
> > > > > -----
> > > > > gmdate -- Format a GMT/CUT date/time
> > > > >
> > > > > Identical to the date() function except that the time returned
> is
> > > > > Greenwich Mean Time (GMT). For example, when run in Finland (GMT
> > > +0200),
> > > > > the first line below prints "Jan 01 1998 00:00:00", while the
> second
> > > > > prints "Dec 31 1997 22:00:00".
> > > > > echo date ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
> > > > > echo gmdate ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
> > > > > -----
> > > > >
> > > > > The definition of the Unix Epoch is itself in GMT (and adjusted
> from
> > > > > there to local time using the +/-TZ difference): "the current
> time
> > > > > measured in the number of seconds since the Unix Epoch (January
> 1
> > > 1970
> > > > > 00:00:00 GMT)".
> > > > >
> > > > > When playing around with UNIX epoch seconds it is important to
> keep
> > > them
> > > > > time-zone separated. So try working your test backwards and
> putting
> > > in a
> > > > > data/time and then asking for the GMT and the local timestamp
> > > values.
> > > > > They will also be separated by the one hour/two hours.
> > > > >
> > > > > Question answered, or in my haste to get to my dinner...?
> > > > > Regards,
> > > > > =dn
> > > > >
> > > > > > i'm storing events in a mysql-db, using epoch timestamps to
> > > pinpoint
> > > > > the
> > > > > > exact date/time for an event.
> > > > > >
> > > > > > so far, I have been using localtime, being aware that there
> are
> > > > > > inconsistencies
> > > > > > in the number of epoch-seconds, when DST flips on and off.
> > > > > nevertheless, that
> > > > > > works fine as long as you stick to mktime() and date() for all
> the
> > > > > date-math
> > > > > > as in mktime(0,0,0,$month,$day+$offset,$year)
> > > > > >
> > > > > > but as soon as you leave php and have to do some calculation
> in
> > > > > javascript,
> > > > > > you will encounter functions that behave differently on the pc
> and
> > > mac
> > > > > > platforms. so you have to revert back to the 'add
> 86400-seconds'
> > > to
> > > > > calculate
> > > > > > the next day.
> > > > > >
> > > > > > so I thought it would be nice to have all the timestamps as
> > > linear,
> > > > > > non-dst-epoch-seconds (UTC) and I went into the gmmktime() and
> > > > > gmdate()
> > > > > > functions, assuming they would do the math in a linear
> > > second-based
> > > > > timespace
> > > > > > (in GMT, without DST). That seems to be the case for the
> output of
> > > > > 'gmdate',
> > > > > > that remains correct, if you count up seconds across the DST
> > > boundary
> > > > > (see
> > > > > > second example).
> > > > > >
> > > > > > but it seems that there is no way to calculate the gmt-epoch
> for a
> > > > > given
> > > > > > date using gmmktime without having to add/subtract the TZ
> > > manually.
> > > > > gmmktime
> > > > > > will always take your local DST-settings into calculation and
> upon
> > > > > conversion
> > > > > > back with gmdate, you will be off by the number of hours of
> your
> > > > > timezone.
> > > > > > I thought gmmktime() would handle this as if the computer
> would be
> > > in
> > > > > > Greenwich
> > > > > > (TZ=0), which would then leave us with the two functions
> > > > > encoding/decoding
> > > > > > consistently.
> > > > > >
> > > > > > anyone having solved this properly?
> > > > > >
> > > > > > -------------------------------------
> > > > > > print "count days:<br>\n";
> > > > > > for($day=0; $day<7; $day++){
> > > > > > $timgmt = gmmktime(0,0,0,3,28+$day,2002);
> > > > > > $timloc = mktime(0,0,0,3,28+$day,2002);
> > > > > > print $timgmt . "= gmmktim epoch - " . gmdate("D d.m.Y H:i
> > > I",$timgmt)
> > > > > .
> > > > > > "<br>\n";
> > > > > > print $timloc . "= mktim epoch - " . date("D d.m.Y H:i
> > > I",$timloc) .
> > > > > > "<br>\n";
> > > > > > print "<BR>\n";
> > > > > > }
> > > > > >
> > > > > > ----
> > > > > > count days:
> > > > > > 1017270000= gmmktim epoch - Wed 27.03.2002 23:00 0
> > > > > > 1017270000= mktim epoch - Thu 28.03.2002 00:00 0
> > > > > >
> > > > > > 1017356400= gmmktim epoch - Thu 28.03.2002 23:00 0
> > > > > > 1017356400= mktim epoch - Fri 29.03.2002 00:00 0
> > > > > >
> > > > > > 1017442800= gmmktim epoch - Fri 29.03.2002 23:00 0
> > > > > > 1017442800= mktim epoch - Sat 30.03.2002 00:00 0
> > > > > >
> > > > > > 1017529200= gmmktim epoch - Sat 30.03.2002 23:00 0
> > > > > > 1017529200= mktim epoch - Sun 31.03.2002 00:00 0
> > > > > >                                                     <<<dst on
> > > > > > 1017619200= gmmktim epoch - Mon 01.04.2002 00:00 0  <<< off by
> one
> > > > > hour due to
> > > > > > DST
> > > > > > 1017612000= mktim epoch - Mon 01.04.2002 00:00 1
> > > > > >
> > > > > > 1017705600= gmmktim epoch - Tue 02.04.2002 00:00 0
> > > > > > 1017698400= mktim epoch - Tue 02.04.2002 00:00 1
> > > > > >
> > > > > > 1017792000= gmmktim epoch - Wed 03.04.2002 00:00 0
> > > > > > 1017784800= mktim epoch - Wed 03.04.2002 00:00 1
> > > > > >
> > > > > >
> > > > > > -------------------------------------
> > > > > > print "count seconds:<br>\n";
> > > > > > $baseepoch = $timloc = mktime(0,0,0,3,28,2002);
> > > > > > for($day=0; $day<7; $day++){
> > > > > > $epochnow = $baseepoch + (60 * 60 * 24 * $day);
> > > > > > print $epochnow . "= gmmktim epoch - " . gmdate("D d.m.Y H:i
> > > > > I",$epochnow) .
> > > > > > "<br>\n";
> > > > > > print $epochnow . "= mktim epoch - " . date("D d.m.Y H:i
> > > > > I",$epochnow) .
> > > > > > "<br>\n";
> > > > > > print "<BR>\n";
> > > > > > }
> > > > > > ----
> > > > > > count seconds:
> > > > > > 1017270000= gmmktim epoch - Wed 27.03.2002 23:00 0  <<<
> > > consistent,
> > > > > but off by
> > > > > > -1 (your TZ)
> > > > > > 1017270000= mktim epoch - Thu 28.03.2002 00:00 0
> > > > > >
> > > > > > 1017356400= gmmktim epoch - Thu 28.03.2002 23:00 0
> > > > > > 1017356400= mktim epoch - Fri 29.03.2002 00:00 0
> > > > > >
> > > > > > 1017442800= gmmktim epoch - Fri 29.03.2002 23:00 0
> > > > > > 1017442800= mktim epoch - Sat 30.03.2002 00:00 0
> > > > > >
> > > > > > 1017529200= gmmktim epoch - Sat 30.03.2002 23:00 0
> > > > > > 1017529200= mktim epoch - Sun 31.03.2002 00:00 0
> > > > > >
> > > > > > 1017615600= gmmktim epoch - Sun 31.03.2002 23:00 0
> > > > > > 1017615600= mktim epoch - Mon 01.04.2002 01:00 1
> > > > > >
> > > > > > 1017702000= gmmktim epoch - Mon 01.04.2002 23:00 0
> > > > > > 1017702000= mktim epoch - Tue 02.04.2002 01:00 1
> > > > > >
> > > > > > 1017788400= gmmktim epoch - Tue 02.04.2002 23:00 0
> > > > > > 1017788400= mktim epoch - Wed 03.04.2002 01:00 1
> > > > > >
> > > > > > --
> >

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to