parseLastUsedString converts the textual MAX(created_at) value returned by SQLite (or any driver that surfaces the timestamp as a string) into a time.Time. Returns the zero time on parse failure.
(s string)
| 390 | // SQLite (or any driver that surfaces the timestamp as a string) into a |
| 391 | // time.Time. Returns the zero time on parse failure. |
| 392 | func parseLastUsedString(s string) time.Time { |
| 393 | if s == "" { |
| 394 | return time.Time{} |
| 395 | } |
| 396 | // GORM's SQLite driver emits Go's default time formatting. Try the formats |
| 397 | // it commonly produces, falling back to RFC3339Nano. |
| 398 | layouts := []string{ |
| 399 | "2006-01-02 15:04:05.999999999 -0700 MST", |
| 400 | "2006-01-02 15:04:05.999999999-07:00", |
| 401 | "2006-01-02 15:04:05.999999999", |
| 402 | "2006-01-02 15:04:05", |
| 403 | time.RFC3339Nano, |
| 404 | time.RFC3339, |
| 405 | } |
| 406 | for _, layout := range layouts { |
| 407 | if t, err := time.Parse(layout, s); err == nil { |
| 408 | return t |
| 409 | } |
| 410 | } |
| 411 | xlog.Warn("parseLastUsedString: unrecognised format", "value", s) |
| 412 | return time.Time{} |
| 413 | } |
| 414 | |
| 415 | // GetAllUsageBySource is the admin variant of GetUserUsageBySource. |
| 416 | // Optional filters: userID and apiKeyID. Legacy is included. |
no test coverage detected