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

SecondOfDay and MinuteOfDay types #243

Closed
NorfairKing opened this issue Jun 3, 2023 · 10 comments
Closed

SecondOfDay and MinuteOfDay types #243

NorfairKing opened this issue Jun 3, 2023 · 10 comments

Comments

@NorfairKing
Copy link

I'm running into this bug: yesodweb/persistent#1500 and I realise that actually I don't need sub-second or even sub-minute precision.

Perhaps time could have SecondOfDay and MinuteOfDay types that avoid this problem by construction.

@AshleyYakeley
Copy link
Member

Hmm, could be useful.

Leaving aside the principle of not representing disallowed state, the more practical advantage of these types over TimeOfDay would be Read and Show instances, is that correct? Is this what caused the issue with persistent/sqlite?

@NorfairKing
Copy link
Author

@AshleyYakeley I know we differ in opinion about this, so I won't argue about it.

What caused the issue with persistent/sqlite is that persistent/sqlite doesn't represent sub-second precision but TimeOfDay does.

@AshleyYakeley
Copy link
Member

OK, but what actually happened that caused the problem?

@NorfairKing
Copy link
Author

@AshleyYakeley I'm not sure. I'm guessing an upgrade somewhere but I can't tell of which package: time/sqlite/persistent...

@AshleyYakeley
Copy link
Member

OK. Well let's leave this open, see if anyone has a real-world use-case for it.

@NorfairKing
Copy link
Author

@AshleyYakeley I've already had a real-world use-case in https://social-dance.today.
TimeOfDay doesn't roundtrip through sqlite so I needed to use SecondOfDay.

@AshleyYakeley
Copy link
Member

Can you tell me why it's not round-tripping?

@AshleyYakeley
Copy link
Member

Which way are you going, sqlite→TimeOfDay→sqlite, or TimeOfDay→sqlite→TimeOfDay? And if the latter, how are you constructing the initial TimeOfDay?

@NorfairKing
Copy link
Author

@AshleyYakeley it's the latter.
genValid :: Gen TimeOfDay -> (this part is "wrong" but it's baked into persistent) sqlite -> TimeOfDay

@AshleyYakeley
Copy link
Member

I think this is better left for another package to do. It would introduce a lot of additional conversion functions, and generally I want to keep time focussed on time-related calculations rather than precise conceptual abstraction.

@AshleyYakeley AshleyYakeley closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2024
bgamari pushed a commit to bgamari/time that referenced this issue Mar 27, 2024
* Allow base-4.17 for GHC 9.4; restrict filepath < 1.5

* Fix 'marked as Trustworthy but has been inferred as safe' warning
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

No branches or pull requests

2 participants