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

Add parsing options, including option to skip automatic date parsing #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sebastien-rosset
Copy link

To support arbitrary date layout parsing, one approach would be to define a custom "parsetime" function, which would take a date/time layout as a parameter, with the same format as time.Parse():

	functions := map[string]govaluate.ExpressionFunction{
		"parsetime": func(args ...interface{}) (interface{}, error) {
			return time.Parse(args[0].(string), args[1].(string))
		},
	}

With the above function, it would be possible to evaluate the following expression:

parsetime('Mon Jan 2 15:04:05 2006', [ts])

where "ts" is a parameter. However, since govaluate always attempts to parse strings as dates, the layout ends up being parsed as a date.

I think it would be useful to provide a method to disable automatic date parsing, this may actually provide a small performance improvement as a side effect. I can work on a PR if that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants