@@ -26,6 +26,7 @@ import Data.Scientific (Scientific)
2626import Data.Set (Set)
2727import qualified Data.Text as T
2828import qualified Data.Text.Lazy as TL
29+import Data.Time
2930import Data.Word
3031import GHC.Generics
3132
@@ -163,6 +164,42 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e) => ToSchem
163164instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f) => ToSchema (a, b, c, d, e, f)
164165instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f, ToSchema g) => ToSchema (a, b, c, d, e, f, g)
165166
167+timeNamedSchema :: String -> String -> NamedSchema
168+timeNamedSchema name format = (Just name, mempty
169+ & schemaType .~ SchemaString
170+ & schemaFormat ?~ T.pack format
171+ & schemaMinLength ?~ toInteger (length format))
172+
173+-- |
174+-- >>> toSchema (Proxy :: Proxy Day) ^. schemaFormat
175+-- Just "yyyy-mm-dd"
176+instance ToSchema Day where
177+ toNamedSchema _ = timeNamedSchema "Day" "yyyy-mm-dd"
178+
179+-- |
180+-- >>> toSchema (Proxy :: Proxy LocalTime) ^. schemaFormat
181+-- Just "yyyy-mm-ddThh:MM:ss"
182+instance ToSchema LocalTime where
183+ toNamedSchema _ = timeNamedSchema "LocalTime" "yyyy-mm-ddThh:MM:ss"
184+
185+-- |
186+-- >>> toSchema (Proxy :: Proxy ZonedTime) ^. schemaFormat
187+-- Just "yyyy-mm-ddThh:MM:ss(Z|+hh:MM)"
188+instance ToSchema ZonedTime where
189+ toNamedSchema _ = (Just "ZonedTime", mempty
190+ & schemaType .~ SchemaString
191+ & schemaFormat ?~ "yyyy-mm-ddThh:MM:ss(Z|+hh:MM)"
192+ & schemaMinLength ?~ toInteger (length ("yyyy-mm-ddThh:MM:ssZ" :: String)))
193+
194+instance ToSchema NominalDiffTime where
195+ toNamedSchema _ = toNamedSchema (Proxy :: Proxy Integer)
196+
197+-- |
198+-- >>> toSchema (Proxy :: Proxy UTCTime) ^. schemaFormat
199+-- Just "yyyy-mm-ddThh:MM:ssZ"
200+instance ToSchema UTCTime where
201+ toNamedSchema _ = timeNamedSchema "UTCTime" "yyyy-mm-ddThh:MM:ssZ"
202+
166203instance ToSchema T.Text where
167204 toNamedSchema _ = unnamed $ toSchema (Proxy :: Proxy String)
168205