Documentation ¶
Index ¶
- Constants
- Variables
- func FormatTimeDuration(d time.Duration) string
- type DesignatorMetError
- type DesignatorNotFoundError
- type DesignatorValueNotFoundError
- type Duration
- func (d *Duration) Days() float64
- func (d *Duration) Hours() float64
- func (d Duration) MarshalJSON() ([]byte, error)
- func (d Duration) MarshalYAML() (interface{}, error)
- func (d *Duration) Minutes() float64
- func (d *Duration) Months() float64
- func (d *Duration) Seconds() float64
- func (d *Duration) String() string
- func (d *Duration) ToTimeDuration() time.Duration
- func (d *Duration) UnmarshalJSON(source []byte) error
- func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (d *Duration) Weeks() float64
- func (d *Duration) Years() float64
- type IncorrectDesignatorError
- type IncorrectIsoFormatError
- type PeriodDuration
- type TimeDuration
Constants ¶
const ( // PERIOD is constant that defines period designators PERIOD = 'P' // TIME is constant that defines time designators TIME = 'T' // YEAR is constant that defines year designators YEAR = 'Y' // MONTH is constant that defines month designators MONTH = 'M' // WEEK is constant that defines week designators WEEK = 'W' // DAY is constant that defines day designators DAY = 'D' // HOUR is constant that defines hour designators HOUR = 'H' // MINUTE is constant that defines minute designators MINUTE = 'M' // SECOND is constant that defines second designators SECOND = 'S' // DayHours is constant that defines number of hours in a day DayHours = 24 // WeekDays is constant that defines number of days in a week WeekDays = 7 // YearDays is constant that defines number of days in a year YearDays = 365 // MonthDays is constant that defines number of days in a month MonthDays = YearDays / 12 )
Variables ¶
var IsNotIsoFormatError = errors.New("incorrect ISO 8601 duration format")
IsNotIsoFormatError occurs when parsing a string in ISO 8601 duration format, the error cannot be clearly identified
var PeriodIsEmptyError = errors.New("incorrect ISO 8601 P duration format, designator P found, but value is empty")
PeriodIsEmptyError occurs when a period designator is found in a line, but its value is not found For example: P
var TimeIsEmptyError = errors.New("incorrect ISO 8601 T duration format, designator T found, but value is empty")
TimeIsEmptyError occurs when a time designator is found in a line, but its value is not found For example: P10YT
Functions ¶
func FormatTimeDuration ¶
FormatTimeDuration represents time.Duration as a string in ISO 8601 duration format Affect: This may have some rounding inaccuracies
Types ¶
type DesignatorMetError ¶
type DesignatorMetError struct {
// contains filtered or unexported fields
}
DesignatorMetError occurs when this designator has already been processed previously. Affect: if you write string like PT10H0M10M it defines value as 10 For example: P1Y5Y
func NewDesignatorMetError ¶
func NewDesignatorMetError(designator rune) *DesignatorMetError
NewDesignatorMetError creates new DesignatorMetError
func (*DesignatorMetError) Error ¶
func (i *DesignatorMetError) Error() string
Error defines error output
func (*DesignatorMetError) Is ¶
func (i *DesignatorMetError) Is(err error) bool
Is checks for object matching
type DesignatorNotFoundError ¶
type DesignatorNotFoundError struct {
// contains filtered or unexported fields
}
DesignatorNotFoundError occurs when there is no designator in the line after the token For example P10T10H.
func NewDesignatorNotFoundError ¶
func NewDesignatorNotFoundError(state rune, after string) *DesignatorNotFoundError
NewDesignatorNotFoundError creates new DesignatorNotFoundError
func (*DesignatorNotFoundError) Error ¶
func (i *DesignatorNotFoundError) Error() string
Error defines error output
func (*DesignatorNotFoundError) Is ¶
func (i *DesignatorNotFoundError) Is(err error) bool
Is checks for object matching
type DesignatorValueNotFoundError ¶
type DesignatorValueNotFoundError struct {
// contains filtered or unexported fields
}
DesignatorValueNotFoundError occurs when no value is found for the designator For example: PT1HM
func NewDesignatorValueNotFoundError ¶
func NewDesignatorValueNotFoundError(state, designator rune) *DesignatorValueNotFoundError
NewDesignatorValueNotFoundError creates new DesignatorValueNotFoundError
func (*DesignatorValueNotFoundError) Error ¶
func (i *DesignatorValueNotFoundError) Error() string
Error defines error output
func (*DesignatorValueNotFoundError) Is ¶
func (i *DesignatorValueNotFoundError) Is(err error) bool
Is checks for object matching
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration is basic duration structure
func MustParseDuration ¶
MustParseDuration is the main method for parsing a string in ISO format. Returns *Duration. If the string cannot be parsed, it returns a panic For example: P10Y5M2W1DT1H1.5M50S or -P10Y5M2W1DT1H1.5M50S
func NewDuration ¶
func NewDuration(years, months, days, weeks, hours, minutes, seconds float64, isNegative bool) *Duration
NewDuration creates new *Duration based on time and period marks
func NewFromTimeDuration ¶
NewFromTimeDuration creates new *Duration based on time.Duration Affect: This may have some rounding inaccuracies
func ParseDuration ¶
ParseDuration is the main method for parsing a string in ISO format. Returns *Duration and an error if the string could not be parsed For example: P10Y5M2W1DT1H1.5M50S or -P10Y5M2W1DT1H1.5M50S
func (Duration) MarshalJSON ¶
MarshalJSON designed to deserialize *Duration to a string in ISO 8601 duration format, defined in user code via the json library
func (Duration) MarshalYAML ¶
MarshalYAML designed to deserialize *Duration to a string in ISO 8601 duration format, defined in user code via the gopkg.in/yaml.v3 library
func (*Duration) ToTimeDuration ¶
ToTimeDuration turns *Duration into time.Duration
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON designed to serialize a string in ISO 8601 duration format to *Duration, defined in user code via the json library
func (*Duration) UnmarshalYAML ¶
UnmarshalYAML designed to serialize a string in ISO 8601 duration format to *Duration, defined in user code via the gopkg.in/yaml.v3 library
type IncorrectDesignatorError ¶
type IncorrectDesignatorError struct {
// contains filtered or unexported fields
}
IncorrectDesignatorError occurs when an unknown designator is encountered in the line. For example: PT10Y or P1V
func NewIncorrectDesignatorError ¶
func NewIncorrectDesignatorError(state, designator rune) *IncorrectDesignatorError
NewIncorrectDesignatorError creates new IncorrectDesignatorError
func (*IncorrectDesignatorError) Error ¶
func (i *IncorrectDesignatorError) Error() string
Error defines error output
func (*IncorrectDesignatorError) Is ¶
func (i *IncorrectDesignatorError) Is(err error) bool
Is checks for object matching
type IncorrectIsoFormatError ¶
type IncorrectIsoFormatError struct {
// contains filtered or unexported fields
}
IncorrectIsoFormatError occurs when a token is found in a string that cannot be converted to the float64 type For example: P10,5Y
func NewIncorrectIsoFormatError ¶
func NewIncorrectIsoFormatError(in string) *IncorrectIsoFormatError
NewIncorrectIsoFormatError creates new IncorrectIsoFormatError
func (*IncorrectIsoFormatError) Error ¶
func (i *IncorrectIsoFormatError) Error() string
Error defines error output
func (*IncorrectIsoFormatError) Is ¶
func (i *IncorrectIsoFormatError) Is(err error) bool
Is checks for object matching
type PeriodDuration ¶
type PeriodDuration struct {
// contains filtered or unexported fields
}
PeriodDuration is period duration marks
type TimeDuration ¶
type TimeDuration struct {
// contains filtered or unexported fields
}
TimeDuration is time duration marks