FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FLIP 251: Cadence Date and Time by darkdrag00nv2 · Pull Request #245 · onflow/flips · GitHub

/ flips Public

FLIP 251: Cadence Date and Time - #245

Open
darkdrag00nv2 wants to merge 4 commits into
onflow:mainfrom
darkdrag00nv2:date_time
Open

FLIP 251: Cadence Date and Time#245
darkdrag00nv2 wants to merge 4 commits into
onflow:mainfrom
darkdrag00nv2:date_time

Conversation

darkdrag00nv2 commented Jan 29, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

#251

Work towards onflow/cadence#843

darkdrag00nv2 changed the title FLIP 245: Cadence Date and time FLIP 245: Cadence Date and Time Jan 29, 2024
darkdrag00nv2 marked this pull request as ready for review February 4, 2024 13:33

Copy link
Copy Markdown
Contributor Author

cc: @turbolent @SupunS @dsainati1

Copy link
Copy Markdown
Collaborator

It is assumed that there are 3600*24 seconds in every day and there are no leap years.

I think ignoring leap years is not a good idea.

turbolent commented Feb 19, 2024
edited
Loading

Copy link
Copy Markdown
Member

It is assumed that there are 3600*24 seconds in every day and there are no leap years.

I think ignoring leap years is not a good idea.

Agreed, we can probably at least support leap years, like e.g. Java's java.time.LocalDate does.

In general, we should not reinvent the wheel here and base the API and implementation of an established solution, like e.g. Java's JSR310

Copy link
Copy Markdown
Contributor Author

In general, we should not reinvent the wheel here and base the API and implementation of an established solution, like e.g. Java's JSR310

Yep, the current proposal is more based on the python datetime module.

I wrongly made the assumption that they don't support leap years 🙁. I was just giving the wrong input with the year 2011 🤦

>>> datetime.datetime(2011, 2, 29)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: day is out of range for month

Trying with an actual leap year works fine.

>>> datetime.datetime(2024, 2, 29)

Copy link
Copy Markdown
Contributor

Hi @darkdrag00nv2 - this FLIP is not reflected on FLIP project tracker. Did you follow the process outlined in https://github.com/onflow/flips? Specifically please remember to do the following without which the FLIP won't get visibility on the project tracker-

Create an issue by using one of the FLIP issue templates based on the type of the FLIP - application, governance, cadence or protocol. The title of the issue should be the title of your FLIP, e.g., "Dynamic Inclusion fees". Submit the issue. Note the issue number that gets assigned.
Then, create your FLIP as a pull request to this repository (onflow/flips). Use the issue number generated in step 2 as the FLIP number. And mention the FLIP issue by copying the GitHub URL or the issue in the comment section.

Thank you!

darkdrag00nv2 changed the title FLIP 245: Cadence Date and Time FLIP 251: Cadence Date and Time Mar 3, 2024
Comment thread cadence/20240115-cadence-date-time.md Outdated

turbolent left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good!

As we're finishing work on Cadence 1.0, we can finally come back to proposals like this. Thank you for your patience!

I left some comments and suggestions, and am happy to apply suggested edits and add remaining details. Does that sound good to you @darkdrag00nv2 ?

Once we addressed the outstanding issues, we can schedule to vote on it in the next WG call


- `LocalDateTime.fromTimestamp(timestamp : UFix64)`: Creates a `LocalDateTime` with value based on the passed timestamp argument.

- `LocalDateTime.of(year: UInt64, month: Month, day: UInt8, hour: UInt8, minute: UInt8, second: UInt8)`: Creates a `LocalDateTime` with value based on the passed arguments assuming that there are 3600*24 seconds in every day.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This can maybe just be a constructor function. It might be good to improve the naming of day and make it explicit that it is the day of the month, e.g. dayOfMonth:

Suggested change
- `LocalDateTime.of(year: UInt64, month: Month, day: UInt8, hour: UInt8, minute: UInt8, second: UInt8)`: Creates a `LocalDateTime` with value based on the passed arguments assuming that there are 3600*24 seconds in every day.
- `LocalDateTime(year: UInt64, month: Month, dayOfMonth: UInt8, hour: UInt8, minute: UInt8, second: UInt8)`: Creates a `LocalDateTime` with value based on the passed arguments assuming that there are 3600*24 seconds in every day.

Examples below also need to be updated


1. `getYear(): UInt32`: Get the year of the date-time.
2. `getMonth(): Month`: Get the month of the date-time.
3. `getDate(): UInt8`: Get the date of the date-time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe improve the naming and clarify it is the day of the month, i.e.

Suggested change
3. `getDate(): UInt8`: Get the date of the date-time.
3. `getDayOfMonth(): UInt8`: Get the day-of-month of the date-time.

Examples below also need to be updated

The `LocalDateTime` type will be defined as follows:

```cadence
pub struct LocalDateTime {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The proposal needs to be updated to Cadence 1.0. For example:

  • pub -> access(all)
  • Add view function modifier to getter functions


## Design Proposal

New types `LocalDateTime` & `Duration` will be added to Cadence. Both of these data types assume that there are 3600*24 seconds in every day and there are no leap years.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I wonder if we should add this functionality as a standard library contract, i.e. namespace it and not add them to the global namespace.

- `getDays(): Int32`: Get the days of the `Duration`.
- `getSeconds(): UInt32`: Get the second of the `Duration`.
- `getMicroseconds(): UInt32`: Get the microseconds of the `Duration`.
- `addYears(years : UInt32): Duration`: Return a new `Duration` after adding the provided number of years to it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Here and for the other functions below: The function name already clarifies what the parameter is, so the argument label can be removed:

Suggested change
- `addYears(years : UInt32): Duration`: Return a new `Duration` after adding the provided number of years to it.
- `addYears(_ years: UInt32): Duration`: Return a new `Duration` after adding the provided number of years to it.

- `getDays(): Int32`: Get the days of the `Duration`.
- `getSeconds(): UInt32`: Get the second of the `Duration`.
- `getMicroseconds(): UInt32`: Get the microseconds of the `Duration`.
- `addYears(years : UInt32): Duration`: Return a new `Duration` after adding the provided number of years to it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The add name sounds like it is mutating, but it seems like that isn't the case right?

Maybe we can use the plus and minus naming like in Java?

dateTimeFromTs.getSecond() // 12
dateTimeFromTs.getDayOfWeek() // wednesday

let dateTimeFromComponents = LocalDateTime.of(2019, april, 29, 19, 49, 31)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Need to add argument labels, as required by the function declaration

Copy link
Copy Markdown
Member

We had a working group call yesterday and discussed this FLIP, see the notes in https://github.com/onflow/Flow-Working-Groups/blob/main/cadence_language_and_execution_working_group/meetings/2024-10-29.md#flips.

Consensus is that the proposed library would be useful, but is low priority. Luckily it can be implemented purely in Cadence, and does not need any knowledge of or required any contributions to the Cadence implementation.

@onflow/flow-develop-experience-tools @gregsantos: @dete proposed this could be a good item for the community and could e.g. be implemented through a grant, at a hackathon, etc.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL