(s string, itm types.IntervalTypeMetadata)
| 1189 | } |
| 1190 | |
| 1191 | func parseDInterval(s string, itm types.IntervalTypeMetadata) (*DInterval, error) { |
| 1192 | // At this time the only supported interval formats are: |
| 1193 | // - SQL standard. |
| 1194 | // - Postgres compatible. |
| 1195 | // - iso8601 format (with designators only), see interval.go for |
| 1196 | // sources of documentation. |
| 1197 | // - Golang time.parseDuration compatible. |
| 1198 | |
| 1199 | // If it's a blank string, exit early. |
| 1200 | if len(s) == 0 { |
| 1201 | return nil, makeParseError(s, types.Interval, nil) |
| 1202 | } |
| 1203 | if s[0] == 'P' { |
| 1204 | // If it has a leading P we're most likely working with an iso8601 |
| 1205 | // interval. |
| 1206 | dur, err := iso8601ToDuration(s) |
| 1207 | if err != nil { |
| 1208 | return nil, makeParseError(s, types.Interval, err) |
| 1209 | } |
| 1210 | return &DInterval{Duration: dur}, nil |
| 1211 | } |
| 1212 | if strings.IndexFunc(s, unicode.IsLetter) == -1 { |
| 1213 | // If it has no letter, then we're most likely working with a SQL standard |
| 1214 | // interval, as both postgres and golang have letter(s) and iso8601 has been tested. |
| 1215 | dur, err := sqlStdToDuration(s, itm) |
| 1216 | if err != nil { |
| 1217 | return nil, makeParseError(s, types.Interval, err) |
| 1218 | } |
| 1219 | return &DInterval{Duration: dur}, nil |
| 1220 | } |
| 1221 | |
| 1222 | // We're either a postgres string or a Go duration. |
| 1223 | // Our postgres syntax parser also supports golang, so just use that for both. |
| 1224 | dur, err := parseDuration(s, itm) |
| 1225 | if err != nil { |
| 1226 | return nil, makeParseError(s, types.Interval, err) |
| 1227 | } |
| 1228 | return &DInterval{Duration: dur}, nil |
| 1229 | } |
| 1230 | |
| 1231 | // ResolvedType implements the TypedExpr interface. |
| 1232 | func (*DInterval) ResolvedType() *types.T { |
no test coverage detected