Metadata: Remove time zone if taken date is from file name #930
This commit is contained in:
parent
67259fbca6
commit
e175251783
2 changed files with 24 additions and 0 deletions
|
@ -857,6 +857,11 @@ func (m *Photo) SetTakenAt(taken, local time.Time, zone, source string) {
|
|||
return
|
||||
}
|
||||
|
||||
// Remove time zone if time was extracted from file name.
|
||||
if source == SrcName {
|
||||
zone = ""
|
||||
}
|
||||
|
||||
// Round times to avoid jitter.
|
||||
taken = taken.Round(time.Second).UTC()
|
||||
|
||||
|
|
|
@ -553,6 +553,25 @@ func TestPhoto_SetTakenAt(t *testing.T) {
|
|||
time.Date(2019, 12, 11, 9, 7, 18, 0, time.UTC), "", SrcAuto)
|
||||
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
||||
})
|
||||
t.Run("from name", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo15")
|
||||
m.TimeZone = ""
|
||||
m.TakenSrc = SrcAuto
|
||||
|
||||
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
||||
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAtLocal)
|
||||
assert.Equal(t, "", m.TimeZone)
|
||||
assert.Equal(t, SrcAuto, m.TakenSrc)
|
||||
|
||||
m.SetTakenAt(time.Date(2011, 12, 11, 9, 7, 18, 0, time.UTC),
|
||||
time.Date(2019, 11, 11, 10, 7, 18, 0, time.UTC), "America/New_York", SrcName)
|
||||
|
||||
assert.Equal(t, "", m.TimeZone)
|
||||
assert.Equal(t, SrcName, m.TakenSrc)
|
||||
|
||||
assert.Equal(t, time.Date(2011, 12, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
||||
assert.Equal(t, time.Date(2019, 11, 11, 10, 7, 18, 0, time.UTC), m.TakenAtLocal)
|
||||
})
|
||||
t.Run("success", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo15")
|
||||
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
||||
|
|
Loading…
Reference in a new issue