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

Function ParseDTime

postgres/parser/sem/tree/datum.go:863–884  ·  view source on GitHub ↗

ParseDTime parses and returns the *DTime Datum value represented by the provided string, or an error if parsing is unsuccessful. The dependsOnContext return value indicates if we had to consult the ParseTimeContext (either for the time or the local timezone).

(
	ctx ParseTimeContext, s string, precision time.Duration,
)

Source from the content-addressed store, hash-verified

861// The dependsOnContext return value indicates if we had to consult the
862// ParseTimeContext (either for the time or the local timezone).
863func ParseDTime(
864 ctx ParseTimeContext, s string, precision time.Duration,
865) (_ *DTime, dependsOnContext bool, _ error) {
866 now := relativeParseTime(ctx)
867
868 // Special case on 24:00 and 24:00:00 as the parser
869 // does not handle these correctly.
870 if DTimeMaxTimeRegex.MatchString(s) {
871 return MakeDTime(timeofday.Time2400), false, nil
872 }
873
874 if strings.HasPrefix(s, LibPQTimePrefix) {
875 s = "1970-01-01" + s[len(LibPQTimePrefix):]
876 }
877
878 t, dependsOnContext, err := pgdate.ParseTimeWithoutTimezone(now, pgdate.ParseModeYMD, s)
879 if err != nil {
880 // Build our own error message to avoid exposing the dummy date.
881 return nil, false, makeParseError(s, types.Time, nil)
882 }
883 return MakeDTime(timeofday.FromTime(t).Round(precision)), dependsOnContext, nil
884}
885
886// ResolvedType implements the TypedExpr interface.
887func (*DTime) ResolvedType() *types.T {

Callers 2

time.goFile · 0.92
ParseAndRequireStringFunction · 0.85

Calls 6

ParseTimeWithoutTimezoneFunction · 0.92
FromTimeFunction · 0.92
relativeParseTimeFunction · 0.85
MakeDTimeFunction · 0.85
makeParseErrorFunction · 0.85
RoundMethod · 0.45

Tested by

no test coverage detected