Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"1.jpg" is incorrectly matched as a date #108

Open
reuvenharrison opened this issue Jul 26, 2020 · 2 comments · May be fixed by #159
Open

"1.jpg" is incorrectly matched as a date #108

reuvenharrison opened this issue Jul 26, 2020 · 2 comments · May be fixed by #159

Comments

@reuvenharrison
Copy link

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
}
@araddon
Copy link
Owner

araddon commented Oct 1, 2020

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)
}

@prochac
Copy link

prochac commented Aug 11, 2023

@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.

klondikedragon added a commit to itlightning/dateparse that referenced this issue Dec 12, 2023
* Don't just assume we were given one of the valid formats.
* Also consolidate the parsing states that occur after timePeriod.
* Add subtests to make it easier to see what fails.
* Additional tests for 4-char timezone names.
* Fix araddon#117
* Fix araddon#150
* Fix araddon#157
* Fix araddon#145
* Fix araddon#108
* Fix araddon#137
* Fix araddon#130
* Fix araddon#123
* Fix araddon#109
* Fix araddon#98
* Addresses bug in araddon#100 (comment)

Adds test cases to verify the following are already fixed:
* araddon#94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants