model

package
v1.13.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package model defines data types for the Swiss public transport API responses.

Index

Constants

This section is empty.

Variables

View Source
var SwissLocation = func() *time.Location {
	loc, err := time.LoadLocation("Europe/Zurich")
	if err != nil {
		loc = time.FixedZone("CET", 1*60*60)
	}
	return loc
}()

SwissLocation is the time zone for Switzerland (CET/CEST, Europe/Zurich). main.go imports _ "time/tzdata" so the embedded TZ database is always available; the fixed-offset fallback is a last-resort safety net only and does not handle the CET↔CEST daylight-saving transition.

Functions

This section is empty.

Types

type Arrival

type Arrival struct {
	Station   Station   `json:"station"`
	Scheduled Timestamp `json:"arrival"`
	Platform  string    `json:"platform"`
	Delay     int       `json:"delay"`
}

Arrival holds arrival information for a connection section.

type Connection

type Connection struct {
	From struct {
		Station   Station   `json:"station"`
		Departure Timestamp `json:"departure"`
		Delay     int       `json:"delay"`
		Platform  string    `json:"platform"`
	} `json:"from"`

	To struct {
		Station  Station   `json:"station"`
		Arrival  Timestamp `json:"arrival"`
		Platform string    `json:"platform"`
	} `json:"to"`

	Duration  string    `json:"duration"`
	Transfers int       `json:"transfers"`
	Sections  []Section `json:"sections"`
}

Connection represents a complete route between two stations.

type Coordinate

type Coordinate struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Coordinate represents a geographic position.

type Departure

type Departure struct {
	Station   Station   `json:"station"`
	Scheduled Timestamp `json:"departure"`
	Platform  string    `json:"platform"`
	Delay     int       `json:"delay"`
}

Departure holds departure information for a connection section.

type Section

type Section struct {
	Journey *struct {
		Category string `json:"category"`
		Number   string `json:"number"`
		Operator string `json:"operator"`
		To       string `json:"to"`
	} `json:"journey"`
	Walk *struct {
		Duration  int       `json:"duration"`
		Departure Departure `json:"departure"`
		Arrival   Arrival   `json:"arrival"`
	} `json:"walk"`
	Departure Departure `json:"departure"`
	Arrival   Arrival   `json:"arrival"`
}

Section represents a leg of a connection (either a journey or a walk).

type Station

type Station struct {
	Name       string     `json:"name"`
	Coordinate Coordinate `json:"coordinate"`
}

Station represents a transport stop or station.

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp wraps time.Time with custom JSON unmarshaling for the SBB API date format (2006-01-02T15:04:05-0700).

func (Timestamp) Local

func (t Timestamp) Local() time.Time

Local overrides time.Time.Local() to return the timestamp in Swiss time (CET/CEST, Europe/Zurich) instead of the system's local timezone.

func (Timestamp) Sub

func (t Timestamp) Sub(other Timestamp) time.Duration

Sub returns the duration between two Timestamps.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON parses the SBB API date format into a Timestamp.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL