lundi 26 mars 2018

Create H:i value in Carbon from gmdate()

Found an issue in a Laravel app with the UK clocks going forward. Everywhere in the app we use Carbon and have Europe/London set as the timezone but found one location that uses gmdate().

The method loops through a range and creates an array of available timeslots in the Hours:Minutes format:

foreach ( range( $lower, $upper, $step ) as $increment ) {
    $increment = gmdate( 'H:i', $increment );
    list( $hour, $minutes ) = explode( ':', $increment );
    $times[] = Carbon::createFromFormat('YmdHi', $day->format('Y') . $day->format('m') . $day->format('d') . $hour . $minutes);
}

I can't quite figure out how gmdate is creating that value from the increments which look along the lines of:

46800  
48600  
50400  
52200  
54000  
55800  
59400 

Is it possible to do the same as the gmdate() method but with Carbon instead?

Thanks!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2DUT3Z5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire