-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Some useful wrappers and functions for building time ranges -- -- Some useful wrappers and functions for building time ranges @package haskell-time-range @version 0.2.0.0 module Data.Time.Range.Types -- | General purpose newtype wrappers for some commonly used -- Data.Time types. Helps to ensure you don't get your range -- ends mixed up, as well as providing some convenience when you only -- need to refer to particular levels of granularity in the time range. -- -- Initial need of this library was only at the day and hour level, if -- there is a need more granular times can be added. data StartDate data EndDate data DayInRange data StartHour data EndHour data Hour data LowerTimeBound data UpperTimeBound data Ranges Ranges :: LowerTimeBound -> UpperTimeBound -> NonEmpty DayInRange -> NonEmpty UTCTime -> Ranges [_rangesLowerBound] :: Ranges -> LowerTimeBound [_rangesUpperBound] :: Ranges -> UpperTimeBound [_rangesDaysInRange] :: Ranges -> NonEmpty DayInRange [_rangesUtcTimes] :: Ranges -> NonEmpty UTCTime class HasRanges c_acAE where rangesDaysInRange = (.) ranges rangesDaysInRange rangesLowerBound = (.) ranges rangesLowerBound rangesUpperBound = (.) ranges rangesUpperBound rangesUtcTimes = (.) ranges rangesUtcTimes ranges :: HasRanges c_acAE => Lens' c_acAE Ranges rangesDaysInRange :: HasRanges c_acAE => Lens' c_acAE (NonEmpty DayInRange) rangesLowerBound :: HasRanges c_acAE => Lens' c_acAE LowerTimeBound rangesUpperBound :: HasRanges c_acAE => Lens' c_acAE UpperTimeBound rangesUtcTimes :: HasRanges c_acAE => Lens' c_acAE (NonEmpty UTCTime) instance Data.Time.Range.Types.HasRanges Data.Time.Range.Types.Ranges instance GHC.Generics.Generic Data.Time.Range.Types.Ranges instance GHC.Classes.Eq Data.Time.Range.Types.Ranges instance GHC.Show.Show Data.Time.Range.Types.Ranges instance Data.Time.Range.Types.UpperTimeBound ~ t0 => Control.Lens.Wrapped.Rewrapped Data.Time.Range.Types.UpperTimeBound t0 instance Control.Lens.Wrapped.Wrapped Data.Time.Range.Types.UpperTimeBound instance GHC.Generics.Generic Data.Time.Range.Types.UpperTimeBound instance GHC.Classes.Eq Data.Time.Range.Types.UpperTimeBound instance GHC.Show.Show Data.Time.Range.Types.UpperTimeBound instance Data.Time.Range.Types.LowerTimeBound ~ t0 => Control.Lens.Wrapped.Rewrapped Data.Time.Range.Types.LowerTimeBound t0 instance Control.Lens.Wrapped.Wrapped Data.Time.Range.Types.LowerTimeBound instance GHC.Generics.Generic Data.Time.Range.Types.LowerTimeBound instance GHC.Classes.Eq Data.Time.Range.Types.LowerTimeBound instance GHC.Show.Show Data.Time.Range.Types.LowerTimeBound instance Data.Time.Range.Types.Hour ~ t0 => Control.Lens.Wrapped.Rewrapped Data.Time.Range.Types.Hour t0 instance Control.Lens.Wrapped.Wrapped Data.Time.Range.Types.Hour instance GHC.Generics.Generic Data.Time.Range.Types.Hour instance GHC.Show.Show Data.Time.Range.Types.Hour instance GHC.Classes.Eq Data.Time.Range.Types.Hour instance Data.Time.Range.Types.EndHour ~ t0 => Control.Lens.Wrapped.Rewrapped Data.Time.Range.Types.EndHour t0 instance Control.Lens.Wrapped.Wrapped Data.Time.Range.Types.EndHour instance GHC.Generics.Generic Data.Time.Range.Types.EndHour instance GHC.Show.Show Data.Time.Range.Types.EndHour instance GHC.Classes.Eq Data.Time.Range.Types.EndHour instance Data.Time.Range.Types.StartHour ~ t0 => Control.Lens.Wrapped.Rewrapped Data.Time.Range.Types.StartHour t0 instance Control.Lens.Wrapped.Wrapped Data.Time.Range.Types.StartHour instance GHC.Generics.Generic Data.Time.Range.Types.StartHour instance GHC.Show.Show Data.Time.Range.Types.StartHour instance GHC.Classes.Eq Data.Time.Range.Types.StartHour instance Data.Time.Range.Types.DayInRange ~ t0 => Control.Lens.Wrapped.Rewrapped Data.Time.Range.Types.DayInRange t0 instance Control.Lens.Wrapped.Wrapped Data.Time.Range.Types.DayInRange instance GHC.Generics.Generic Data.Time.Range.Types.DayInRange instance GHC.Show.Show Data.Time.Range.Types.DayInRange instance GHC.Classes.Eq Data.Time.Range.Types.DayInRange instance Data.Time.Range.Types.EndDate ~ t0 => Control.Lens.Wrapped.Rewrapped Data.Time.Range.Types.EndDate t0 instance Control.Lens.Wrapped.Wrapped Data.Time.Range.Types.EndDate instance GHC.Generics.Generic Data.Time.Range.Types.EndDate instance GHC.Show.Show Data.Time.Range.Types.EndDate instance GHC.Classes.Eq Data.Time.Range.Types.EndDate instance Data.Time.Range.Types.StartDate ~ t0 => Control.Lens.Wrapped.Rewrapped Data.Time.Range.Types.StartDate t0 instance Control.Lens.Wrapped.Wrapped Data.Time.Range.Types.StartDate instance GHC.Generics.Generic Data.Time.Range.Types.StartDate instance GHC.Show.Show Data.Time.Range.Types.StartDate instance GHC.Classes.Eq Data.Time.Range.Types.StartDate module Data.Time.Range class AsDay p f s _Day :: AsDay p f s => Optic' p f s Day -- |
-- >>> d ^. re _Day :: (Integer, Int, Int) -- (2017,2,25) -- -- >>> (2017 :: Integer, 2 :: Int, 25 :: Int) ^? _Day -- Just 2017-02-25 -- -- >>> (2017 :: Integer, 2 :: Int, 35 :: Int) ^? _Day -- Nothing ---- |
-- >>> d ^. re _Day :: String -- "2017-02-25" -- -- >>> "2017-02-25" ^? _Day -- Just 2017-02-25 ---- | Parse some common date formats to a Day -- -- Examples: -- --
-- >>> dayParse "2017-01-09" -- Right 2017-01-09 -- -- >>> dayParse "09/01/2017" -- Right 2017-01-09 -- -- >>> dayParse "30/02/2017" -- Left "Unable to parse Date Accepts [yyyy-mm-dd, yyyymmdd, mm/dd/yy, dd/mm/yyyy]: 30/02/2017" -- -- >>> dayParse "20170109" -- Right 2017-01-09 -- -- >>> dayParse "010917" -- Left "Unable to parse Date Accepts [yyyy-mm-dd, yyyymmdd, mm/dd/yy, dd/mm/yyyy]: 010917" -- -- >>> dayParse "02/13/17" -- Right 2017-02-13 -- -- >>> dayParse "2017-01-09" -- Right 2017-01-09 --dayParse :: String -> Either String Day -- | Given a wrapped start and end Day, as well as a chosen -- Hour, create a pair of wrapped UTCTime values that -- represent their upper and lower values. Used internally. -- --
-- >>> boundFromWrapped startD endD startH endH -- (LowerBound 2017-02-25 03:00:00 UTC,UpperBound 2017-02-27 05:00:00 UTC) --boundFromWrapped :: (Rewrapped s s, Rewrapped e e, Unwrapped s ~ Day, Unwrapped e ~ Day, Rewrapped hs hs, Rewrapped he he, Unwrapped hs ~ Natural, Unwrapped he ~ Natural) => s -> e -> hs -> he -> (LowerTimeBound, UpperTimeBound) -- | Provide a range builder for any wrapped types that have an -- Ord instance. -- --
-- >>> wrappedRange (_Wrapped #) succ startH endH :: NonEmpty StartHour -- StartHour 3 :| [StartHour 4,StartHour 5] -- -- >>> wrappedRange (_Wrapped #) succ endH startH :: NonEmpty StartHour -- StartHour 5 :| [] --wrappedRange :: (Rewrapped a a, Rewrapped b b, Rewrapped c c, Unwrapped a ~ t, Unwrapped b ~ t, Unwrapped c ~ t, Ord t) => (t -> c) -> (t -> t) -> a -> b -> NonEmpty c -- | Try to read a String value into a Natural -- representing a whole hour, in 24 hour time. "1" .. "23" or "00" -- --
-- >>> strToHourNatural "1" -- Right 1 -- -- >>> strToHourNatural "10" -- Right 10 -- -- >>> strToHourNatural "0" -- Left "Unable to parse 0 into acceptable hour value. Expected '1'-'23' or '00'" -- -- >>> strToHourNatural "00" -- Right 0 --strToHourNatural :: String -> Either String Natural -- | Convenience function for wrappedRange that provides a list of -- UTCTime at hourly intervals between the given start and end -- times. utcRangeHours :: (Rewrapped start start, Rewrapped end end, Unwrapped start ~ UTCTime, Unwrapped end ~ UTCTime) => start -> end -> NonEmpty UTCTime -- | Given two wrapped Day values, provide a NonEmpty -- list of all the days in between. -- --
-- >>> datesInRange startD endD -- DayInRange 2017-02-25 :| [DayInRange 2017-02-26,DayInRange 2017-02-27] -- -- >>> datesInRange endD startD -- DayInRange 2017-02-27 :| [] --datesInRange :: (Rewrapped a a, Rewrapped b b, Unwrapped a ~ Day, Unwrapped b ~ Day) => a -> b -> NonEmpty DayInRange -- | From the given starting points, construct a Ranges record -- with ranges and bounds constructed. Not providing an EndDate -- will use the StartDate. buildRanges :: StartDate -> Maybe EndDate -> StartHour -> EndHour -> Ranges instance (Data.Profunctor.Choice.Choice p, GHC.Base.Applicative f) => Data.Time.Range.AsDay p f (GHC.Integer.Type.Integer, GHC.Types.Int, GHC.Types.Int) instance (Data.Profunctor.Choice.Choice p, GHC.Base.Applicative f) => Data.Time.Range.AsDay p f GHC.Base.String