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

feat(date): add builtin function time to the date package to convert any timeable into datetime (#4749) #4833

Closed
wants to merge 1 commit into from

Conversation

Rahul-Vasan
Copy link
Contributor

@Rahul-Vasan Rahul-Vasan commented Jun 3, 2022

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

  • docs/SPEC.md updated
  • Test cases written

…any timeable into datetime (#4749)

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
@Rahul-Vasan Rahul-Vasan requested review from a team as code owners June 3, 2022 23:22
@Rahul-Vasan Rahul-Vasan requested review from nathanielc and lwandzura and removed request for a team June 3, 2022 23:22
@sanderson sanderson requested review from sanderson and removed request for lwandzura June 4, 2022 19:19
@@ -39,6 +39,35 @@ package date
// ```
builtin second : (t: T) => int where T: Timeable

// time returns the datetime of a specified timeable.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// - t: Timeable. It can be either time or duration
// - t: Duration or time value.

Comment on lines +59 to +60
// ```
// ### Return the time for a given relative duration
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// ```
// ### Return the time for a given relative duration
// ```
//
// ### Return the time for a given relative duration

Comment on lines +62 to +68
// ```no_run
// import "date"
//
// date.time(t: -1d1h1m1s1us1ns)
//
// // Returns 2022-06-02T20:02:19.506570999Z
// ```
Copy link
Contributor

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.
Suggested change
// ```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 pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a function to create a datetime from a Timeable
2 participants