GetSendTime parses the raw SendTime string into a *time.Time. For timezone-naive formats, the time is interpreted in the given location. For RFC3339 (which includes an offset), the embedded offset is used.
(location *time.Location)
| 24 | // For timezone-naive formats, the time is interpreted in the given location. |
| 25 | // For RFC3339 (which includes an offset), the embedded offset is used. |
| 26 | func (input *BulkMessage) GetSendTime(location *time.Location) *time.Time { |
| 27 | raw := strings.TrimSpace(input.SendTime) |
| 28 | if raw == "" { |
| 29 | return nil |
| 30 | } |
| 31 | |
| 32 | if location == nil { |
| 33 | location = time.UTC |
| 34 | } |
| 35 | |
| 36 | // RFC3339 already contains timezone offset, parse without location |
| 37 | if t, err := time.Parse(time.RFC3339, raw); err == nil { |
| 38 | utc := t.UTC() |
| 39 | return &utc |
| 40 | } |
| 41 | |
| 42 | // Naive formats: interpret in the user's location |
| 43 | naiveFormats := []string{ |
| 44 | "2006-01-02T15:04:05", |
| 45 | "2006-01-02 15:04:05", |
| 46 | } |
| 47 | |
| 48 | for _, format := range naiveFormats { |
| 49 | if t, err := time.ParseInLocation(format, raw, location); err == nil { |
| 50 | utc := t.UTC() |
| 51 | return &utc |
| 52 | } |
| 53 | } |
| 54 | return nil |
| 55 | } |
| 56 | |
| 57 | // Sanitize sets defaults to BulkMessage |
| 58 | func (input *BulkMessage) Sanitize() *BulkMessage { |
no outgoing calls
no test coverage detected