Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

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

Open
sebastien-rosset wants to merge 1 commit into
Knetic:masterfrom
CiscoM31:master
Open

Add parsing options, including option to skip automatic date parsing#87
sebastien-rosset wants to merge 1 commit into
Knetic:masterfrom
CiscoM31:master

Conversation

@sebastien-rosset
Copy link
Copy Markdown

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants