lpeterse / haskell-utc Goto Github PK
View Code? Open in Web Editor NEWA pragmatic time and date library (Haskell)
License: MIT License
A pragmatic time and date library (Haskell)
License: MIT License
Consequently, renderRfc3339
is always off by a factor of 60:
> renderRfc3339 (Local (Just 3600) (epoch :: DateTime)) :: Maybe Text
Just "1970-01-01T00:00:00+60:00"
parseRfc3339
uses the offset correctly however, consequently renderRfc3339
and parseRfc3339
don't form an identity relationship anymore:
(parseRfc3339 "1970-01-01T00:00:00+01:00" :: Maybe (Local DateTime)) >>= renderRfc3339) :: Maybe Text
Just "1970-01-01T00:00:00+60:00"
RFC3339 strings consist of a local time and an UTC offset. renderRfc3339
and parseRfc3339
however always interpret the local time of the string as utc
time: Instead of offseting the utc
field by offset
before rendering and after parsing to convert the utc time of the Local
type to the local time of the RFC3339 string and vice versa, these functions just treat RFC3339 as if it were a UTC time and an additional offset (just like Local
works internally).
From RFC3339
Numeric offsets are calculated as "local time minus UTC". So the
equivalent time in UTC can be determined by subtracting the offset
from the local time. For example, 18:50:00-04:00 is the same time as
22:50:00Z. (This example shows negative offsets handled by adding
the absolute value of the offset.)
This bug is caused by not operating on the Local
type, but on the internal type wrapped by Local
whose IsTime
and IsDate
instances don't know about the offset. It is not trivial to fix, since in rfc3339Builder
IsDate (Local t)
IsTime (Local t)
can't be deduced. It would require IsDate t
and IsTime t
to imply IsDate (Local t)
and IsTime (Local t)
which is currently not the case and might be tricky to achieve.
To reproduce:
addSecondFractions (-1.0) epoch :: IO Time
*** Exception: UtcException "Time: setSecondFraction 1 % 1 00:00:00"
This happens, because with that value, frcs
would be 0
in addSecondFractions
, so setSecond (frcs + 1.0)
fails of course.
It would be nice if this package would be available on Stackage. Provided that everything builds with the current snapshot (master appears to do so, but v0.2.0.1 does not), doing so is as simple as submitting a pull request to fpco/stackage to add a few lines of metadata to the build constraints file. See the guide for details.
Would be great to be able to build directly from hackage again!
Data/UTC/Class/HasUnixTime.hs:39:3: error:
• Constraint ‘Monad m’ in the type of ‘getUnixTime’
constrains only the class type variables
Use ConstrainedClassMethods to allow it
• When checking the class method:
getUnixTime :: forall (m :: * -> *).
HasUnixTime m =>
forall a. (Monad m, IsUnixTime a) => m a
In the class declaration for ‘HasUnixTime’
cabal: Leaving directory '/tmp/cabal-tmp-9305/utc-0.2.0.1'
cabal: Error: some packages failed to install:
utc-0.2.0.1 failed during the building phase. The exception was:
ExitFailure 1
Please see http://hydra.cryp.to/build/778539/log/raw for a complete log of the failing build.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.