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

Names and addresses are parsed without an error #98

Open
yonivy opened this issue Nov 15, 2019 · 2 comments · May be fixed by #159
Open

Names and addresses are parsed without an error #98

yonivy opened this issue Nov 15, 2019 · 2 comments · May be fixed by #159

Comments

@yonivy
Copy link

yonivy commented Nov 15, 2019

  1. Some name formats are successfully parsed as a valid date
  2. Some address formats are successfully parsed as a valid date

An working example can be found here. I also copied it here for reference.

package main

import (
	"fmt"
	"time"
	
	"github.com/araddon/dateparse"
)

func main() {	
	inputs := []string{
		// names
		"Wayne, Bruce",
		
		// addresses
		"Miami, Florida",
		
		// for some bizarre reason this fails to parse (that's good)
		"Doe, John",
	}
	
	for _, i := range inputs {
		dt, err := dateparse.ParseIn(i, time.FixedZone("", 0))
		fmt.Printf("input: %v\n", i)
		fmt.Printf("date:  %v\n", dt)
		fmt.Printf("error: %v\n\n", err)
	}	
}
input: Wayne, Bruce
date:  0000-01-01 00:00:00 +0000 +0000
error: <nil>

input: Miami, Florida
date:  0000-01-01 00:00:00 +0000 +0000
error: <nil>

input: Doe, John
date:  0001-01-01 00:00:00 +0000 UTC
error: parsing time "Doe, John" as "Mon, John": cannot parse "Doe, John" as "Mon"
@phemmer
Copy link

phemmer commented Dec 20, 2019

I have a somewhat similar issue which I think is related to this, in that if a string is only partially parsed, no error is emitted.

For example, I tried to parse 2019-09-01_01:00:00 (using ParseStrict), which ended up getting parsed as 2019-01-01 00:00:00 +0000 (only the year got parsed).
If there were unknown data in the string, I would have expected some sort of error to be thrown. As it is there is no way to tell if the date was properly recognized, which is important when handling human input.

@uditrana
Copy link

Pretty much any string that satisfies the regex ^(\w+)(,\w+)+$gets parsed as a valid date. We are having to exempt out that regex to use this library.

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