util

package
v0.0.0-...-fd78167 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Overview

Utility types used to store common data like times

Index

Constants

View Source
const (
	DateTime      = "2006-01-02 15:04:05"
	Date          = "2006-01-02"
	HumanDateTime = "2006 Jan 02 15:04:05"
	HumanDate     = "2006 Jan 02"
	Time          = "15:04:05"
)

Variables

This section is empty.

Functions

func CompareTime

func CompareTime(a, b time.Time) bool

Compare a time.Time against another, accounting for crossing midnight. The rules for handling crossing midnight are: < -6 hours = crossed midnight < 0 back in time < 18 hours increasing time > 18 hours back in time & crossing midnight

func DecodeXML_Bool

func DecodeXML_Bool(decoder *xml.Decoder, token *xml.StartElement) (bool, error)

DecodeXML_Bool parses a simple XML element of type <element>bool</element> and returns the bool value. It's used within custom xml.UnmarshalXML() code.

func DecodeXML_Int

func DecodeXML_Int(decoder *xml.Decoder, token *xml.StartElement) (int, error)

DecodeXML_Int parses a simple XML element of type <element>integer</element> and returns the integer value. It's used within custom xml.UnmarshalXML() code.

func GenerateScheduleKey

func GenerateScheduleKey(tpl string, wta *WorkingTime, wtd *WorkingTime, wtp *WorkingTime) string

GenerateScheduleKey generates a unique key for the given tiploc and working schedule

func London

func London() *time.Location

func Now

func Now() time.Time

Now is the same as time.Now() but the returned value will be in the Europe/London timezone.

Types

type CircularTimes

type CircularTimes struct {
	// The working time for this location. This value is used in sequencing as it's based on the Working timetable.
	// This is calculated as the first value defined below in the following
	// sequence: Wtd, Wta, Wtp, Ptd & Pta.
	Time WorkingTime `json:"time"`
	// The public time for this location. This value is used for delay calculations as it's based on the Public timetable.
	// Unlike Time this iscalculated as the first value defined below in the following
	// sequence: Ptd & Pta, Wtd, Wta, Wtp.
	PublicTime WorkingTime `json:"publicTime"`
	// Public Scheduled Time of Arrival
	Pta *PublicTime `json:"pta,omitempty"`
	// Public Scheduled Time of Departure
	Ptd *PublicTime `json:"ptd,omitempty"`
	// Working Scheduled Time of Arrival
	Wta *WorkingTime `json:"wta,omitempty"`
	// Working Scheduled Time of Departure
	Wtd *WorkingTime `json:"wtd,omitempty"`
	// Working Scheduled Time of Passing
	Wtp *WorkingTime `json:"wtp,omitempty"`
}

A scheduled time used to distinguish a location on circular routes. Note that all scheduled time attributes are marked as optional, but at least one must always be supplied. Only one value is required, and typically this should be the wtd value. However, for locations that have no wtd, or for clients that deal exclusively with public times, another value that is valid for the location may be supplied.

func (*CircularTimes) Compare

func (a *CircularTimes) Compare(b *CircularTimes) bool

Compare compares two Locations by their times

func (*CircularTimes) EqualInSchedule

func (a *CircularTimes) EqualInSchedule(b *CircularTimes) bool

EqualInSchedule returns true if the working timetable fields of both CircularTimes are equal as they are the primary key

func (*CircularTimes) Equals

func (a *CircularTimes) Equals(b *CircularTimes) bool

Equals returns true if both CircularTimes are exactly the same

func (*CircularTimes) IsPass

func (t *CircularTimes) IsPass() bool

IsPass returns true if the instance represents a pass at a station

func (*CircularTimes) IsPublic

func (t *CircularTimes) IsPublic() bool

IsPublic returns true of the instance contains public times

func (*CircularTimes) ScheduleKey

func (c *CircularTimes) ScheduleKey(tpl string) string

ScheduleKey returns a unique key for this CircularTimes

func (*CircularTimes) String

func (l *CircularTimes) String() string

func (*CircularTimes) UnmarshalXMLAttributes

func (t *CircularTimes) UnmarshalXMLAttributes(start xml.StartElement)

UnmarshalXMLAttributes reads from an arbitary start element

func (*CircularTimes) UpdateTime

func (l *CircularTimes) UpdateTime()

UpdateTime updates the Time & PublicTime fields used for sequencing the location & Delays. Note these values are not persisted as it's a generated value

type PublicTime

type PublicTime struct {
	// contains filtered or unexported fields
}

Public Timetable time Note: 00:00 is not possible as in CIF that means no-time

func NewPublicTime

func NewPublicTime(s string) *PublicTime

NewPublicTime returns a new PublicTime instance from a string of format "HH:MM"

func PublicTime_FromTime

func PublicTime_FromTime(tm time.Time) *PublicTime

WorkingTime_FromTime returns a WorkingTime from a time.Time with a resolution of 1 minute.

func (*PublicTime) Compare

func (a *PublicTime) Compare(b *PublicTime) bool

Compare a PublicTime against another, accounting for crossing midnight. The rules for handling crossing midnight are: < -6 hours = crossed midnight < 0 back in time < 18 hours increasing time > 18 hours back in time & crossing midnight

func (*PublicTime) Equals

func (a *PublicTime) Equals(b *PublicTime) bool

func (*PublicTime) Get

func (t *PublicTime) Get() int

Get returns the PublicTime in minutes of the day

func (*PublicTime) IsNil

func (t *PublicTime) IsNil() bool

Is this instance representing nil

func (*PublicTime) IsZero

func (t *PublicTime) IsZero() bool

IsZero returns true if the time is not present

func (*PublicTime) MarshalJSON

func (t *PublicTime) MarshalJSON() ([]byte, error)

Custom JSON Marshaler. This will write null or the time as "HH:MM"

func (*PublicTime) MarshalXMLAttr

func (t *PublicTime) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

Custom XML Marshaler.

func (*PublicTime) Parse

func (v *PublicTime) Parse(s string)

func (*PublicTime) Set

func (t *PublicTime) Set(v int)

Set sets the PublicTime in minutes of the day

func (*PublicTime) SetTime

func (t *PublicTime) SetTime(tm time.Time)

SetTime set's the working time to the current time (resolution 1 minute)

func (*PublicTime) String

func (t *PublicTime) String() string

String returns a PublicTime in HH:MM format or 5 blank spaces if it's not set.

func (*PublicTime) Time

func (pt *PublicTime) Time(t time.Time) time.Time

Time returns the PublicTime as a time.Time The returned value will be in the Europe/London time zone. t The time containing the date to contain the PublicTime

func (*PublicTime) TrainTime

func (pt *PublicTime) TrainTime(t time.Time) time.Time

TrainTime returns the PublicTime as a time.Time based on the supplied start time. This start time should be the date & time of the scheduled departure because we use this moment in time to determine if midnight has been crossed so that the result is always after the passed value of t. The returned value will be in the Europe/London time zone. t The time containing the date & time of the scheduled departure.

func (*PublicTime) UnmarshalJSON

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

type SSD

type SSD struct {
	// contains filtered or unexported fields
}

func (*SSD) Before

func (s *SSD) Before(t time.Time) bool

Before is an SSD before a specified time

func (*SSD) Equals

func (a *SSD) Equals(b *SSD) bool

func (*SSD) MarshalJSON

func (t *SSD) MarshalJSON() ([]byte, error)

Custom JSON Marshaler.

func (*SSD) MarshalXMLAttr

func (t *SSD) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

Custom XML Marshaler.

func (*SSD) Parse

func (t *SSD) Parse(s string)

func (*SSD) Set

func (t *SSD) Set(t0 time.Time)

func (*SSD) String

func (t *SSD) String() string

String returns a SSD in "YYYY-MM-DD" format

func (*SSD) Time

func (t *SSD) Time() time.Time

func (*SSD) UnmarshalJSON

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

type TSTime

type TSTime struct {
	// Estimated Time. For locations with a public activity,
	// this will be based on the "public schedule".
	// For all other activities, it will be based on the "working schedule".
	ET *WorkingTime `json:"et,omitempty" xml:"et,attr,omitempty"`
	// The manually applied lower limit that has been applied to the estimated
	// time at this location. The estimated time will not be set lower than this
	// value, but may be set higher.
	ETMin *WorkingTime `json:"etMin,omitempty" xml:"etmin,attr,omitempty"`
	// Indicates that an unknown delay forecast has been set for the estimated
	// time at this location. Note that this value indicates where a manual
	// unknown delay forecast has been set, whereas it is the "delayed"
	// attribute that indicates that the actual forecast is "unknown delay".
	ETUnknown bool `json:"etUnknown,omitempty" xml:"etUnknown,attr,omitempty"`
	// The estimated time based on the "working schedule".
	// This will only be set for public activities and when it also differs
	// from the estimated time based on the "public schedule".
	WET *WorkingTime `json:"wet,omitempty" xml:"wet,attr,omitempty"`
	// Actual Time
	AT *WorkingTime `json:"at,omitempty" xml:"at,attr,omitempty"`
	// If true, indicates that an actual time ("at") value has just been removed
	// and replaced by an estimated time ("et").
	// Note that this attribute will only be set to "true" once, when the actual
	// time is removed, and will not be set in any snapshot.
	ATRemoved bool `json:"atRemoved,omitempty" xml:"atRemoved,attr,omitempty"`
	// The class of the actual time.
	// Added 2018-12-18 in rttiPPTForecasts_v3.xsd
	ATClass string `json:"atClass,omitempty" xml:"atClass,attr,omitempty"`
	// Indicates that this estimated time is a forecast of "unknown delay".
	// Displayed  as "Delayed" in LDB.
	// Note that this value indicates that this forecast is "unknown delay",
	// whereas it is the "etUnknown" attribute that indicates where the manual
	// unknown delay forecast has been set.
	Delayed bool `json:"delayed,omitempty" xml:"delayed,attr,omitempty"`
	// The source of the forecast or actual time.
	Src string `json:"src,omitempty" xml:"src,attr,omitempty"`
	// The RTTI CIS code of the CIS instance if the src is a CIS.
	SrcInst string `json:"srcInst,omitempty" xml:"srcInst,attr,omitempty"`
}

Type describing time-based forecast attributes for a TS arrival/departure/pass

func (*TSTime) Compare

func (a *TSTime) Compare(b *TSTime) bool

Compare compares two TSTime's. This will use the value returned by TSTime.Time()

func (*TSTime) Equals

func (a *TSTime) Equals(b *TSTime) bool

func (*TSTime) IsSet

func (t *TSTime) IsSet() bool

IsSet returns true if at least ET or AT is set

func (*TSTime) MarshalJSON

func (t *TSTime) MarshalJSON() ([]byte, error)

func (*TSTime) Time

func (t *TSTime) Time() *WorkingTime

Time returns the appropirate time from TSTime to use in displays. This is the first one set of AT, ET or nil if neither is set.

func (*TSTime) UnmarshalXML

func (s *TSTime) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type WorkingTime

type WorkingTime struct {
	// contains filtered or unexported fields
}

Working Timetable time. WorkingTime is similar to PublicTime, except we can have seconds. In the Working Timetable, the seconds can be either 0 or 30.

func NewWorkingTime

func NewWorkingTime(s string) *WorkingTime

NewWorkingTime returns a new WorkingTime instance from a string of format "HH:MM:SS"

func WorkingTimeFromBytes

func WorkingTimeFromBytes(b []byte) *WorkingTime

func WorkingTime_FromTime

func WorkingTime_FromTime(tm time.Time) *WorkingTime

WorkingTime_FromTime returns a WorkingTime from a time.Time with a resolution of 1 minute.

func (*WorkingTime) After

func (a *WorkingTime) After(b *WorkingTime) bool

After returns true if this WorkingTime is after another

func (*WorkingTime) Before

func (a *WorkingTime) Before(b *WorkingTime) bool

Before returns true if this WorkingTime is before another

func (*WorkingTime) Between

func (t *WorkingTime) Between(from *WorkingTime, to *WorkingTime) bool

Between returns true if this WorkingTime falls between two other WorkingTime's. The test is inclusive of the from & to times. If from is after to then we presume we cross midnight.

func (*WorkingTime) Bytes

func (a *WorkingTime) Bytes() []byte

func (*WorkingTime) Compare

func (a *WorkingTime) Compare(b *WorkingTime) bool

Compare a WorkingTime against another, accounting for crossing midnight. The rules for handling crossing midnight are: < -6 hours = crossed midnight < 0 back in time < 18 hours increasing time > 18 hours back in time & crossing midnight

func (WorkingTime) Difference

func (wt WorkingTime) Difference(ot WorkingTime) int

Difference returns the difference between two WorkingTimes in seconds. A positive value indicates that this WorkingTime is after the parameter. A negative value inidcates that this WorkingTime is before the parameter.

func (*WorkingTime) Equals

func (a *WorkingTime) Equals(b *WorkingTime) bool

func (*WorkingTime) Get

func (t *WorkingTime) Get() int

Get returns the WorkingTime in seconds of the day

func (WorkingTime) IsApproaching

