Page 1 of 1

Manipulating Times

Posted: Mon Aug 14, 2006 3:13 pm
by ibanez270dx
Hi,
I have run into a problem in a program I'm writing for my client... Heres the story:

I am developing a system that logs the downtime of aircraft due to many different reasons. One of them is maintenance. The maintenance work is based on a 24 hour day. Thus, the log is based on a 24 hour time scale where a user can log a downtime (ex: 05:00 to 14:30). However, the hours of operation for these aircraft is based on an 18 hour day (05:00 to 23:00). What I need to do is to be able to take a 24hr day maintenance log and convert it to an 18hr day to log the downtimes in operation.

Here is an example: Let's say that the aircraft is down for maintenance between the hours of 01:00 and 08:00. I need to convert this 24 hour scale to an 18 hour scale. In actuallity, I need to take the overlapping hours and store them in a variable. The hours of operation are 05:00 to 23:00, thus with the example of 01:00 to 08:00, I would count 05:00 to 08:00. How would I do that?

Its kinda confusing, I know, but any help is greatly appreciated!!!!

Thank you!
- Jeff

Posted: Mon Aug 14, 2006 3:37 pm
by feyd
Some rough code

Code: Select all

$timeDiff = $timeEnd - $timeStart;
$eighteenHours = 18 * 3600;
$days = floor($timeDiff / $eighteenHours);
$remainder = $timeDiff % $eighteenHours;

Posted: Mon Aug 14, 2006 3:44 pm
by ibanez270dx
Thanks for the code! Could you maybe explain it? I don't really know whats going on in it...

Posted: Mon Aug 14, 2006 3:48 pm
by feyd
$timeEnd and $timeStart are unix timestamps of when the work ended and started, respectively. $eighteenHours is, well eighteen hours (in seconds, the unit of measure in unix timestamps.) $days is the number of eighteen hour days the work took. $remainder is any remaining time into the $days + 1 day.

Posted: Mon Aug 14, 2006 5:11 pm
by ibanez270dx
this might sound stupid, but how do I go about converting my input (05:00) to a timestamp? I tried to use mktime($mytime) where $mytime = 05:00, but it just gives an output thats way off...

Thanks,
- Jeff

Posted: Mon Aug 14, 2006 5:22 pm
by MarK (CZ)

Code: Select all

mktime(5, 0, 0);
for today's 5am, check manual for more.