-
Notifications
You must be signed in to change notification settings - Fork 153
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
feat(date): add builtin function time to the date package to convert any timeable into datetime (#4749) #4833
Conversation
@@ -39,6 +39,35 @@ package date | |||
// ``` | |||
builtin second : (t: T) => int where T: Timeable | |||
|
|||
// time returns the datetime of a specified timeable. |
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.
// time returns the datetime of a specified timeable. | |
// time returns the time value of a specified relative duration or time. | |
// | |
// `date.time` assumes duration values are relative to `now()`. |
// time returns the datetime of a specified timeable. | ||
// | ||
// ## Parameters | ||
// - t: Timeable. It can be either time or duration |
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.
// - t: Timeable. It can be either time or duration | |
// - t: Duration or time value. |
// ``` | ||
// ### Return the time for a given relative duration |
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.
// ``` | |
// ### Return the time for a given relative duration | |
// ``` | |
// | |
// ### Return the time for a given relative duration |
// ```no_run | ||
// import "date" | ||
// | ||
// date.time(t: -1d1h1m1s1us1ns) | ||
// | ||
// // Returns 2022-06-02T20:02:19.506570999Z | ||
// ``` |
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.
- To keep this example and return value constant, define the
now
option in the example. - Add the
introduced: NEXT
metadata to tag this function with the next tagged Flux version.
// ```no_run | |
// import "date" | |
// | |
// date.time(t: -1d1h1m1s1us1ns) | |
// | |
// // Returns 2022-06-02T20:02:19.506570999Z | |
// ``` | |
// ```no_run | |
// import "date" | |
// | |
// option now = () => 2022-01-01T00:00:00Z | |
// | |
// date.time(t: -1h) | |
// | |
// // Returns 2021-12-31T23:00:00.000000000Z | |
// ``` | |
// | |
// ## Metadata | |
// introduced: NEXT | |
// |
This feature addition now addresses the need for a function as part of the date package to be able to convert any Timeable into a datetime.
fixes: #4749
testing done:
import "date"
date.time(t: -1h)
2022-06-03T15:49:42.544101000Z
start = date.time(t: -1h)
start
2022-06-03T15:50:19.282299000Z
start = date.time(t: 2020-01-01)
start
2020-01-01T00:00:00.000000000Z
date.time(t: 2022-06-03T15:49:42.544101000Z)
2022-06-03T15:49:42.544101000Z
date.time(t: 2022-06-04T15:49:42Z)
2022-06-04T15:49:42.000000000Z
date.time(t: 2022-06-04T15:49:04.541Z)
2022-06-04T15:49:04.541000000Z
date.time(t: -3d12h4m25s1ms1us1ns)
2022-05-31T04:55:07.872817999Z
date.time(t: -1y1mo1w)
2021-04-26T17:00:24.855445000Z
Done checklist