Jump to content


Photo

serious date time problem

date time

  • Please log in to reply
1 reply to this topic

#1 sniperscope

sniperscope

    Advanced Member

  • Members
  • PipPipPip
  • 283 posts
  • LocationOsaka - Japan

Posted 31 January 2013 - 09:25 PM

Hello
I have some serious date and time problem and i am working on it for 3 days without any hope.

On my current job day change at 07:00 and i cannot calculate to see if person working or not if his job end after 00:00

My current code work fine if current time until 07:00am but fail after it.
// Find end hour
$working_hour = explode("~", "10:00~01:30");
// Explode it to hour and minute
$ending = explode(":", $working_hour[1]);
$mid = ($working_hour[1] > "07:00" && $working_hour[1] < "23:59") ? 1 : 0;
$end_hour = mktime($ending[0], $ending[1], 0, date("n"), date("d") - $mid, date("Y"));
$current  = mktime(date("H"), date("i"), 0, date("n"), date("d"), date("Y"));
// Return result
if($end_hour < $current)
return "-";
else if($row['left_min'] > 0)
return "You have " .$row['left_min'] ." minutes left";
else
return "you are done";

However; yesterday i wrote some code which works perfect for single count but fail in loop.
Here it is;
$array_for_hour = array();
$working_hour = explode("~", "10:00~01:30");
// if job end after midnight
if($working_hour[1] > "23:59" || $working_hour[1] > "00:00")
{
$start_hour = strtotime($working_hour[0]);
$end_hour = strtotime("23:59");
// Add into array every 30 minutes
for($i = $start_hour; $i <= $end_hour; $i += 1800)
{
  $array_for_hour = $i;
}

// Add another 30 minutes to comlete to 00:00
array_push($array_for_hour, $i);


$midnight_start = strtotime("00:30");
$midnight_end = strtotime($working_hour[1]);
// Add hours into array from midnight to actual end hour
for($i = $midnight_start; $i <= $midnight_end; $i += 1800)
{
  $array_for_hour = $i;
}
}
else
{
$start_hour = strtotime($working_hour[0]);
$end_hour = strtotime($this->bitis_saat);

if($end_hour == "00:00")
  $end_hour = "23:59";

for($i = $start_hour; $i <= $end_hour; $i += 1800)
{
  $this->arr[] = $i;
}

if($end_hour == "00:00")
  array_push($array_for_hour, $i);
}

Thanks for any help and advise.

Regards

#2 sniperscope

sniperscope

    Advanced Member

  • Members
  • PipPipPip
  • 283 posts
  • LocationOsaka - Japan

Posted 01 February 2013 - 01:34 AM

problem solved.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com