hourglass-orphans (empty) → 0.1.0.0
raw patch · 6 files changed
+173/−0 lines, 6 filesdep +aesondep +basedep +hourglasssetup-changed
Dependencies added: aeson, base, hourglass, hourglass-orphans, hspec, hspec-expectations, text
Files
- LICENSE +30/−0
- README.md +7/−0
- Setup.hs +2/−0
- hourglass-orphans.cabal +40/−0
- src/Data/Hourglass/Types/Orphans.hs +47/−0
- test/Spec.hs +47/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Sibi Prabakaran (c) 2017++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 Author name here 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.
+ README.md view
@@ -0,0 +1,7 @@+# hourglass-orphans++[](https://travis-ci.org/psibi/hourglass-orphans)++Orphan Aeson instances to hourglass++
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hourglass-orphans.cabal view
@@ -0,0 +1,40 @@+name: hourglass-orphans+version: 0.1.0.0+synopsis: Orphan Aeson instances to hourglass+description: Orphan Aeson instances to hourglass+homepage: https://github.com/psibi/hourglass-orphans#readme+license: BSD3+license-file: LICENSE+author: Sibi Prabakaran+maintainer: sibi@psibi.in+copyright: 2017 Sibi+category: Web+build-type: Simple+extra-source-files: README.md+cabal-version: >=1.10++library+ hs-source-dirs: src+ exposed-modules: Data.Hourglass.Types.Orphans+ build-depends: base >= 4.7 && < 5,+ hourglass,+ aeson+ default-language: Haskell2010++test-suite hourglass-orphans-test+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Spec.hs+ build-depends: base+ , hourglass-orphans+ , hspec >= 2.1 && < 3+ , aeson+ , hspec-expectations+ , hourglass+ , text+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/psibi/hourglass-orphans
+ src/Data/Hourglass/Types/Orphans.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE OverloadedStrings #-}++module Data.Hourglass.Types.Orphans+ ( + -- * Re-exports+ module Data.Hourglass.Types+ ) where++import Data.Hourglass.Types+import Data.Aeson+import Data.Aeson.TH+#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*>))+import Data.Monoid (mempty)+#endif++deriveJSON defaultOptions ''Month++deriveJSON defaultOptions ''WeekDay++deriveJSON defaultOptions ''NanoSeconds++deriveJSON defaultOptions ''Seconds++deriveJSON defaultOptions ''Minutes++deriveJSON defaultOptions ''Hours++deriveJSON defaultOptions ''TimezoneOffset++deriveJSON defaultOptions ''Elapsed++instance ToJSON ElapsedP where+ toJSON (ElapsedP e n) =+ object ["seconds" .= toJSON e, "nanoseconds" .= toJSON n]++instance FromJSON ElapsedP where+ parseJSON (Object v) = ElapsedP <$> (v .: "seconds") <*> (v .: "nanoseconds")+ parseJSON _ = mempty++deriveJSON defaultOptions ''Date++deriveJSON defaultOptions ''TimeOfDay++deriveJSON defaultOptions ''DateTime
+ test/Spec.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE OverloadedStrings #-}++import Data.Hourglass.Types.Orphans+import Data.Aeson.Types+import Test.Hspec+import Data.Hourglass.Types+import Data.Text++main :: IO ()+main =+ hspec $+ do describe "Month instance" $+ do it "January" $+ do let x = January :: Month+ toJSON x `shouldBe` (String "January")+ it "December" $+ do let x = December :: Month+ toJSON x `shouldBe` (String "December")+ describe "Weekday instance" $+ do it "Sunday" $+ do let x = Sunday :: WeekDay+ toJSON x `shouldBe` (String "Sunday")+ it "Friday" $+ do let x = Friday :: WeekDay+ toJSON x `shouldBe` (String "Friday")+ describe "NanoSeconds" $+ do it "90000" $+ do let x = NanoSeconds 90000+ toJSON x `shouldBe` (Number 90000.0)+ describe "Elapsed" $+ do it "sample 1" $+ do let x = Elapsed 500+ toJSON x `shouldBe` (Number 500.0)+ describe "Date" $+ do it "sample 1" $+ do let x =+ Date+ { dateYear = 2000+ , dateMonth = January+ , dateDay = 3+ }+ toJSON x `shouldBe`+ object+ [ ("dateMonth", String "January")+ , ("dateDay", Number 3.0)+ , ("dateYear", Number 2000.0)+ ]