Skip to content

feat: add duration support - #490

Closed
II11II wants to merge 1 commit into
serverpod:mainfrom
II11II:support_duration
Closed

II11II wants to merge 1 commit into
serverpod:mainfrom
II11II:support_duration

Conversation

@II11II

@II11II II11II commented Dec 16, 2022

Copy link
Copy Markdown
Contributor

Replace this paragraph with a description of what this PR is changing or adding, and why.

List which issues are fixed by this PR. You must list at least one issue.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update cointains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

If you have done any breaking changes, make sure to outline them here, so that they can be included in the notes for the next release.

@II11II

II11II commented Dec 16, 2022

Copy link
Copy Markdown
Contributor Author

#311

@github-actions

github-actions Bot commented Dec 16, 2022 •

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@II11II

II11II commented Dec 16, 2022

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@vlidholt vlidholt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a good addition. However, it needs tests added to the connection test and serialization test, here:
https://github.com/serverpod/serverpod/blob/main/tests/serverpod_test_server/test/connection_test.dart

It also needs support for reading and writing to the database. Look at e.g. DateTime for how that is setup.

@@ -0,0 +1,98 @@
/// Extension for decoding [Duration] in the protocol.
extension DurationDec on String {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about using the intl package to format the duration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yahu1031 Does intl library have parser from String to Duration?
If yes, could you share the method name or link to the docs to that method?
Thank you

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You could also just use the inMicroseconds property, store the value as an int, recreate the Duration from the microseconds. That seems much better than involving the intl package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am afraid that when the user wants to insert Duration(days: 9999999999), it can be stored incorrectly while inMicroseconds or inMilliSeconds are used

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

2^63 - 1 is the max value of int in Dart, that should be enough, no?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's 213503982 days.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Or 584942 years. I doubt anyone use more than that for calculating dates and times.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

213503982 days * 8,64e+7 miliseconds=very big number😅

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, just checked. The Duration is internally stored as an int anyway. So it cannot handle any higher values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In that case, I have no argument )
If you request to change it to int, ill update my mr

@vlidholt

Copy link
Copy Markdown
Collaborator

I'm closing this as there is a new one with the same feature.

@vlidholt vlidholt closed this Dec 17, 2022
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 17, 2022
@II11II
II11II deleted the support_duration branch December 17, 2022 14:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants