-
Notifications
You must be signed in to change notification settings - Fork 128
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
Include get-date helper function #262
Conversation
Signed-off-by: Zach Leslie <zach.leslie@grafana.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Would you mind adding some unit tests for this new helper? You can find examples here: https://github.com/mickael-menu/zk/blob/c21c4fc21f7fe75f05d3fc3d09e74ffed41ba2ef/internal/adapter/handlebars/handlebars_test.go#L229
Nice, thanks for the review. I'll find some time this week to add tests and address your feedback. |
Co-authored-by: Mickaël Menu <mickael.menu@gmail.com>
Signed-off-by: Zach Leslie <zach.leslie@grafana.com>
Signed-off-by: Zach Leslie <zach.leslie@grafana.com>
Signed-off-by: Zach Leslie <zach.leslie@grafana.com>
I've added a couple tests. Let me know if you'd like me to drop the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a couple tests. Let me know if you'd like me to drop the
date
calls in theget-date
tests.
No that's great, thank you.
I think the tests are failing because the helper is using time.Now()
in the implementation, so the now
context var set in the tests is ignored.
To work around this, and after fixing my other comment to use TimeFromNatural()
, you can use an absolute date as input (e.g. {{get-date "2006-01-02T15:04:05"}}
instead of a relative one. We just need to test that TimeFromNatural()
is called, and can assume that relative dates will work as well.
// {{date (get-date "last week") "timestamp"}} | ||
func RegisterGetDate(logger util.Logger) { | ||
raymond.RegisterHelper("get-date", func(natural string) time.Time { | ||
date, err := naturaldate.Parse(natural, time.Now()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this in my first review, but you can use the helper TimeFromNatural()
(which is part of this project) instead of using directly naturaldate.Parse()
. This way it will be able to parse more formats.
Signed-off-by: Zach Leslie <zach.leslie@grafana.com>
Okay, I've updated. As a side note, I had to add |
Signed-off-by: Zach Leslie <zach.leslie@grafana.com>
4e8bfe1
to
a6ce0e3
Compare
@zalegrala Thank you for contributing this feature! I might change the names before the next release, I'll sleep on it:
|
I released a new version and renamed the date helpers. |
No description provided.