Skip to content

Commit

Permalink
Add String representations for temporal types (#561)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Cathcart <stephen.cathcart@neotechnology.com>
  • Loading branch information
robsdedude and StephenCathcart authored Jan 8, 2024
1 parent a3fa881 commit d7aed10
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 311 deletions.
30 changes: 30 additions & 0 deletions neo4j/dbtype/temporal.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,55 @@ type (
)

// Time casts LocalDateTime to time.Time
//
// Note that the resulting time.Time will have its location set to time.Local.
// From the DBMS's perspective, however, a LocalDateTime is considered to not have any timezone information.
func (t LocalDateTime) Time() time.Time {
return time.Time(t)
}

// String returns the string representation of this LocalDateTime in ISO-8601 compliant form:
// `YYYY-MM-DDThh:mm:ss.nnnnnnnnn`.
func (t LocalDateTime) String() string {
return t.Time().Format("2006-01-02T15:04:05.999999999")
}

// Time casts LocalTime to time.Time
//
// Note that the resulting time.Time will have its location set to time.Local.
// From the DBMS's perspective, however, a LocalTime is considered to not have any timezone information.
func (t LocalTime) Time() time.Time {
return time.Time(t)
}

// String returns the string representation of this LocalTime in ISO-8601 compliant form:
// `hh:mm:ss.nnnnnnnnn`.
func (t LocalTime) String() string {
return t.Time().Format("15:04:05.999999999")
}

// Time casts Date to time.Time
func (t Date) Time() time.Time {
return time.Time(t)
}

// String returns the string representation of this Date in ISO-8601 compliant form:
// `YYYY-MM-DD`.
func (t Date) String() string {
return t.Time().Format("2006-01-02")
}

// Time casts Time to time.Time
func (t Time) Time() time.Time {
return time.Time(t)
}

// String returns the string representation of this Time in ISO-8601 compliant form:
// `hh:mm:ss.nnnnnnnnn±Z/hh:mm`.
func (t Time) String() string {
return t.Time().Format("15:04:05.999999999Z07:00")
}

// Duration represents temporal amount containing months, days, seconds and nanoseconds.
// Supports longer durations than time.Duration
type Duration struct {
Expand Down
Loading

0 comments on commit d7aed10

Please sign in to comment.