git.iko.soy/typeable/http-api-data
on master help sign in
Add Day (yesodweb/yesod#320)
commitcd5d554c230735e9e3eae3e17917c65eec273b2e authorMichael Snoyman <michael@snoyman.com> dateTue 3 Apr 2012, 07:06 (15 years ago) parent3c241df
2 files changed+9−1
Web/PathPieces.hs+7 path-pieces.cabal+2−1
Web/PathPieces.hs+7
@@ -13,6 +13,7 @@ import Data.Int (Int64)
1313import qualified Data.Text as S
1414import qualified Data.Text.Lazy as L
1515import qualified Data.Text.Read
16+import Data.Time (Day)
1617
1718class PathPiece s where
1819 fromPathPiece :: S.Text -> Maybe s
@@ -51,6 +52,12 @@ instance PathPiece Int64 where
5152 Left _ -> Nothing
5253 toPathPiece = S.pack . show
5354
55+instance PathPiece Day where
56+ fromPathPiece t =
57+ case reads $ S.unpack t of
58+ [(a,"")] -> Just a
59+ _ -> Nothing
60+ toPathPiece = S.pack . show
5461
5562class PathMultiPiece s where
5663 fromPathMultiPiece :: [S.Text] -> Maybe s
path-pieces.cabal+2−1
@@ -1,5 +1,5 @@
11name: path-pieces
2−version: 0.1.0
2+version: 0.1.1
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>
@@ -14,6 +14,7 @@ homepage: http://github.com/snoyberg/path-pieces
1414library
1515 build-depends: base >= 4 && < 5
1616 , text >= 0.5 && < 0.12
17+ , time
1718 exposed-modules: Web.PathPieces
1819 ghc-options: -Wall
1920