kylekatarnls / business-time

Carbon mixin to handle business days and opening hours
MIT License
297 stars 14 forks source link

How to run with the times stored in the database? #44

Closed JMultimidia closed 3 years ago

JMultimidia commented 3 years ago

I created the table with the start and end times of the two shifts and I would like to understand how I can put them in BusinessTime :: enable (Carbon :: class, [

2021-03-19_20-04

I already have the following function to get the schedules

foreach ($horarios as $horario) {

    switch ($horario['dia']) {      

            case "monday":
                $arr .= "
                'monday' => ['".$horario['hora_inicio_01']."-".$horario['hora_fim_01']."', '".$horario['hora_inicio_02']."-".$horario['hora_fim_02']."'],
                ";
                    break;
            case "tuesday":
                $arr .= "
                'tuesday' => ['".$horario['hora_inicio_01']."-".$horario['hora_fim_01']."', '".$horario['hora_inicio_02']."-".$horario['hora_fim_02']."'],
                ";
                    break;
            case "wednesday":
                $arr .= "
                'wednesday' => ['".$horario['hora_inicio_01']."-".$horario['hora_fim_01']."', '".$horario['hora_inicio_02']."-".$horario['hora_fim_02']."'],
                ";
                    break;
            case "thursday":
                $arr .= "
                'thursday' => ['".$horario['hora_inicio_01']."-".$horario['hora_fim_01']."', '".$horario['hora_inicio_02']."-".$horario['hora_fim_02']."'],
                ";
                    break;
            case "friday":
                $arr .= "
                'friday' => ['".$horario['hora_inicio_01']."-".$horario['hora_fim_01']."', '".$horario['hora_inicio_02']."-".$horario['hora_fim_02']."'],
                ";
                    break;
            case "saturday":
                $arr .= "
                'saturday' => ['".$horario['hora_inicio_01']."-".$horario['hora_fim_01']."', '".$horario['hora_inicio_02']."-".$horario['hora_fim_02']."'],
                ";
                    break;
            case "sunday":
                $arr .= "
                'sunday' => ['".$horario['hora_inicio_01']."-".$horario['hora_fim_01']."', '".$horario['hora_inicio_02']."-".$horario['hora_fim_02']."'],
                ";
                    break;          
    }       
}

$list .= $arr;
kylekatarnls commented 3 years ago

See https://github.com/spatie/opening-hours/issues/167