Metadata: Apply time zone estimate if date was not set manually #930

This commit is contained in:
Michael Mayer 2021-01-27 22:47:37 +01:00
parent 964cb550d9
commit 28e2e85d48
3 changed files with 29 additions and 7 deletions

View file

@ -902,12 +902,12 @@ func (m *Photo) SetTakenAt(taken, local time.Time, zone, source string) {
}
// SetTimeZone updates the time zone.
func (m *Photo) SetTimeZone(zone, source string) {
func (m *Photo) SetTimeZone(zone string) {
if zone == "" {
return
}
if SrcPriority[source] < SrcPriority[m.TakenSrc] && m.TimeZone != "" {
if SrcPriority[m.TakenSrc] >= SrcPriority[SrcManual] && m.TimeZone != "" {
return
}

View file

@ -77,13 +77,13 @@ func (m *Photo) EstimatePlace() {
m.PlaceID = recentPhoto.PlaceID
m.PhotoCountry = recentPhoto.PhotoCountry
m.PlaceSrc = SrcEstimate
m.SetTimeZone(recentPhoto.TimeZone, recentPhoto.TakenSrc)
m.SetTimeZone(recentPhoto.TimeZone)
log.Debugf("photo: approximate position of %s is %s (id %s)", m, txt.Quote(m.CountryName()), recentPhoto.PlaceID)
} else if recentPhoto.HasCountry() {
m.PhotoCountry = recentPhoto.PhotoCountry
m.PlaceSrc = SrcEstimate
m.SetTimeZone(recentPhoto.TimeZone, recentPhoto.TakenSrc)
m.SetTimeZone(recentPhoto.TimeZone)
log.Debugf("photo: probable country for %s is %s", m, txt.Quote(m.CountryName()))
} else {

View file

@ -653,7 +653,7 @@ func TestPhoto_SetTimeZone(t *testing.T) {
assert.Equal(t, takenAt, m.TakenAt)
assert.Equal(t, takenAtLocal, m.TakenAtLocal)
m.SetTimeZone(zone, SrcAuto)
m.SetTimeZone(zone)
assert.Equal(t, takenAt, m.TakenAt)
assert.Equal(t, m.GetTakenAtLocal(), m.TakenAtLocal)
@ -671,7 +671,7 @@ func TestPhoto_SetTimeZone(t *testing.T) {
assert.Equal(t, takenAtLocal, m.TakenAtLocal)
assert.Equal(t, "", m.TimeZone)
m.SetTimeZone(zone, SrcAuto)
m.SetTimeZone(zone)
assert.Equal(t, m.GetTakenAt(), m.TakenAt)
assert.Equal(t, takenAtLocal, m.TakenAtLocal)
@ -691,11 +691,33 @@ func TestPhoto_SetTimeZone(t *testing.T) {
assert.Equal(t, takenAtLocal, m.TakenAtLocal)
assert.Equal(t, "Europe/Berlin", m.TimeZone)
m.SetTimeZone(zone, SrcAuto)
m.SetTimeZone(zone)
assert.Equal(t, m.GetTakenAt(), m.TakenAt)
assert.Equal(t, takenAtLocal, m.TakenAtLocal)
})
t.Run("manual", func(t *testing.T) {
m := PhotoFixtures.Get("Photo12")
m.TimeZone = "Europe/Berlin"
m.TakenAt = m.GetTakenAt()
m.TakenSrc = SrcManual
zone := "America/New_York"
takenAt := m.TakenAt
takenAtLocal := m.TakenAtLocal
assert.Equal(t, takenAt, m.TakenAt)
assert.Equal(t, takenAtLocal, m.TakenAtLocal)
assert.Equal(t, "Europe/Berlin", m.TimeZone)
m.SetTimeZone(zone)
assert.Equal(t, takenAt, m.TakenAt)
assert.Equal(t, takenAtLocal, m.TakenAtLocal)
assert.Equal(t, "Europe/Berlin", m.TimeZone)
})
}
func TestPhoto_SetCoordinates(t *testing.T) {