Documentation
¶
Index ¶
- func Add(d time.Duration) func(destination ro.Observable[time.Time]) ro.Observable[time.Time]
- func AddDate(years int, months int, days int) func(destination ro.Observable[time.Time]) ro.Observable[time.Time]
- func Format(format string) func(destination ro.Observable[time.Time]) ro.Observable[string]
- func In(loc *time.Location) func(destination ro.Observable[time.Time]) ro.Observable[time.Time]
- func Parse[T ~string](layout string) func(ro.Observable[T]) ro.Observable[time.Time]
- func ParseInLocation[T ~string](layout string, loc *time.Location) func(ro.Observable[T]) ro.Observable[time.Time]
- func StartOfDay() func(ro.Observable[time.Time]) ro.Observable[time.Time]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add(d time.Duration) func(destination ro.Observable[time.Time]) ro.Observable[time.Time]
Add returns an operator that adds a fixed duration to each time value.
Example:
obs := ro.Pipe1(
ro.Just(time.Now()),
rotime.Add(2*time.Hour),
)
The observable then emits: time.Now().Add(2 * time.Hour). Play: https://go.dev/play/p/XWgGO-93YPK
Example ¶
t := time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC)
observable := ro.Pipe2(
ro.Just(t),
Add(2*time.Hour),
Format("2006-01-02 15:04:05"),
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: 2026-01-07 16:30:00 Completed
func AddDate ¶
func AddDate(years int, months int, days int) func(destination ro.Observable[time.Time]) ro.Observable[time.Time]
AddDate returns an operator that adds a date offset (years, months, days) to each time value.
Example:
obs := ro.Pipe1(
ro.Just(time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC)),
rotime.AddDate(0, 1, 0),
)
The observable then emits: time.Date(2026, time.February, 7, 14, 30, 0, 0, time.UTC).
Example ¶
t := time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC)
observable := ro.Pipe2(
ro.Just(t),
AddDate(0, 1, 0),
Format("2006-01-02 15:04:05"),
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: 2026-02-07 14:30:00 Completed
func Format ¶
func Format(format string) func(destination ro.Observable[time.Time]) ro.Observable[string]
Format returns an operator that formats each time value using the given layout.
Example:
obs := ro.Pipe1(
ro.Just(time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC)),
rotime.Format("2006-01-02 15:04:05"),
)
The observable then emits: "2026-01-07 14:30:00". Play: https://go.dev/play/p/ZOq1b1z2P1z
Example ¶
t := time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC)
observable := ro.Pipe1(
ro.Just(t),
Format("2006-01-02 15:04:05"),
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: 2026-01-07 14:30:00 Completed
func In ¶
func In(loc *time.Location) func(destination ro.Observable[time.Time]) ro.Observable[time.Time]
In returns an operator that converts each time value to the given location.
Example:
loc, _ := time.LoadLocation("Europe/Paris")
obs := ro.Pipe1(
ro.Just(time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC)),
rotime.In(loc),
)
The observable then emits: time.Date(2026, time.January, 7, 15, 30, 0, 0, loc). Play: https://go.dev/play/p/4XKgzoqfH4H
Example ¶
loc := time.FixedZone("UTC+2", 2*60*60)
t := time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC)
observable := ro.Pipe2(
ro.Just(t),
In(loc),
Format("2006-01-02 15:04:05 -0700"),
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: 2026-01-07 16:30:00 +0200 Completed
func Parse ¶
func Parse[T ~string](layout string) func(ro.Observable[T]) ro.Observable[time.Time]
Parse returns an operator that parses time strings using the given layout.
Example:
obs := ro.Pipe[string, time.Time](
ro.Just("2026-01-07 14:30:00"),
rotime.Parse("2006-01-02 15:04:05"),
)
The observable then emits: time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC). Play: https://go.dev/play/p/rsbNtg6Xr_d
Example ¶
observable := ro.Pipe2(
ro.Just("2026-01-07 14:30:00"),
Parse[string]("2006-01-02 15:04:05"),
Format("2006-01-02 15:04:05"),
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: 2026-01-07 14:30:00 Completed
func ParseInLocation ¶
func ParseInLocation[T ~string](layout string, loc *time.Location) func(ro.Observable[T]) ro.Observable[time.Time]
ParseInLocation returns an operator that parses time strings in the given location.
Example:
obs := ro.Pipe[string, time.Time](
ro.Just("2026-01-07 14:30:00"),
rotime.ParseInLocation("2006-01-02 15:04:05", time.UTC),
)
The observable then emits: time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC).
Example ¶
loc := time.FixedZone("UTC+5", 5*60*60)
observable := ro.Pipe2(
ro.Just("2026-01-07 14:30:00"),
ParseInLocation[string]("2006-01-02 15:04:05", loc),
Format("2006-01-02 15:04:05 -0700"),
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: 2026-01-07 14:30:00 +0500 Completed
func StartOfDay ¶
func StartOfDay() func(ro.Observable[time.Time]) ro.Observable[time.Time]
StartOfDay returns an operator that truncates each time value to the start of its day.
Example:
obs := ro.Pipe1(
ro.Just(time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC)),
rotime.StartOfDay(),
)
The observable then emits: time.Date(2026, time.January, 7, 0, 0, 0, 0, time.UTC). Play: https://go.dev/play/p/Rp_5REv3dMK
Example ¶
t := time.Date(2026, time.January, 7, 14, 30, 45, 0, time.UTC)
observable := ro.Pipe2(
ro.Just(t),
StartOfDay(),
Format("2006-01-02 15:04:05"),
)
subscription := observable.Subscribe(ro.PrintObserver[string]())
defer subscription.Unsubscribe()
Output: Next: 2026-01-07 00:00:00 Completed
Types ¶
This section is empty.