mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
11a454c2d6
This commit applies ormolu to the whole Haskell code base by running `make format`. For in-flight branches, simply merging changes from `main` will result in merge conflicts. To avoid this, update your branch using the following instructions. Replace `<format-commit>` by the hash of *this* commit. $ git checkout my-feature-branch $ git merge <format-commit>^ # and resolve conflicts normally $ make format $ git commit -a -m "reformat with ormolu" $ git merge -s ours post-ormolu https://github.com/hasura/graphql-engine-mono/pull/2404 GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
45 lines
1.3 KiB
Haskell
45 lines
1.3 KiB
Haskell
-- | Time-related properties we care about.
|
|
module Data.TimeSpec (spec) where
|
|
|
|
import Data.Aeson
|
|
import Data.Time
|
|
import Data.Time.Clock.Units
|
|
import Test.Hspec
|
|
import Prelude
|
|
|
|
spec :: Spec
|
|
spec = do
|
|
timeUnitsSpec
|
|
diffTimeSpec
|
|
|
|
timeUnitsSpec :: Spec
|
|
timeUnitsSpec =
|
|
describe "time units" $ do
|
|
it "converts correctly" $ do
|
|
seconds 123 `shouldBe` 123
|
|
milliseconds 123 `shouldBe` 0.123
|
|
microseconds 123 `shouldBe` 0.000123
|
|
nanoseconds 123 `shouldBe` 0.000000123
|
|
|
|
it "has a correct Read instance" $ do
|
|
seconds (read "123") `shouldBe` 123
|
|
milliseconds (read "123") `shouldBe` 0.123
|
|
microseconds (read "123") `shouldBe` 0.000123
|
|
nanoseconds (read "123") `shouldBe` 0.000000123
|
|
|
|
it "JSON serializes as proper units" $ do
|
|
toJSON (1 :: Seconds) `shouldBe` Number 1
|
|
decode "1.0" `shouldBe` Just (1 :: Seconds)
|
|
|
|
it "converts with convertDuration" $ do
|
|
convertDuration (2 :: Minutes) `shouldBe` (120 :: NominalDiffTime)
|
|
convertDuration (60 :: Seconds) `shouldBe` (1 :: Minutes)
|
|
|
|
diffTimeSpec :: Spec
|
|
diffTimeSpec =
|
|
describe "DiffTime" $ do
|
|
it "JSON serializes as seconds" $ do
|
|
-- although we would prefer to use Seconds instead...
|
|
toJSON (1 :: DiffTime) `shouldBe` Number 1
|
|
decode "1.0" `shouldBe` Just (1 :: DiffTime)
|