Below functions are to satisfy the Value interface Parses the string value to timestamp
(value string)
| 52 | |
| 53 | // Parses the string value to timestamp |
| 54 | func (t *timestampValue) Set(value string) error { |
| 55 | var timestamp time.Time |
| 56 | var err error |
| 57 | |
| 58 | if t.location == nil { |
| 59 | t.location = time.UTC |
| 60 | } |
| 61 | |
| 62 | if len(t.layouts) == 0 { |
| 63 | return errors.New("got nil/empty layouts slice") |
| 64 | } |
| 65 | |
| 66 | for _, layout := range t.layouts { |
| 67 | var locErr error |
| 68 | |
| 69 | timestamp, locErr = time.ParseInLocation(layout, value, t.location) |
| 70 | if locErr != nil { |
| 71 | if err == nil { |
| 72 | err = locErr |
| 73 | continue |
| 74 | } |
| 75 | |
| 76 | err = newMultiError(err, locErr) |
| 77 | continue |
| 78 | } |
| 79 | |
| 80 | err = nil |
| 81 | break |
| 82 | } |
| 83 | |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | |
| 88 | defaultTS, _ := time.ParseInLocation(time.TimeOnly, time.TimeOnly, timestamp.Location()) |
| 89 | |
| 90 | n := time.Now().In(timestamp.Location()) |
| 91 | |
| 92 | // If format is missing date (or year only), set it explicitly to current |
| 93 | if timestamp.Truncate(time.Hour*24).UnixNano() == defaultTS.Truncate(time.Hour*24).UnixNano() { |
| 94 | timestamp = time.Date( |
| 95 | n.Year(), |
| 96 | n.Month(), |
| 97 | n.Day(), |
| 98 | timestamp.Hour(), |
| 99 | timestamp.Minute(), |
| 100 | timestamp.Second(), |
| 101 | timestamp.Nanosecond(), |
| 102 | timestamp.Location(), |
| 103 | ) |
| 104 | } else if timestamp.Year() == 0 { |
| 105 | timestamp = time.Date( |
| 106 | n.Year(), |
| 107 | timestamp.Month(), |
| 108 | timestamp.Day(), |
| 109 | timestamp.Hour(), |
| 110 | timestamp.Minute(), |
| 111 | timestamp.Second(), |