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

fix parsing timestamp strings #162

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

Conversation

toinebeg
Copy link

@toinebeg toinebeg commented Aug 30, 2021

Fixes #161

By defautl dayjs parse strings as isoDate. If the string only contain
digits, we can assume it is a timestamp and convert it to number before
giving it to dayjs for parsing.

by defautl dayjs parse strings as isoDate. If the string only contain
digits, we can assume it is a timestamp and convert it to number
giving it to dayjs for parsing.
if (timeString === null) {
return timeString;
}
if (!isNaN(+timeString)) {
Copy link
Author

@toinebeg toinebeg Aug 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explicit conversion to number here is only to appease typescript who want a number in isNaN, it's not needed in js.
We could add a tsignore comment instead.

@toinebeg
Copy link
Author

toinebeg commented Aug 30, 2021

Looking more into it, it does conflict with the dayjs case where you give the string '2005' and it return january 1st 2005. 🤔

@marcusolsson
Copy link
Contributor

marcusolsson commented Sep 3, 2021

Hey, and thanks for taking a look at this! I believe had something similar in earlier version of the plugin, i.e. a more intelligent time format detection. Unfortunately, some users reported issues like the one you noticed as well, so I decided to simplify it.

Instead of detecting the format, I'm thinking maybe we should look into defining the format explicitly. Do you have any thoughts on #165? Specifically, if you think it would solve your use case?

@toinebeg
Copy link
Author

toinebeg commented Sep 7, 2021

Yeah it look like the same kind of problem.
I will have a look at it but it's a little bit more involved than my current proposition. I will need some time to setup a proper dev env, unit tests won't suffice and I don't know grafana plugin developement.

I feel you could have a "custom time" type that open a modal with the all the knobs to set it up to your needs. I don't know if the grafana ui tools allow this kind of stuff.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


ABegon seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

@TristanVisnar TristanVisnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an issue this request fixes, I would love it to be approved.

I look at a code and I doesn't see any issues. It is a good quick fix.

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

Successfully merging this pull request may close these issues.

Troubles with parsing strings containing timestamps as Time
4 participants