Metadata: When parsing dates from exiftool, remap year 0 to 1 (#2508)
Year 0 is frequently used in exiftool but is not accepted in the Go time package. time package uses year 1 for "zero" dates instead. Therefore, remap year 0 from exiftool to year 1.
This commit is contained in:
parent
da61515c4a
commit
9a699f234d
2 changed files with 11 additions and 1 deletions
|
@ -132,8 +132,15 @@ func DateTime(s, timeZone string) (t time.Time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create rounded timestamp from parsed input values.
|
// Create rounded timestamp from parsed input values.
|
||||||
|
// Year 0 is treated separately as it has a special meaning in exiftool. Golang
|
||||||
|
// does not seem to accept value 0 for the year, but considers a date to be
|
||||||
|
// "zero" when year is 1.
|
||||||
|
year := IntVal(m[v["year"]], 0, YearMax, time.Now().Year())
|
||||||
|
if year == 0 {
|
||||||
|
year = 1
|
||||||
|
}
|
||||||
t = time.Date(
|
t = time.Date(
|
||||||
IntVal(m[v["year"]], 1, YearMax, time.Now().Year()),
|
year,
|
||||||
time.Month(IntVal(m[v["month"]], 1, 12, 1)),
|
time.Month(IntVal(m[v["month"]], 1, 12, 1)),
|
||||||
IntVal(m[v["day"]], 1, 31, 1),
|
IntVal(m[v["day"]], 1, 31, 1),
|
||||||
IntVal(m[v["h"]], 0, 23, 0),
|
IntVal(m[v["h"]], 0, 23, 0),
|
||||||
|
|
|
@ -119,6 +119,9 @@ func TestDateTime(t *testing.T) {
|
||||||
assert.Equal(t, "2020-10-17 17:48:24.9508123 +0000 UTC", result.UTC().String())
|
assert.Equal(t, "2020-10-17 17:48:24.9508123 +0000 UTC", result.UTC().String())
|
||||||
assert.Equal(t, "2020-10-17 17:48:24.9508123", result.Format("2006-01-02 15:04:05.999999999"))
|
assert.Equal(t, "2020-10-17 17:48:24.9508123", result.Format("2006-01-02 15:04:05.999999999"))
|
||||||
})
|
})
|
||||||
|
t.Run("UTC/0000:00:00 00:00:00", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTime("0000:00:00 00:00:00", "UTC").IsZero())
|
||||||
|
})
|
||||||
t.Run("2022-09-03T17:48:26-07:00", func(t *testing.T) {
|
t.Run("2022-09-03T17:48:26-07:00", func(t *testing.T) {
|
||||||
result := DateTime("2022-09-03T17:48:26-07:00", "")
|
result := DateTime("2022-09-03T17:48:26-07:00", "")
|
||||||
assert.Equal(t, "2022-09-04 00:48:26 +0000 UTC", result.UTC().String())
|
assert.Equal(t, "2022-09-04 00:48:26 +0000 UTC", result.UTC().String())
|
||||||
|
|
Loading…
Reference in a new issue