dateparse icon indicating copy to clipboard operation
dateparse copied to clipboard

"1.jpg" is incorrectly matched as a date

Open reuvenharrison opened this issue 4 years ago • 2 comments

The following code prints: Matched 1.jpg as date with format 1.jpg

layout, err := dateparse.ParseFormat("1.jpg")
if err == nil {
	fmt.Printf("Matched %s as date with format %s", s, layout)
	return true
}

reuvenharrison avatar Jul 26 '20 16:07 reuvenharrison

Not sure this one is fixable or will be fixed, probably will close as wnf: https://play.golang.org/p/NY-m3OnWkKA

This really passes down to underlying go parser to determine correctness, it doesn't do a ton of additional error testing beyond validating it can parse it. Since go parser says that is a valid format, not sure this lib will attempt beyond that. open to arguments counter, but seems like an impossible chase to find invalid formats beyond that.

package main

import (
	"fmt"
	"time"
)

func main() {
	t, err := time.ParseInLocation("1.jpg", "1.jpg", time.UTC)
	fmt.Printf("hello t=%v IsZero()=%v err=%v", t, t.IsZero(), err)
}

araddon avatar Oct 01 '20 18:10 araddon

@araddon Although it's sad, but it fits the module description:

About
GoLang Parse many date strings without knowing format in advance.

Maybe you could highlight in readme, that this package isn't able to detect if the string is a date string. It just parses strings that are a date string, but you just don't know the format.

It can be used for date string detection, but not without false positives. It should be said at laud.

prochac avatar Aug 11 '23 10:08 prochac