gtfs/common/time

Time and Date parsing utilities for GTFS

GTFS uses special time handling where times can exceed 24:00:00 to indicate service that continues past midnight into the next calendar day but is still part of the same “service day”.

Source: GTFS reference.md - Field Types

Values

pub fn add_seconds(t: types.Time, seconds: Int) -> types.Time

Add seconds to a time

pub fn compare_date(a: types.Date, b: types.Date) -> order.Order

Compare two dates

pub fn compare_time(a: types.Time, b: types.Time) -> order.Order

Compare two times, returning:

  • Lt if a < b
  • Eq if a == b
  • Gt if a > b
pub fn crosses_midnight(t: types.Time) -> Bool

Check if a time crosses midnight (hours >= 24)

pub fn date_in_range(
  date: types.Date,
  start: types.Date,
  end: types.Date,
) -> Bool

Check if a date is within a range (inclusive)

pub fn date_is_after(a: types.Date, b: types.Date) -> Bool

Check if date a is after date b

pub fn date_is_before(a: types.Date, b: types.Date) -> Bool

Check if date a is before date b

pub fn day_offset(t: types.Time) -> Int

Get the calendar day offset for a time Returns 0 for times < 24:00:00, 1 for 24:00:00-47:59:59, etc.

pub fn format_date(d: types.Date) -> String

Format a Date as YYYYMMDD string

pub fn format_date_iso(d: types.Date) -> String

Format a Date in human-readable ISO format (YYYY-MM-DD)

pub fn format_local_time(t: types.LocalTime) -> String

Format a LocalTime as HH:MM:SS string

pub fn format_time(t: types.Time) -> String

Format a Time as HH:MM:SS string

pub fn is_after(a: types.Time, b: types.Time) -> Bool

Check if time a is after time b

pub fn is_before(a: types.Time, b: types.Time) -> Bool

Check if time a is before time b

pub fn normalize_time(t: types.Time) -> types.Time

Normalize a time to within a 24-hour period Example: 25:30:00 -> 01:30:00

pub fn parse_date(value: String) -> Result(types.Date, String)

Parse a GTFS date string (YYYYMMDD format) Example: “20251028” -> Date(year: 2025, month: 10, day: 28)

pub fn parse_date_optional(
  value: String,
) -> Result(option.Option(types.Date), String)

Parse an optional GTFS date string

pub fn parse_local_time(
  value: String,
) -> Result(types.LocalTime, String)

Parse a local time (wall-clock time that cannot exceed 24:00:00)

pub fn parse_time(value: String) -> Result(types.Time, String)

Parse a GTFS time string (HH:MM:SS or H:MM:SS format) Times can exceed 24:00:00 for overnight service Examples: “08:30:00”, “25:35:00” (1:35 AM next day, same service day)

pub fn parse_time_optional(
  value: String,
) -> Result(option.Option(types.Time), String)

Parse an optional GTFS time string

pub fn seconds_to_time(seconds: Int) -> types.Time

Convert seconds from midnight to a Time

pub fn time_difference(a: types.Time, b: types.Time) -> Int

Calculate the difference between two times in seconds Returns a positive value if a > b, negative if a < b

pub fn time_to_seconds(t: types.Time) -> Int

Convert a Time to total seconds from midnight

Search Document