temporal

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package temporal provides value objects related to temporal information.

Package temporal provides value objects related to time and duration. It includes implementations for time-based value objects that follow the domain-driven design principles.

Package temporal provides value objects related to time and versioning information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration struct {
	base.BaseStructValueObject
	// contains filtered or unexported fields
}

Duration represents a time duration value object

func NewDuration

func NewDuration(duration time.Duration) (Duration, error)

NewDuration creates a new Duration with validation

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration creates a new Duration from a string

func (Duration) Add

func (v Duration) Add(other Duration) (Duration, error)

Add adds another Duration and returns a new Duration

func (Duration) Equals

func (v Duration) Equals(other Duration) bool

Equals checks if two Durations are equal

func (Duration) Format

func (v Duration) Format(format string) string

Format returns a formatted string representation of the duration Format options: - "short": "1h 30m 45s" - "long": "1 hour 30 minutes 45 seconds" - "compact": "1:30:45"

func (Duration) Hours

func (v Duration) Hours() float64

Hours returns the duration as a floating point number of hours

func (Duration) IsEmpty

func (v Duration) IsEmpty() bool

IsEmpty checks if the Duration is empty (zero value)

func (Duration) MarshalJSON

func (v Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (Duration) Milliseconds

func (v Duration) Milliseconds() int64

Milliseconds returns the duration as an integer number of milliseconds

func (Duration) Minutes

func (v Duration) Minutes() float64

Minutes returns the duration as a floating point number of minutes

func (Duration) Seconds

func (v Duration) Seconds() float64

Seconds returns the duration as a floating point number of seconds

func (Duration) String

func (v Duration) String() string

String returns the string representation of the Duration

func (Duration) Subtract

func (v Duration) Subtract(other Duration) (Duration, error)

Subtract subtracts another Duration and returns a new Duration If the result would be negative, it returns zero duration

func (Duration) ToMap

func (v Duration) ToMap() map[string]interface{}

ToMap converts the Duration to a map[string]interface{}

func (Duration) Validate

func (v Duration) Validate() error

Validate checks if the Duration is valid

func (Duration) Value

func (v Duration) Value() time.Duration

Value returns the underlying time.Duration value

type Time

type Time struct {
	base.BaseStructValueObject
	// contains filtered or unexported fields
}

Time represents a time value object based on RFC 3339 format. It encapsulates a time.Time value and provides methods for comparison, arithmetic, and conversion operations.

func NewTime

func NewTime(value time.Time) (Time, error)

NewTime creates a new Time with validation. It returns an error if the validation fails.

func NewTimeFromString

func NewTimeFromString(value string) (Time, error)

NewTimeFromString creates a new Time from an RFC 3339 formatted string. It returns an error if the string is empty or not in valid RFC 3339 format.

func (Time) Add

func (t Time) Add(d time.Duration) Time

Add returns a new Time with the given duration added. It properly handles any errors from the NewTime constructor.

func (Time) After

func (t Time) After(other Time) bool

After checks if this time is after another time.

func (Time) Before

func (t Time) Before(other Time) bool

Before checks if this time is before another time.

func (Time) Equal

func (t Time) Equal(other Time) bool

Equal is maintained for backward compatibility. New code should use Equals() instead.

func (Time) Equals

func (t Time) Equals(other Time) bool

Equals checks if two times are equal. This method follows the naming convention used in other value objects.

func (Time) IsEmpty

func (t Time) IsEmpty() bool

IsEmpty checks if the time is empty (zero value).

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface. It marshals the time as an RFC 3339 formatted string.

func (Time) String

func (t Time) String() string

String returns the RFC 3339 string representation of the time.

func (Time) Sub

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

Sub returns the duration between two times.

func (Time) ToMap

func (t Time) ToMap() map[string]interface{}

ToMap converts the time to a map representation.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It unmarshals an RFC 3339 formatted string into a Time.

func (Time) Validate

func (t Time) Validate() error

Validate checks if the Time is valid. Currently, all time.Time values are considered valid. This method is included for consistency with other value objects.

func (Time) Value

func (t Time) Value() time.Time

Value returns the underlying time.Time value.

type Version

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

Version represents a semantic version (major.minor.patch)

func NewVersion

func NewVersion(major, minor, patch int, preRelease, build string) (Version, error)

NewVersion creates a new Version with validation

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion creates a new Version from a string in format "major.minor.patch[-prerelease][+build]"

func (Version) Build

func (v Version) Build() string

Build returns the build metadata

func (Version) CompareTo

func (v Version) CompareTo(other Version) int

CompareTo compares this version to another version Returns:

-1 if this version is less than the other
 0 if this version is equal to the other
 1 if this version is greater than the other

func (Version) Equals

func (v Version) Equals(other Version) bool

Equals checks if two Versions are equal

func (Version) IsEmpty

func (v Version) IsEmpty() bool

IsEmpty checks if the Version is empty (zero value)

func (Version) IsPreRelease

func (v Version) IsPreRelease() bool

IsPreRelease checks if this is a pre-release version

func (Version) Major

func (v Version) Major() int

Major returns the major version number

func (Version) Minor

func (v Version) Minor() int

Minor returns the minor version number

func (Version) NextMajor

func (v Version) NextMajor() Version

NextMajor returns the next major version

func (Version) NextMinor

func (v Version) NextMinor() Version

NextMinor returns the next minor version

func (Version) NextPatch

func (v Version) NextPatch() Version

NextPatch returns the next patch version

func (Version) Patch

func (v Version) Patch() int

Patch returns the patch version number

func (Version) PreRelease

func (v Version) PreRelease() string

PreRelease returns the pre-release identifier

func (Version) String

func (v Version) String() string

String returns the string representation of the Version

func (Version) ToMap

func (v Version) ToMap() map[string]interface{}

ToMap converts the Version to a map[string]interface{}

func (Version) Validate

func (v Version) Validate() error

Validate checks if the Version is valid

Jump to

Keyboard shortcuts

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