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

Use fixed-width integers to represent days #68

Open
charles-cooper opened this issue Mar 19, 2017 · 3 comments
Open

Use fixed-width integers to represent days #68

charles-cooper opened this issue Mar 19, 2017 · 3 comments
Milestone

Comments

@charles-cooper
Copy link

Currently https://hackage.haskell.org/package/time-1.8.0.1/docs/Data-Time-Calendar.html#t:Day is represented in memory as an Integer, and many similar functions like fromGregorian which interface with Integers. While this is admirably future-proof (we can deal with years larger than the year 2,147,481,790 AD!) I think we will be using intuitionistic type theory sooner than we will need those dates :)

Using something like Int32 would give us nearly the same flexibility, better Storable instances, interfacing with C and serialization/deserialization. I'm not sure how much this will break downstream code, but I have a feeling most people are using fromIntegral to interface with the API anyways, and this change will actually lessen the amount of marshalling people need to do.

@charles-cooper
Copy link
Author

Something like charles-cooper@404f094.

To get a sense of practicality I was able to get ghc to build (https://github.com/charles-cooper/ghc/tree/day_int32) with only one change to libraries/Cabal:

diff --git a/Cabal/Distribution/Simple/SrcDist.hs b/Cabal/Distribution/Simple/SrcDist.hs
index 90a6323..a0b5e0e 100644
--- a/Cabal/Distribution/Simple/SrcDist.hs
+++ b/Cabal/Distribution/Simple/SrcDist.hs
@@ -391,10 +391,10 @@ snapshotVersion date = alterVersion (++ [dateToSnapshotNumber date])
 -- For example given a date @18/03/2008@ produce the number @20080318@.
 --
 dateToSnapshotNumber :: UTCTime -> Int
-dateToSnapshotNumber date = case toGregorian (utctDay date) of
+dateToSnapshotNumber date = fromIntegral $ case toGregorian (utctDay date) of
                             (year, month, day) ->
-                                fromIntegral year * 10000
-                              + month             * 100
+                                fromIntegral{-backwards compat time-}year  * 10000
+                              + month * 100
                               + day

Which needs an extra fromIntegral for one of the bootstrapping stages.

@AshleyYakeley
Copy link
Member

It's about 6 million years each way, which is probably reasonable.

Prelude Data.Int Data.Time> ModifiedJulianDay $ toInteger (maxBound :: Int32)
5881469-05-27
Prelude Data.Int Data.Time> ModifiedJulianDay $ toInteger (minBound :: Int32)
-5877752-05-08

@AshleyYakeley AshleyYakeley added this to the 2.0 milestone Jan 7, 2018
@AshleyYakeley
Copy link
Member

#80 is the larger issue.

bgamari pushed a commit to bgamari/time that referenced this issue Mar 27, 2024
bgamari pushed a commit to bgamari/time that referenced this issue Mar 27, 2024
And fix free-bug in 'putEnv'. Fixes haskell#68
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