Metadata: Ignore date string defaults caused by software errors #3229
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
2bf6b2a7f6
commit
96ea732637
|
@ -60,8 +60,8 @@ func DateTime(s, timeZone string) (t time.Time) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Empty time string?
|
// Ignore defaults.
|
||||||
if EmptyTime(s) {
|
if DateTimeDefault(s) {
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
func Empty(s string) bool {
|
func Empty(s string) bool {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return true
|
return true
|
||||||
} else if s = strings.Trim(s, "%* "); s == "" || s == "0" || s == "-1" || EmptyTime(s) {
|
} else if s = strings.Trim(s, "%* "); s == "" || s == "0" || s == "-1" || DateTimeDefault(s) {
|
||||||
return true
|
return true
|
||||||
} else if s = strings.ToLower(s); s == "nil" || s == "null" || s == "nan" {
|
} else if s = strings.ToLower(s); s == "nil" || s == "null" || s == "nan" {
|
||||||
return true
|
return true
|
||||||
|
@ -22,10 +22,12 @@ func NotEmpty(s string) bool {
|
||||||
return !Empty(s)
|
return !Empty(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmptyTime tests if the string is empty or matches an unknown time pattern.
|
// EmptyDateTime tests if the string is empty or matches an unknown time pattern.
|
||||||
func EmptyTime(s string) bool {
|
func EmptyDateTime(s string) bool {
|
||||||
switch s {
|
switch s {
|
||||||
case "":
|
case "", "-", ":", "z", "zz", "Z", "nil", "null", "none", "nan", "NaN":
|
||||||
|
return true
|
||||||
|
case "0", "00", "0000", "0000:00:00", "00:00:00", "0000-00-00", "00-00-00":
|
||||||
return true
|
return true
|
||||||
case "0000:00:00 00:00:00", "0000-00-00 00-00-00", "0000-00-00 00:00:00":
|
case "0000:00:00 00:00:00", "0000-00-00 00-00-00", "0000-00-00 00:00:00":
|
||||||
return true
|
return true
|
||||||
|
@ -35,3 +37,20 @@ func EmptyTime(s string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DateTimeDefault tests if the datetime string is not empty and not a default value.
|
||||||
|
func DateTimeDefault(s string) bool {
|
||||||
|
switch s {
|
||||||
|
case "1970-01-01", "1970-01-01 00:00:00":
|
||||||
|
// Unix epoch.
|
||||||
|
return true
|
||||||
|
case "1980-01-01", "1980-01-01 00:00:00":
|
||||||
|
// Common default.
|
||||||
|
return true
|
||||||
|
case "2002:12:08 12:00:00":
|
||||||
|
// Android Bug: https://issuetracker.google.com/issues/36967504
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return EmptyDateTime(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -102,20 +102,77 @@ func TestNotEmpty(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyTime(t *testing.T) {
|
func TestEmptyDateTime(t *testing.T) {
|
||||||
t.Run("EmptyString", func(t *testing.T) {
|
t.Run("Empty", func(t *testing.T) {
|
||||||
assert.True(t, EmptyTime(""))
|
assert.True(t, EmptyDateTime(""))
|
||||||
|
})
|
||||||
|
t.Run("0", func(t *testing.T) {
|
||||||
|
assert.True(t, EmptyDateTime("0"))
|
||||||
|
})
|
||||||
|
t.Run("00-00-00", func(t *testing.T) {
|
||||||
|
assert.True(t, EmptyDateTime("00-00-00"))
|
||||||
|
})
|
||||||
|
t.Run("0000-00-00", func(t *testing.T) {
|
||||||
|
assert.True(t, EmptyDateTime("0000-00-00"))
|
||||||
|
})
|
||||||
|
t.Run("00:00:00", func(t *testing.T) {
|
||||||
|
assert.True(t, EmptyDateTime("00:00:00"))
|
||||||
|
})
|
||||||
|
t.Run("0000:00:00", func(t *testing.T) {
|
||||||
|
assert.True(t, EmptyDateTime("0000:00:00"))
|
||||||
})
|
})
|
||||||
t.Run("0000-00-00 00-00-00", func(t *testing.T) {
|
t.Run("0000-00-00 00-00-00", func(t *testing.T) {
|
||||||
assert.True(t, EmptyTime("0000-00-00 00-00-00"))
|
assert.True(t, EmptyDateTime("0000-00-00 00-00-00"))
|
||||||
})
|
})
|
||||||
t.Run("0000:00:00 00:00:00", func(t *testing.T) {
|
t.Run("0000:00:00 00:00:00", func(t *testing.T) {
|
||||||
assert.True(t, EmptyTime("0000:00:00 00:00:00"))
|
assert.True(t, EmptyDateTime("0000:00:00 00:00:00"))
|
||||||
})
|
})
|
||||||
t.Run("0000-00-00 00:00:00", func(t *testing.T) {
|
t.Run("0000-00-00 00:00:00", func(t *testing.T) {
|
||||||
assert.True(t, EmptyTime("0000-00-00 00:00:00"))
|
assert.True(t, EmptyDateTime("0000-00-00 00:00:00"))
|
||||||
})
|
})
|
||||||
t.Run("0001-01-01 00:00:00 +0000 UTC", func(t *testing.T) {
|
t.Run("0001-01-01 00:00:00 +0000 UTC", func(t *testing.T) {
|
||||||
assert.True(t, EmptyTime("0001-01-01 00:00:00 +0000 UTC"))
|
assert.True(t, EmptyDateTime("0001-01-01 00:00:00 +0000 UTC"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDateTimeDefault(t *testing.T) {
|
||||||
|
t.Run("Empty", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault(""))
|
||||||
|
})
|
||||||
|
t.Run("nil", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("nil"))
|
||||||
|
})
|
||||||
|
t.Run("2002", func(t *testing.T) {
|
||||||
|
assert.False(t, DateTimeDefault("2002"))
|
||||||
|
})
|
||||||
|
t.Run("1970-01-01", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("1970-01-01"))
|
||||||
|
})
|
||||||
|
t.Run("1980-01-01", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("1980-01-01"))
|
||||||
|
})
|
||||||
|
t.Run("1970-01-01 00:00:00", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("1970-01-01 00:00:00"))
|
||||||
|
})
|
||||||
|
t.Run("1980-01-01 00:00:00", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("1980-01-01 00:00:00"))
|
||||||
|
})
|
||||||
|
t.Run("2002:12:08 12:00:00", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("2002:12:08 12:00:00"))
|
||||||
|
})
|
||||||
|
t.Run("0000-00-00", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("0000-00-00"))
|
||||||
|
})
|
||||||
|
t.Run("0000-00-00 00-00-00", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("0000-00-00 00-00-00"))
|
||||||
|
})
|
||||||
|
t.Run("0000:00:00 00:00:00", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("0000:00:00 00:00:00"))
|
||||||
|
})
|
||||||
|
t.Run("0000-00-00 00:00:00", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("0000-00-00 00:00:00"))
|
||||||
|
})
|
||||||
|
t.Run("0001-01-01 00:00:00 +0000 UTC", func(t *testing.T) {
|
||||||
|
assert.True(t, DateTimeDefault("0001-01-01 00:00:00 +0000 UTC"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue