snmp_exporter icon indicating copy to clipboard operation
snmp_exporter copied to clipboard

Add type to parse date and time

Open phibos opened this issue 1 year ago • 7 comments

I have added a new type ParseDateAndTime to parse timestamps from DisplayString and report it as unix timestamp.

Please have a look and report if something is missing.

This fixes #1232

For now it uses the go time.Parse() function. If we want to swap it out there are some packages.

  • https://github.com/golang-module/carbon
  • https://github.com/jinzhu/now

What do you think?

phibos avatar Aug 13 '24 11:08 phibos

Nice, I like it so far. I haven't had a chance to evaluate the parser libraries.

SuperQ avatar Aug 16 '24 13:08 SuperQ

I personally prefer strftime style parsing. I sent a couple of PRs to https://github.com/lestrrat-go/strftime to see if the maintainer is still active.

What do you think @bastischubert? Do you prefer Go or strftime style date parsing syntax?

SuperQ avatar Aug 18 '24 08:08 SuperQ

I'm not in favor of any specific parsing syntax - whatever works and doesn't introduce unnecessary complexity if ok (-:

bastischubert avatar Aug 18 '24 13:08 bastischubert

@SuperQ did you find the time to have a look at the time parser libraries? Do I have to change something or can this PR be merged?

phibos avatar Aug 27 '24 11:08 phibos

I looked over https://github.com/lestrrat-go/strftime, it seems reasonable. I'm fine with either library, but I live a slight preference for strftime.

SuperQ avatar Aug 27 '24 12:08 SuperQ

Thanks for you reply. I will update the PR and use the strftime functions to parse the date and time. But before I change the code. Do you see any reason why we should provide an config option to specify the format type?

Example:

datetime_format_type: go | strftime

phibos avatar Aug 27 '24 12:08 phibos

Adding multiple parser options is probably a bit more complexity than necessary. I'd like to start with one parser and see how things evolve.

SuperQ avatar Aug 27 '24 13:08 SuperQ

Had to use https://github.com/itchyny/timefmt-go instead of https://github.com/lestrrat-go/strftime because it does not support parsing lestrrat-go/strftime#22

phibos avatar Aug 29 '24 15:08 phibos