Skip to content

Commit dc738d1

Browse files
Merge pull request #96 from chrisdone/cd/2025-05-30-add-support-for-day
Add basic Day support
2 parents a575918 + 7818284 commit dc738d1

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

examples/39-day.hell

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
main = do
2+
day1 :: Day <-
3+
Maybe.maybe (Error.error "Invalid") IO.pure $ Day.fromGregorianValid (Int.toInteger 2025) 08 09
4+
day2 <- Maybe.maybe (Error.error "Invalid") IO.pure $ Day.iso8601ParseM "2025-08-09"
5+
IO.print $ Eq.eq day1 day2 -- True
6+
Text.putStrLn $ Day.iso8601Show day1 -- 2025-08-09

hell.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ executable hell
4040
, th-lift
4141
, th-orphans
4242
, these
43+
, time
4344
, typed-process
4445
, unliftio
4546
, vector

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies:
2929
- aeson
3030
- temporary
3131
- these
32+
- time
3233

3334
ghc-options:
3435
- -Wall

src/Hell.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ module Main (main) where
4646
-- guest language as such.
4747

4848
#if __GLASGOW_HASKELL__ >= 906
49-
import Numeric
5049
import Control.Monad
5150
#endif
51+
import qualified Data.Time.Format.ISO8601 as Time
52+
import qualified Data.Time as Time
53+
import Data.Time (Day)
54+
import Numeric
5255
import Control.Exception (evaluate)
5356
import qualified Control.Concurrent as Concurrent
5457
import Control.Monad.Reader
@@ -666,6 +669,7 @@ tc (UForall _ forallLoc _ _ fall _ _ reps0) _env = go reps0 fall
666669
if
667670
| Just Type.HRefl <- Type.eqTypeRep rep (typeRep @Int) -> go reps (f rep)
668671
| Just Type.HRefl <- Type.eqTypeRep rep (typeRep @Integer) -> go reps (f rep)
672+
| Just Type.HRefl <- Type.eqTypeRep rep (typeRep @Day) -> go reps (f rep)
669673
| Just Type.HRefl <- Type.eqTypeRep rep (typeRep @Double) -> go reps (f rep)
670674
| Just Type.HRefl <- Type.eqTypeRep rep (typeRep @Bool) -> go reps (f rep)
671675
| Just Type.HRefl <- Type.eqTypeRep rep (typeRep @Char) -> go reps (f rep)
@@ -1259,6 +1263,7 @@ supportedTypeConstructors =
12591263
("Value", SomeTypeRep $ typeRep @Value),
12601264
("()", SomeTypeRep $ typeRep @()),
12611265
("Handle", SomeTypeRep $ typeRep @IO.Handle),
1266+
("Day", SomeTypeRep $ typeRep @Day),
12621267

12631268
-- Internal, hidden types
12641269
("hell:Hell.NilL", SomeTypeRep $ typeRep @('NilL)),
@@ -1291,6 +1296,14 @@ supportedLits =
12911296
lit' "Text.readProcessStdout_" t_readProcessStdout_,
12921297
lit' "Text.getContents" (fmap Text.decodeUtf8 ByteString.getContents),
12931298
lit' "Text.setStdin" t_setStdin,
1299+
1300+
-- Dates
1301+
lit' "Day.fromGregorianValid" Time.fromGregorianValid,
1302+
lit' "Day.addDays" Time.addDays,
1303+
lit' "Day.diffDays" Time.diffDays,
1304+
lit' "Day.iso8601Show" (Text.pack . Time.iso8601Show :: Day -> Text),
1305+
lit' "Day.iso8601ParseM" (Time.iso8601ParseM . Text.unpack :: Text -> Maybe Day),
1306+
12941307
-- Text operations
12951308
lit' "Text.decodeUtf8" Text.decodeUtf8,
12961309
lit' "Text.encodeUtf8" Text.encodeUtf8,

0 commit comments

Comments
 (0)