module Data.Validity.Time.LocalTime where
import Data.Validity
import Data.Time.LocalTime
import Data.Validity.Time.Calendar ()
instance Validity TimeZone where
isValid TimeZone {..} =
isValid timeZoneMinutes &&
isValid timeZoneSummerOnly && isValid timeZoneName
validate TimeZone {..} =
mconcat
[ timeZoneMinutes <?!> "timeZoneMinutes"
, timeZoneSummerOnly <?!> "timeZoneSummerOnly"
, timeZoneName <?!> "timeZoneName"
]
instance Validity TimeOfDay where
isValid TimeOfDay {..} =
and
[ isValid todHour
, todHour >= 0
, todHour <= 23
, isValid todMin
, todMin >= 0
, todMin <= 59
, isValid todSec
, todSec >= 0
, todSec < 61
]
validate TimeOfDay {..} =
mconcat
[ todHour <?!> "todHour"
, todHour >= 0 <?@> "The 'hour' is positive."
, todHour <= 23 <?@> "The 'hour' is 23 or less."
, todMin <?!> "todMin"
, todMin >= 0 <?@> "The 'minute' is positive."
, todMin <= 59 <?@> "The 'minute' is 59 or less."
, todSec <?!> "todSec"
, todSec >= 0 <?@> "The 'second' is positive."
, todSec < 61 <?@> "The 'second' is 60 or less."
]
instance Validity LocalTime where
isValid LocalTime {..} = isValid localDay && isValid localTimeOfDay
validate LocalTime {..} =
mconcat [localDay <?!> "localDay", localTimeOfDay <?!> "localTimeOfDay"]
instance Validity ZonedTime where
isValid ZonedTime {..} =
isValid zonedTimeToLocalTime && isValid zonedTimeZone
validate ZonedTime {..} =
mconcat
[ zonedTimeToLocalTime <?!> "zonedTimeToLocalTime"
, zonedTimeZone <?!> "zonedTimeZone"
]