Backend: Add validation for valid dates in setTakenAt()
This commit is contained in:
parent
6e2849fba2
commit
7e7b53590a
2 changed files with 10 additions and 1 deletions
|
@ -817,7 +817,7 @@ func (m *Photo) SetDescription(desc, source string) {
|
|||
|
||||
// SetTakenAt changes the photo date if not empty and from the same source.
|
||||
func (m *Photo) SetTakenAt(taken, local time.Time, zone, source string) {
|
||||
if taken.IsZero() || taken.Year() < 1000 {
|
||||
if taken.IsZero() || taken.Year() < 1000 || taken.Year() > txt.YearMax {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -557,6 +557,15 @@ func TestPhoto_SetTakenAt(t *testing.T) {
|
|||
assert.Equal(t, time.Date(2019, 12, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
||||
assert.Equal(t, time.Date(2019, 12, 11, 10, 7, 18, 0, time.UTC), m.TakenAtLocal)
|
||||
})
|
||||
t.Run("time > max year", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo15")
|
||||
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)
|
||||
m.SetTakenAt(time.Date(2123, 12, 11, 9, 7, 18, 0, time.UTC),
|
||||
time.Date(2123, 12, 11, 10, 7, 18, 0, time.UTC), "", "location")
|
||||
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)
|
||||
})
|
||||
t.Run("success with empty takenAtLocal", 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