DummyStupidFace
DummyStupidFace

Reputation: 1

How do I create a list of time ranges?

I'm trying to set up a way to be able to step backward and forward through sets of time ranges.

I'm creating a simple display for my work's production floor. Every time a user scans a barcode a serial number is generated in our ERP system. In order to track progress throughout the day they want a display that will show how many serials (and because of that, how many widgets) were processed that day. The display would also show the previous shift's widgets. So at any given time you look at the display you'll see the current shift's progress, and then the previous shift's totals.

We run 3 normal shifts throughout the week. 1st shift 6am to 2pm, 2nd shift 2pm to 10pm, 3rd shift 10pm to 6am. Then on both weekend days we have a weekend shift that runs 6am to 6pm.

I currently have a spaghetti noodle mess of if/else statements that make this actually work, but I really want to clean it up and make it easier to maintain long-term.

So let's say it's Monday 1st shift. I want to grab Monday 1st shift's totals, but I also want to step backwards by 1 shift to the weekend shift and grab those totals to display. The weekend shifts are really what threw this for a loop because now I have to be aware of the day of the week. 3rd shift is a little leery as well because it crosses over into multiple dates. Is there a clean way to set this up? A library out there that lets me define these things easily?

Hope this made sense. Happy to clarify anything I'm missing. Thanks in advance for any guidance!

Upvotes: 0

Views: 41

Answers (2)

BlueC
BlueC

Reputation: 1581

Have you tried using CarbonPeriod? Note that Carbon is already included in Laravel so there's no need to go and add it with Composer.

Upvotes: 0

Diogo Gomes
Diogo Gomes

Reputation: 2265

Maybe a shifts resource would be usefull.

  1. creating a shifts table with id, start_date, end_date, shift_type,...

  2. when scanning for a barcode:

    • if the current shift was already created, assign a shift_id to the barcode row
    • if not, create the shift row, and assign a shift_id to the barcode row

Benefits:

  • Very easy and fast query to get the results that you need

  • If shifts changes (starting hour, ending hour,...) it would still work (the only change needed is on the method that creates the shift row)

  • Comparing shifts results would be very easy

Upvotes: 0

Related Questions