packages feed

time-lens (empty) → 0.1

raw patch · 4 files changed

+160/−0 lines, 4 filesdep +basedep +data-lensdep +timesetup-changed

Dependencies added: base, data-lens, time

Files

+ Data/Time/Lens.hs view
@@ -0,0 +1,108 @@+module Data.Time.Lens+    ( -- * Time+      HasTime(..)+    , hours+    , minutes+    , seconds+      -- * Date+    , HasDay(..)+    , year+    , month+    , dayOfMonth+    , gregorianDay+      -- * Time zone+    , HasTimeZone(..)+    , tzMinutes+    , tzSummerOnly+    , tzName+      -- * Re-exports from "Data.Time"+    , T.Day+    , T.TimeOfDay+    , T.LocalTime+    , T.ZonedTime+    , T.getZonedTime+      -- * Re-exports from "Data.Lens.Common"+    , Lens+    , getL+    )+where++import Control.Category+import Prelude hiding ((.), id)+import Data.Lens.Common+import Data.Fixed (Pico)+import qualified Data.Time as T++class HasTime a where+    time :: Lens a T.TimeOfDay++hours :: HasTime a => Lens a Int+hours = (lens T.todHour $ \x t -> t { T.todHour = x }) . time++minutes :: HasTime a => Lens a Int+minutes = (lens T.todMin $ \x t -> t { T.todMin = x }) . time++seconds :: HasTime a => Lens a Pico+seconds = (lens T.todSec $ \x t -> t { T.todSec = x }) . time++instance HasTime T.TimeOfDay where+    time = iso id id++localTimeOfZonedTime :: Lens T.ZonedTime T.LocalTime+localTimeOfZonedTime =+    lens T.zonedTimeToLocalTime $+        \x t -> t { T.zonedTimeToLocalTime = x }++instance HasTime T.LocalTime where+    time = lens T.localTimeOfDay $ \x t -> t { T.localTimeOfDay = x }++instance HasTime T.ZonedTime where+    time = time . localTimeOfZonedTime++instance HasTime T.UTCTime where+    time = time . iso (T.utcToLocalTime T.utc) (T.localTimeToUTC T.utc)++class HasDay a where+    day :: Lens a T.Day++gregorianDay :: HasDay a => Lens a (Integer,Int,Int)+gregorianDay = iso T.toGregorian (uncurry3 T.fromGregorian) . day++year :: HasDay a => Lens a Integer+year = lens (\(y,_,_) -> y) (\y (_,m,d) -> (y,m,d)) . gregorianDay++month :: HasDay a => Lens a Int+month = lens (\(_,m,_) -> m) (\m (y,_,d) -> (y,m,d)) . gregorianDay++dayOfMonth :: HasDay a => Lens a Int+dayOfMonth = lens (\(_,_,d) -> d) (\d (y,m,_) -> (y,m,d)) . gregorianDay++uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d+uncurry3 f (a, b, c) = f a b c++instance HasDay T.Day where+    day = iso id id++instance HasDay T.LocalTime where+    day = lens T.localDay (\d s -> s { T.localDay = d })++instance HasDay T.ZonedTime where+    day = day . localTimeOfZonedTime++instance HasDay T.UTCTime where+    day = day . iso (T.utcToLocalTime T.utc) (T.localTimeToUTC T.utc)++class HasTimeZone a where+    timeZone :: Lens a T.TimeZone++tzMinutes :: HasTimeZone a => Lens a Int+tzMinutes = (lens T.timeZoneMinutes $ \x t -> t { T.timeZoneMinutes = x }) . timeZone++tzSummerOnly :: HasTimeZone a => Lens a Bool+tzSummerOnly = (lens T.timeZoneSummerOnly $ \x t -> t { T.timeZoneSummerOnly = x }) . timeZone++tzName :: HasTimeZone a => Lens a String+tzName = (lens T.timeZoneName $ \x t -> t { T.timeZoneName = x }) . timeZone++instance HasTimeZone T.ZonedTime where+    timeZone = lens T.zonedTimeZone $ \x t -> t { T.zonedTimeZone = x }
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, Roman Cheplyaka++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Roman Cheplyaka nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ time-lens.cabal view
@@ -0,0 +1,20 @@+-- Initial time-lens.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                time-lens+version:             0.1+synopsis:            Lens-based interface to Data.Time data structures+-- description:         +license:             BSD3+license-file:        LICENSE+author:              Roman Cheplyaka+maintainer:          Roman Cheplyaka <roma@ro-che.info>+-- copyright:           +category:            Data+build-type:          Simple+cabal-version:       >=1.8++library+  exposed-modules:     Data.Time.Lens+  -- other-modules:       +  build-depends:       base == 4.*, data-lens == 2.*, time == 1.*