Skip to content

Commit 25c12d3

Browse files
authored
feat(sdk): helpers for date and time (#252)
1 parent c8ca8d9 commit 25c12d3

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

datetime/datetime.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
// Date represents a date without time using RFC3339 date format (YYYY-MM-DD).
1010
type Date struct{ time.Time }
1111

12+
// NewDate constructs a [Date] from a calendar date in UTC.
13+
func NewDate(year int, month time.Month, day int) Date {
14+
return Date{time.Date(year, month, day, 0, 0, 0, 0, time.UTC)}
15+
}
16+
1217
// String returns the date formatted as YYYY-MM-DD.
1318
func (d Date) String() string {
1419
return d.Format(time.DateOnly)
@@ -38,6 +43,11 @@ func (d Date) MarshalJSON() ([]byte, error) {
3843
// Time represents a time of day using RFC3339 time format (HH:MM:SS).
3944
type Time struct{ time.Time }
4045

46+
// NewTime constructs a [Time] from a clock time in UTC.
47+
func NewTime(hour, min, sec int) Time {
48+
return Time{time.Date(0, 0, 0, hour, min, sec, 0, time.UTC)}
49+
}
50+
4151
// String returns the time formatted as HH:MM:SS.
4252
func (t Time) String() string {
4353
return t.Format(time.TimeOnly)

0 commit comments

Comments
 (0)