gtfs/common/types

Common types used across GTFS Static and Realtime

These foundational types represent the core data formats specified in the GTFS reference documentation.

Types

Color as RGB values Stored as separate R, G, B integers (0-255 each) In GTFS files, colors are represented as 6-character hex strings without the # prefix (e.g., “FFFFFF” for white, “000000” for black) Source: GTFS Static reference.md

pub type Color {
  Color(red: Int, green: Int, blue: Int)
}

Constructors

  • Color(red: Int, green: Int, blue: Int)

Geographic coordinate (WGS84) Latitude: -90.0 to 90.0 (decimal degrees) Longitude: -180.0 to 180.0 (decimal degrees) Source: GTFS Static reference.md

pub type Coordinate {
  Coordinate(latitude: Float, longitude: Float)
}

Constructors

  • Coordinate(latitude: Float, longitude: Float)

Currency amount with proper decimal handling Uses integer arithmetic to avoid floating-point precision issues decimal_places indicates where the decimal point should be placed Example: amount=199, decimal_places=2 represents 1.99 Source: GTFS Static reference.md

pub type CurrencyAmount {
  CurrencyAmount(amount: Int, decimal_places: Int)
}

Constructors

  • CurrencyAmount(amount: Int, decimal_places: Int)

ISO 4217 currency code (3 letters) Examples: “USD”, “EUR”, “JPY” Source: GTFS Static reference.md

pub type CurrencyCode {
  CurrencyCode(code: String)
}

Constructors

  • CurrencyCode(code: String)

Date in YYYYMMDD format Example: 20251028 represents October 28, 2025 Source: GTFS Static reference.md

pub type Date {
  Date(year: Int, month: Int, day: Int)
}

Constructors

  • Date(year: Int, month: Int, day: Int)

A valid email address Source: GTFS Static reference.md

pub type Email {
  Email(value: String)
}

Constructors

  • Email(value: String)

A unique identifier string Used for agency_id, route_id, trip_id, stop_id, etc.

pub type Id {
  Id(value: String)
}

Constructors

  • Id(value: String)

BCP-47/IETF language code Examples: “en”, “en-US”, “fr-CA”, “zh-Hant” Source: GTFS Static reference.md

pub type LanguageCode {
  LanguageCode(code: String)
}

Constructors

  • LanguageCode(code: String)

Local time - wall-clock time in local timezone Used for timeframes.txt Cannot exceed 24:00:00 (unlike Time type) Source: GTFS Static reference.md

pub type LocalTime {
  LocalTime(hours: Int, minutes: Int, seconds: Int)
}

Constructors

  • LocalTime(hours: Int, minutes: Int, seconds: Int)

A phone number string Source: GTFS Static reference.md

pub type PhoneNumber {
  PhoneNumber(value: String)
}

Constructors

  • PhoneNumber(value: String)

Presence requirement level for fields Used for documentation and validation purposes

pub type Presence {
  Required
  Optional
  ConditionallyRequired(condition: String)
  ConditionallyForbidden(condition: String)
  Recommended
}

Constructors

  • Required

    Field must always be provided

  • Optional

    Field is optional

  • ConditionallyRequired(condition: String)

    Field is required when a specific condition is met

  • ConditionallyForbidden(condition: String)

    Field must not be provided when a specific condition is met

  • Recommended

    Field is recommended but not required

Time in HH:MM:SS format (H:MM:SS also accepted) Can exceed 24:00:00 for overnight service on the same service day Example: 25:35:00 represents 1:35 AM on the next calendar day but still part of the same service day Source: GTFS Static reference.md - times can exceed 24:00:00

pub type Time {
  Time(hours: Int, minutes: Int, seconds: Int)
}

Constructors

  • Time(hours: Int, minutes: Int, seconds: Int)

IANA timezone identifier Examples: “America/New_York”, “Europe/London”, “Asia/Tokyo” Source: GTFS Static reference.md

pub type Timezone {
  Timezone(name: String)
}

Constructors

  • Timezone(name: String)

A fully qualified URL including http:// or https:// Source: GTFS Static reference.md

pub type Url {
  Url(value: String)
}

Constructors

  • Url(value: String)

Values

pub fn color(red: Int, green: Int, blue: Int) -> Color

Create a new Color from red, green, and blue components (0-255)

pub fn color_from_hex(hex: String) -> option.Option(Color)

Create a Color from a hex string (with or without # prefix) Returns None if the string is not a valid hex color

pub fn coordinate(
  latitude: Float,
  longitude: Float,
) -> Coordinate

Create a new Coordinate from latitude and longitude

pub fn currency_amount(
  amount: Int,
  decimal_places: Int,
) -> CurrencyAmount

Create a new CurrencyAmount

pub fn currency_code(code: String) -> CurrencyCode

Create a new CurrencyCode

pub fn date(year: Int, month: Int, day: Int) -> Date

Create a new Date from year, month, and day components

pub fn email(value: String) -> Email

Create a new Email

pub fn id(value: String) -> Id

Create a new Id

pub fn is_valid_color(c: Color) -> Bool

Check if a color has valid RGB values (0-255)

pub fn is_valid_coordinate(coord: Coordinate) -> Bool

Check if a coordinate is within valid WGS84 bounds

pub fn language_code(code: String) -> LanguageCode

Create a new LanguageCode

pub fn local_time(
  hours: Int,
  minutes: Int,
  seconds: Int,
) -> LocalTime

Create a new LocalTime from hours, minutes, and seconds

pub fn phone_number(value: String) -> PhoneNumber

Create a new PhoneNumber

pub fn seconds_to_time(seconds: Int) -> Time

Convert seconds from midnight to a Time

pub fn time(hours: Int, minutes: Int, seconds: Int) -> Time

Create a new Time from hours, minutes, and seconds

pub fn time_to_seconds(t: Time) -> Int

Convert a Time to total seconds from midnight Useful for comparing times or calculating durations

pub fn timezone(name: String) -> Timezone

Create a new Timezone

pub fn url(value: String) -> Url

Create a new Url

Search Document