Characterize Ship Cutoffs With Twelve Frozen Instants
Move one holiday check only after a frozen cutoff table holds. A messy ship function hides three clocks in one return. An early extract can flip a same-day answer without a failing test. Start from the boolean you have Same-day shipping rules fail in quiet local ways. A holiday string can miss the zoned date. A VIP hour bump can cross a trusted cutoff. This module is only a labeled teaching…
The provided code defines a function called `can_ship_today` that takes in four parameters: `now`, `warehouse_tz`, `carrier`, and `vip`. The function determines whether a shipment can be made today based on certain conditions.
The function first converts the `now` parameter to the local time zone specified by `warehouse_tz`. It then sets the `cutoff` time based on the `carrier` and `vip` parameters. If the `carrier` is not "air", the cutoff time is set to 15:00, otherwise it is set to 12:00. If `vip` is `True`, the cutoff time is incremented by one hour.
Next, the function checks if the `carrier` is "air" or if the `stamp` (local date) is present in the `HOLIDAYS` set. If either condition is true, the function returns `False`, indicating that the shipment cannot be made today.
The function also checks if the local time is equal to or greater than the `cutoff` time, and if the local day of the week is Saturday (weekday() equals 5). If either condition is true, the function returns `False`.
If none of the above conditions are met, the function returns `True`, indicating that the shipment can be made today.
The code also includes a set of test cases defined in the `ROWS` list. Each row consists of a UTC instant, zone, carrier, VIP flag, and the expected boolean result. These test cases cover various scenarios, such as different dates, zones, carriers, VIP flags, and cutoff times.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.