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

Match time format #8

Open
cyucelen opened this issue Oct 6, 2019 · 10 comments · Fixed by #20
Open

Match time format #8

cyucelen opened this issue Oct 6, 2019 · 10 comments · Fixed by #20
Assignees
Labels
bug Something isn't working enhancement New feature or request Hacktoberfest Festival of open source community!

Comments

@cyucelen
Copy link
Owner

cyucelen commented Oct 6, 2019

Create a matcher which takes one of the time layouts of golang standard time library and matches them in given string.

const (
	ANSIC       = "Mon Jan _2 15:04:05 2006"
	UnixDate    = "Mon Jan _2 15:04:05 MST 2006"
	RubyDate    = "Mon Jan 02 15:04:05 -0700 2006"
	RFC822      = "02 Jan 06 15:04 MST"
	RFC822Z     = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone
	RFC850      = "Monday, 02-Jan-06 15:04:05 MST"
	RFC1123     = "Mon, 02 Jan 2006 15:04:05 MST"
	RFC1123Z    = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
	RFC3339     = "2006-01-02T15:04:05Z07:00"
	RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
	Kitchen     = "3:04PM"
	// Handy time stamps.
	Stamp      = "Jan _2 15:04:05"
	StampMilli = "Jan _2 15:04:05.000"
	StampMicro = "Jan _2 15:04:05.000000"
	StampNano  = "Jan _2 15:04:05.000000000"
)

An example:

strWithTimestamp := "Current timestamp is 2019-10-07T23:45:05Z03:00"
match := MatchTimestamp(time.RFC3339)(strWithTimestamp)
// expected match => Match{Template: "Current timestamp is %s", Patterns: []string{"2019-10-07T23:45:05Z03:00"}}

Distinct implementations can be written for each format. We can discuss to split the issue to fine grained pieces on the way with respect to complexity.

@cyucelen cyucelen added enhancement New feature or request Hacktoberfest Festival of open source community! labels Oct 6, 2019
@marco-silveira
Copy link
Contributor

Hi @cyucelen. What you're asking for is a function that given some string returns witch layout corresponds to it, or a func that converts one format to another?

@cyucelen
Copy link
Owner Author

cyucelen commented Oct 7, 2019

Hi @MarcoAntonioSilveira. I just updated the description with some detail about what are we expecting from this feature.
I suggest you to review existing matchers to have an idea about how marker works. Feel free to ask more questions.

@marco-silveira
Copy link
Contributor

@cyucelen I must pay attention to the date being valid or only match the layout without worrying about the correctness of the date? (Mon Feb 31 23:59:59 2006 with ANSIC layout would be marked in this case)

@cyucelen
Copy link
Owner Author

cyucelen commented Oct 8, 2019

You don't need to check if its a valid date or not. Just match for the layout.

Validation can be another feature for another issue and can be implemented later.

@marco-silveira
Copy link
Contributor

@cyucelen Could you assing me this issue? I'm working on it

@cyucelen
Copy link
Owner Author

cyucelen commented Oct 9, 2019

@MarcoAntonioSilveira looks like time.Stamp matches more than one layouts' parts (i.e. ANSIC, UnixDate, StampMilli, StampMicro, StampNano). I created a new branch match-timestamp and added a test for it. Take a look and lets discuss can we do something about it.

@cyucelen cyucelen added the bug Something isn't working label Oct 13, 2019
@marco-silveira
Copy link
Contributor

@cyucelen maybe we can filter those cases with regexps. The conflicts with other stamps (StampMilli, etc) looks like it's easy to solve, some time soon I will try some ideas.

But in the ANSIC and UnixDate cases, is it really a wrong match? The pattern is there. In case you do think those cases should be treated, maybe it's possible to do it with regexps to avoid matching when preceded by the abbreviations of days of the week, since these doesn't conflict with other real worlds (I guess).

What do you think?

@cyucelen
Copy link
Owner Author

Lets fix the overlap with StampMilli, StampMicro and Stampnano first. Then we can discuss ANSIC and UnixDate cases whether its a problem or not.

@cyucelen
Copy link
Owner Author

Any updates @MarcoAntonioSilveira, do you need help?

@marco-silveira
Copy link
Contributor

@cyucelen sorry, I've been really busy lately. My solution to the overlap with the other stamps was using negative lookahead to filter out the ".[0-9]" part, but golang's regexp package doesn't support negative lookaheads.

To date I couldn't think of some way to do it using regexp without including the whitespace after the layout in the match. Take a look: https://regex101.com/r/tDMEIN/1

If you have any suggestions, it would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Hacktoberfest Festival of open source community!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants