MCPcopy Create free account
hub / github.com/dolthub/doltgresql / MakeDateFromTime

Function MakeDateFromTime

postgres/parser/pgdate/pgdate.go:113–128  ·  view source on GitHub ↗

MakeDateFromTime creates a Date from the specified time. The timezone-relative date is used.

(t time.Time)

Source from the content-addressed store, hash-verified

111// MakeDateFromTime creates a Date from the specified time. The
112// timezone-relative date is used.
113func MakeDateFromTime(t time.Time) (Date, error) {
114 sec := t.Unix()
115 _, offset := t.Zone()
116 sec += int64(offset)
117
118 days := sec / secondsPerDay
119 if sec < 0 && sec%secondsPerDay != 0 {
120 // If days are negative AND not divisible by secondsPerDay,
121 // we need to round down.
122 // e.g. for 1969-12-30 01:00, the division will round to -1
123 // but we want -2.
124 days--
125 }
126 d, err := MakeDateFromUnixEpoch(days)
127 return d, err
128}
129
130var errDateOutOfRange = pgerror.WithCandidateCode(errors.New("date is out of range"), pgcode.DatetimeFieldOverflow)
131

Callers 3

timestampAssignmentFunction · 0.92
timestampTZAssignmentFunction · 0.92
MakeDateMethod · 0.85

Calls 1

MakeDateFromUnixEpochFunction · 0.85

Tested by

no test coverage detected