#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2006
    Posts
    21
    Rep Power
    0

    Adding time to time of day


    Okay slightly different to my earlier question. I have a time of day and day of week. This does not represent a calendar day.

    Say Tuesday 22:45.

    I want to add 3 Hours 14 to it.

    Result will be Wednesday 02:00.

    I'm at this point of a function.

    PHP Code:
            $DOW 'Tu';
            
    $DepTime '22:45PM';
            
    $FlightTime '2.45';
        
    $Dep strtotime($DOW $DepTime);
        
    $Arrival strtotime($FlightTime$Dep);
        return 
    $Arrival
  2. #2
  3. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,968
    Rep Power
    9647
    What about daylight saving time? What if it started during those three hours? What if Wednesday 2am isn't a real time because the clock advanced at that moment and it went from 1:59 to 3:00?
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,971
    Rep Power
    4576
    You'll probably want to play around with the DateTime class for this, although I don't know how it handles daylight savings...

    PHP: DateTime - Manual
    -- Cigars, whiskey and wild, wild women. --
  6. #4
  7. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,968
    Rep Power
    9647
    It'll handle DST correctly when using the right dates. Well... probably... I believe there are still a couple bugs out there about DST behavior, but 99% of the time it does what it should.
    Mostly my question was aimed at what "correct" is expected to be.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2016
    Location
    Cheshire, UK
    Posts
    90
    Rep Power
    73
    I notice you are using flight times, where arrivals and departure times are usually given in local time. So, just to add further complication for you, a 2 hour flight from London to Nice might be
    Code:
    Outbound : Dep 10:00     Arr: 13:00
    Inbound  : Dep 14:00     Arr: 15:00

IMN logo majestic logo threadwatch logo seochat tools logo