Re: weird timestamp problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm not sure why you'd have that problem, but I definitely think you're 
over-engineering the code.  That could well be why you're having a problem.  
You can greatly simplify it like so:

$start_c = mktime(5, 0, 0, $month_t, $day_t, $year_t);
$end_c = mktime(21, 30, 0, $month_t, $day_t, $year_t);

for ($start_time = $start_c; $start_time <= $end_c; $start_time += 900) {
  $start = date("g:i A", $start_time);
  $end = date("g:i A", $start_time + 900);
  print "$start<br />$end";
}

There may be an edge-case at the end you need to deal with, as I've not tested 
the above, but as there's less code there's fewer places things can go wrong.  
That's generally a good way to do things. :-)

On Thursday 07 December 2006 18:55, Amanda Emily wrote:
> I am working on an app that has 15 minute blocks of time to schedule
> meeting room reservations and have ran into an rather odd problem. Any
> ideas as to what could be causing this
>
> I am expecting the block of code output this:
>
> ....
> 7:00PM
> 7:15PM
>
> 7:15PM
> 7:30PM
>
> 7:30PM
> 7:45PM
> ....etc
>
> from 5:00 AM local time (PST) to 9:30 PM, but instead starting at 7:45PM, I
> see this (time jumps from 8:00 to 8:01).
>
> 7:45 PM
> 8:00 PM
>
> 8:01 PM
> 8:16 PM
>
> 8:16 PM
> 8:31 PM
>
> 8:31 PM
> 8:46 PM
> ....etc
>
> What is odd is that the app works as intended if I use 30 minute blocks of
> 15 minute blocks
>
> Snippet of code is below
>
> // menu start time
> $start_c = mktime(5, 0, 0, $month_t, $day_t, $year_t);
> // menu end time
> $end_c = mktime(21, 30, 0, $month_t, $day_t, $year_t);
>
> while($start_c < $end_c)
> {
>     $time_start = $start_c;
>     $loop_s = $loop_s+900;
>     $time_end = $end_c;
>
>     $unix_e = $time_end-900;
>     $unix_s = date("U", $time_start);
>
>     $timeloop_e = date("g:i A", $time_end);
>     $timeloop_s = date("g:i A", $time_start);
>     print("<tr><td class=\"timeblock\" align=\"center\">". $timeloop_s
> ."<br />". $timeloop_e . "</td>\n");
>
> }

-- 
Larry Garfield			AIM: LOLG42
larry@xxxxxxxxxxxxxxxx		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux