From ccdd048c47ff1c3d10c69484329d01af31b9cf91 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Tue, 8 Dec 2020 23:20:43 +0100 Subject: [PATCH] Indexer: Ignore date in canonical file names Signed-off-by: Michael Mayer --- pkg/txt/convert.go | 7 +------ pkg/txt/convert_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/txt/convert.go b/pkg/txt/convert.go index 2bcd7adbc..f41bbaa5c 100644 --- a/pkg/txt/convert.go +++ b/pkg/txt/convert.go @@ -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 { diff --git a/pkg/txt/convert_test.go b/pkg/txt/convert_test.go index 61c20ffc4..13fd33ced 100644 --- a/pkg/txt/convert_test.go +++ b/pkg/txt/convert_test.go @@ -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) {