parseTimeValue parses a timestamp string, trying RFC3339 first, then relative expressions.
(value string)
| 2304 | |
| 2305 | // parseTimeValue parses a timestamp string, trying RFC3339 first, then relative expressions. |
| 2306 | func parseTimeValue(value string) (time.Time, error) { |
| 2307 | // Try RFC3339Nano first (existing behavior) |
| 2308 | if t, err := time.Parse(time.RFC3339Nano, value); err == nil { |
| 2309 | return t, nil |
| 2310 | } |
| 2311 | |
| 2312 | // Try RFC3339 (without nanoseconds) |
| 2313 | if t, err := time.Parse(time.RFC3339, value); err == nil { |
| 2314 | return t, nil |
| 2315 | } |
| 2316 | |
| 2317 | // Fall back to dateparser for relative expressions |
| 2318 | cfg := &dateparser.Configuration{ |
| 2319 | CurrentTime: time.Now().UTC(), |
| 2320 | } |
| 2321 | result, err := dateparser.Parse(cfg, value) |
| 2322 | if err != nil { |
| 2323 | return time.Time{}, fmt.Errorf("invalid timestamp (expected RFC3339 or relative time like '5 minutes ago'): %s", value) |
| 2324 | } |
| 2325 | if result.Time.IsZero() { |
| 2326 | return time.Time{}, fmt.Errorf("could not parse time: %s", value) |
| 2327 | } |
| 2328 | return result.Time.UTC(), nil |
| 2329 | } |
| 2330 | |
| 2331 | // FileControl handles file control operations, specifically PRAGMA commands for time travel. |
| 2332 | func (f *VFSFile) FileControl(op int, pragmaName string, pragmaValue *string) (*string, error) { |
no test coverage detected