Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Build a Time-Zone-Safe Itinerary Validator in Python

A travel itinerary looks like a sequence of cards: a museum at 10:00, lunch at 12:30, and a train later in the day. Underneath those cards, however, is a scheduling problem. Time zones, daylight-saving transitions, inconsistent supplier data, and missing transfer time can make a plan impossible even when every individual booking is valid. This tutorial builds a small, dependency-free itinerary…

A travel itinerary consists of a series of activities, each with a start time, end time, label, required transfer time, and time zone. However, time zones, daylight saving changes, inconsistent supplier data, and missing transfer times can make any plan invalid even if each booking individually appears valid.

This tutorial presents a small, dependency-free itinerary validator in Python that checks the facts a travel application already has, reports conflicts, and explains why a proposed schedule needs attention. It does not make up journey durations or decide whether a restaurant is open. Instead, it verifies the facts provided by the application, reports any issues, and explains why the proposed schedule requires attention.

To use the validator, you should store instants, not just clock labels. For example, a flight arrival at 14:10 and hotel check-in at 14:45 might seem to have a 35-minute gap at first glance. However, if those times belong to different cities or if a supplier has stripped the UTC offset, the actual gap could be different. Therefore, the scheduling engine should not guess; it must require an ISO 8601 timestamp that includes an explicit offset, such as 2027-04-07T10:00:00+02:00.

This timestamp identifies a real instant and keeps the IANA time-zone name as separate metadata for display and future date calculations. Remember, Paris is not always UTC+02:00; its offset changes seasonally.

Our prototype event contract includes three fields: start and end times as offset-aware timestamps, label (human-readable activity name), travel_after_min (estimated transfer time), and zone (IANA time zone used by the activity's local clock). The transfer estimate must come from a routing provider, tour operator, or a clearly labeled user assumption. A validator should never silently substitute a made-up travel duration.

The validator checks for duration, overlap, and transfer buffer issues. If an event's start and end times are the same, or if the transfer estimate is negative, it reports an error. To normalize the events and avoid incorrect comparisons across time zones, the validator converts all instants to UTC. It then sorts the events by their UTC start times and checks for any gaps between events. If there is a gap smaller than the estimated transfer time, it reports an issue.

For example, consider these fictional appointments: a museum visit from 10:00 to 11:30 in Paris, lunch from 12:30 to 13:30 in Paris, and an afternoon walk from 13:45 to 14:30 in Paris. The validator will report that the lunch interval provides only 15 minutes for a transfer estimated at 20 minutes, indicating that the transfer requirement cannot be met.

The validator catches time zone mistakes by requiring ISO 8601 timestamps with explicit offsets. For instance, an impossible offset or a mismatch between the local time/zone and the UTC offset would raise an error. This approach is deliberately strict and aims to provide accurate results rather than plausible-looking but untrustworthy ones. In a production API, you could convert these exceptions into a structured validation response that identifies the affected record.

The transfer requirement belongs to the preceding event in our data model. However, a richer route graph could attach transfer estimates to each pair of locations and travel mode, representing transfers as their own scheduled events. Our simpler model demonstrates the principle effectively.

To prove the validator's effectiveness, run a small example with fictional appointments and check for any reported issues. This will demonstrate that the validator can catch time zone mistakes and other scheduling conflicts.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Builds are the new bottleneck

The world is going to need more compute. Agents produce more software, and that software needs to be built and tested. When we started building infrastructure at Tuist , we expected that demand to…

  • Tuist developed Struo to address repetitive dependency compilation.
  • Struo connects existing projects to new caching and remote execution infrastructure.
  • Simple incremental adoption allows teams to optimize compute usage without workflow changes.

Two customers, one item left: preventing overselling with one PostgreSQL UPDATE

Two customers. One kurta left. Both press Place order within the same second. In many stores, both orders go through. Somebody finds out later, usually the shop owner, on the phone, apologising.

  • Prevent overselling with single PostgreSQL UPDATE statement
  • Reserve stock in conditional update to check availability
  • Lazy cleanup releases expired reservations without cron job

How vibedom turns a website's look into a procedural soundscape

Paste a URL into vibedom and it plays a soundtrack built from that site's design. A scraper reads the page, a JSON "Sound Seed" is produced, and Tone.js synthesises pad, drone and arpeggio in the…

  • Vibedom generates soundscape from website's visual design
  • Scrapes page elements, creates Sound Seed in JSON
  • Tone.js synthesizes audio in browser without downloads

More from Thursday 26 November →