FormatSQLTimestamp - returns the a string representation of the timestamp as used in S3 Select
(t time.Time)
| 52 | // FormatSQLTimestamp - returns the a string representation of the |
| 53 | // timestamp as used in S3 Select |
| 54 | func FormatSQLTimestamp(t time.Time) string { |
| 55 | _, zoneOffset := t.Zone() |
| 56 | hasZone := zoneOffset != 0 |
| 57 | hasFracSecond := t.Nanosecond() != 0 |
| 58 | hasSecond := t.Second() != 0 |
| 59 | hasTime := t.Hour() != 0 || t.Minute() != 0 |
| 60 | hasDay := t.Day() != 1 |
| 61 | hasMonth := t.Month() != 1 |
| 62 | |
| 63 | switch { |
| 64 | case hasFracSecond: |
| 65 | return t.Format(layoutNanosecond) |
| 66 | case hasSecond: |
| 67 | return t.Format(layoutSecond) |
| 68 | case hasTime || hasZone: |
| 69 | return t.Format(layoutMinute) |
| 70 | case hasDay: |
| 71 | return t.Format(layoutDay) |
| 72 | case hasMonth: |
| 73 | return t.Format(layoutMonth) |
| 74 | default: |
| 75 | return t.Format(layoutYear) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | const ( |
| 80 | timePartYear = "YEAR" |