func (wt WorkingTime) IsApproaching() bool

IsApproaching returns true if the WorkingTime is in the last Minute based on the current clock

func (*WorkingTime) IsZero

func (t *WorkingTime) IsZero() bool

IsZero returns true if the time is not present

func (*WorkingTime) MarshalJSON

func (t *WorkingTime) MarshalJSON() ([]byte, error)

Custom JSON Marshaler. This will write null or the time as "HH:MM:SS"

func (*WorkingTime) MarshalXMLAttr

func (t *WorkingTime) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

Custom XML Marshaler.

func (*WorkingTime) Parse

func (v *WorkingTime) Parse(s string)

func (*WorkingTime) Set

func (t *WorkingTime) Set(v int)

Set sets the WorkingTime in seconds of the day

func (*WorkingTime) SetTime

func (t *WorkingTime) SetTime(tm time.Time)

SetTime set's the working time to the current time (resolution 1 minute)

func (*WorkingTime) String

func (t *WorkingTime) String() string

String returns a PublicTime in HH:MM:SS format or 8 blank spaces if it's not set.

func (*WorkingTime) Time

func (wt *WorkingTime) Time(t time.Time) time.Time

Time returns the WorkingTime as a time.Time. The returned value will be in the Europe/London time zone. t The time containing the date to contain the WorkingTime

func (*WorkingTime) TrainTime

func (wt *WorkingTime) TrainTime(t time.Time) time.Time

TrainTime returns the PublicTime as a time.Time based on the supplied start time. This start time should be the date & time of the scheduled departure because we use this moment in time to determine if midnight has been crossed so that the result is always after the passed value of t. The returned value will be in the Europe/London time zone. t The time containing the date & time of the scheduled departure.

func (*WorkingTime) UnmarshalJSON

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

type XmlBuilder

type XmlBuilder struct {
	// contains filtered or unexported fields
}

func NewXmlBuilder

func NewXmlBuilder(e *xml.Encoder, start xml.StartElement) *XmlBuilder

func (*XmlBuilder) AddAttribute

func (b *XmlBuilder) AddAttribute(n xml.Name, v string) *XmlBuilder

func (*XmlBuilder) AddAttributeIfSet

func (b *XmlBuilder) AddAttributeIfSet(n xml.Name, v string) *XmlBuilder

func (*XmlBuilder) AddBoolAttribute

func (b *XmlBuilder) AddBoolAttribute(n xml.Name, v bool) *XmlBuilder

func (*XmlBuilder) AddBoolAttributeIfSet

func (b *XmlBuilder) AddBoolAttributeIfSet(n xml.Name, v bool) *XmlBuilder

func (*XmlBuilder) AddCharData

func (b *XmlBuilder) AddCharData(v string) *XmlBuilder

func (*XmlBuilder) AddComment

func (b *XmlBuilder) AddComment(v string) *XmlBuilder

func (*XmlBuilder) AddFloat32Attribute

func (b *XmlBuilder) AddFloat32Attribute(n xml.Name, v float32) *XmlBuilder

func (*XmlBuilder) AddFloat32AttributeIfSet

func (b *XmlBuilder) AddFloat32AttributeIfSet(n xml.Name, v float32) *XmlBuilder

func (*XmlBuilder) AddFloatAttribute

func (b *XmlBuilder) AddFloatAttribute(n xml.Name, v float64) *XmlBuilder

func (*XmlBuilder) AddFloatAttributeIfSet

func (b *XmlBuilder) AddFloatAttributeIfSet(n xml.Name, v float64) *XmlBuilder

func (*XmlBuilder) Append

func (b *XmlBuilder) Append(n xml.Name, v interface{}) *XmlBuilder

func (*XmlBuilder) Build

func (b *XmlBuilder) Build() error

func (*XmlBuilder) Element

func (b *XmlBuilder) Element(n xml.Name, f func(builder *XmlBuilder) error) *XmlBuilder

func (*XmlBuilder) ElementIf

func (b *XmlBuilder) ElementIf(v bool, n xml.Name, f func(builder *XmlBuilder) error) *XmlBuilder

func (*XmlBuilder) EndIf

func (b *XmlBuilder) EndIf() *XmlBuilder

func (*XmlBuilder) If

func (b *XmlBuilder) If(v bool) *XmlBuilder

func (*XmlBuilder) Run

func (b *XmlBuilder) Run(f func(builder *XmlBuilder) error) *XmlBuilder

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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