dimanche 24 janvier 2016

Using day and time to get dates for the rest of the year

I'm trying to build an online version of a roster as a side project. I'm using FullCalendar to help me display this and have this functioning well with dummy data.

For each staff member, I know the day that they work and the start/finish time.

I'm looking for a way to initially seed my database with dates and times this person will work so that I can pull these in to FullCalendar later on.

I've been using Carbon for my dates and using new Carbon('next Monday 18:00:00') has been working for me, however extending this past the next Monday would then require adding ->addDays(7).

Using that to generate dates for given days for the rest of the year seems messy and not very streamlined.

I stumbled across the use of CarbonInterval, which could be used like so CarbonInterval::week(). However, I'm not fluent with Carbon and not really sure how to implement it.

Currently, the data I have is like this for each staff member:

'staff_id' => 1,
'day' => 'Monday',
'start_time' => '18:00:00',
'finish_time' => '22:00:00',

I am looking for a way to use this to generate fields like this in a a different table for the rest of this year:

'staff_id' => 1,
'date' => '2015-1-25',
'start_time' => '18:00:00',
'finish_time' => '22:00:00',

How could I do this simply?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire