Indexer: Ignore date in canonical file names
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
ee49073cf2
commit
ccdd048c47
2 changed files with 8 additions and 7 deletions
|
@ -8,7 +8,6 @@ import (
|
|||
)
|
||||
|
||||
var DateRegexp = regexp.MustCompile("\\D\\d{4}[\\-_]\\d{2}[\\-_]\\d{2,}")
|
||||
var DateCanonicalRegexp = regexp.MustCompile("\\D\\d{8}_\\d{6}_\\w+\\.")
|
||||
var DatePathRegexp = regexp.MustCompile("\\D\\d{4}/\\d{1,2}/?\\d*")
|
||||
var DateTimeRegexp = regexp.MustCompile("\\D\\d{4}[\\-_]\\d{2}[\\-_]\\d{2}.{1,4}\\d{2}\\D\\d{2}\\D\\d{2,}")
|
||||
var DateIntRegexp = regexp.MustCompile("\\d{1,4}")
|
||||
|
@ -53,11 +52,7 @@ func Time(s string) (result time.Time) {
|
|||
|
||||
b := []byte(s)
|
||||
|
||||
if found := DateCanonicalRegexp.Find(b); len(found) > 0 { // Is it a canonical name like "20120727_093920_97425909.jpg"?
|
||||
if date, err := time.Parse("20060102_150405", string(found[1:16])); err == nil {
|
||||
result = date.Round(time.Second).UTC()
|
||||
}
|
||||
} else if found := DateTimeRegexp.Find(b); len(found) > 0 { // Is it a date with time like "2020-01-30_09-57-18"?
|
||||
if found := DateTimeRegexp.Find(b); len(found) > 0 { // Is it a date with time like "2020-01-30_09-57-18"?
|
||||
n := DateIntRegexp.FindAll(found, -1)
|
||||
|
||||
if len(n) != 6 {
|
||||
|
|
|
@ -27,7 +27,13 @@ func TestTime(t *testing.T) {
|
|||
t.Run("/2020/1212/20130518_142022_3D657EBD.jpg", func(t *testing.T) {
|
||||
result := Time("/2020/1212/20130518_142022_3D657EBD.jpg")
|
||||
//assert.False(t, result.IsZero())
|
||||
assert.Equal(t, "2013-05-18 14:20:22 +0000 UTC", result.String())
|
||||
assert.True(t, result.IsZero())
|
||||
})
|
||||
|
||||
t.Run("20130518_142022_3D657EBD.jpg", func(t *testing.T) {
|
||||
result := Time("20130518_142022_3D657EBD.jpg")
|
||||
//assert.False(t, result.IsZero())
|
||||
assert.True(t, result.IsZero())
|
||||
})
|
||||
|
||||
t.Run("telegram_2020_01_30_09_57_18.jpg", func(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue