Urgent.News

What's breaking now, across thousands of outlets.

Tech

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.

Read the original at dev.to →

More in Tech

The Celebrity Problem: From Brute Force to O(n)

Imagine you walk into a party with a few hundred guests. You don't know who anyone is, but you're told that one person there might be a celebrity .

  • Celebrity satisfies two rules: known by everyone, knows no one
  • Brute force approach has O(n²) time complexity, constant space
  • Efficient algorithm reduces time complexity to O(n) with O(n) space

Restrict SSH Logins with AllowUsers Without Locking Yourself Out

A valid SSH key or password does not guarantee that an account can log in. OpenSSH can apply an additional server-side filter: AllowUsers lists which accounts are eligible to connect.

  • AllowUsers restricts SSH logins to specified users.
  • Multiple users can be allowed by separating names with spaces.
  • Incorrectly configured AllowUsers can lock out legitimate users.

More from Sunday 11 October →