Time

package
v0.0.0-...-b0e9511 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(layout, value string) Result.Interface

Parse builds a Time from a layout and a value (see time.Parse).

On success the Result carries the Time as its payload; when the value does not match the layout the Result carries an Error instead — the operation never panics and never returns nil.

r := Time.Parse(time.RFC3339, "2026-06-20T12:00:00Z")
if r.HasError() {
    // r.Error().Message()
}

func ParseAny

func ParseAny(value string) Result.Interface

ParseAny builds a Time from a date/time string WITHOUT an explicit layout, trying the real-world format zoo — RFC 822/1123/2822/3339/5322, asctime, HTTP, 2-digit years, ISO 8601 and named-zone abbreviations — via the shared go-datetime/dates parser. This is the lenient, MRI-style Time.parse behaviour (Ruby's Time.parse accepts almost any recognisable date), so consumers such as the rbgo interpreter delegate here instead of reimplementing a layout table.

On success the Result carries the Time; an unrecognisable value carries an Error; the operation never panics and never returns nil.

r := Time.ParseAny("Tue, 07 Jul 26 11:13:37 UTC") // 2-digit year + named zone

Types

type Interface

type Interface interface {
	ToUnix() int64
	Format(layout string) string
	ToGoString() string
	In(name string) Result.Interface
	Zone() string
	UTC() Interface
	Before(Interface) bool
	After(Interface) bool
	Equal(Interface) bool
	Add(Duration.Interface) Result.Interface
	Sub(Interface) Duration.Interface
	IsNull() bool
}

Time is a composite over an instant in time, wrapping Go's stdlib time.Time (Ruby's Time as the reference).

It follows Composition-Oriented Programming: it is interface-first, its fallible constructors (Parse, Add) return a Result.Interface so that failures are values rather than panics, and it ships a Null-Object variant so callers never have to test for a bare nil.

Time is deterministic by construction: there is no Now(). Instances are built only from explicit values (FromUnix, Parse), which keeps behaviour reproducible across architectures and test runs.

func FromUnix

func FromUnix(sec int64) Interface

FromUnix is the Time constructor from a Unix timestamp (seconds since the epoch), in UTC.

t := Time.FromUnix(0) // 1970-01-01T00:00:00Z

func Null

func Null() Interface

Null returns the Null-Object variant of Time.

It satisfies Interface so callers never have to test for a bare nil: it denotes the zero instant, its comparisons are false, its Add yields itself, its Sub yields a null Duration, and IsNull() returns true.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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