Skip to content

Commit

Permalink
fix(integral to hex): added
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Yakovenko committed Feb 4, 2019
1 parent 4ad1e2f commit 77f745d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
31 changes: 31 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 2.1
jobs:
build:
docker:
- image: fpco/stack-build:lts
steps:
- checkout
- restore_cache:
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
name: Restore Cached Dependencies
keys:
- cci-demo-haskell-v1-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }}
- run:
name: Resolve/Update Dependencies
command: stack setup
- run:
name: Run tests
command: stack test
- run:
name: Install executable
command: stack install
- save_cache:
name: Cache Dependencies
key: cci-hauth-haskell-v1-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }}
paths:
- ".stack"
- ".stack-work"
- store_artifacts:
# Upload test summary for display in Artifacts: https://circleci.com/docs/2.0/artifacts/
path: ~/.local/bin/hauth
destination: hauth
8 changes: 6 additions & 2 deletions src/Time.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
module Time (hexTime) where
module Time (hexTime, toHex) where

import qualified Data.Time.Clock.POSIX as PT
import Data.Hex (hex)
import qualified Numeric as N

data HexTime = HexTime String deriving Show

-- get unix time in HEX format
hexTime :: IO HexTime
hexTime = fmap (HexTime . hex . show . round . flip (/) 30) PT.getPOSIXTime
hexTime = fmap (HexTime . toHex . round . flip (/) 30) PT.getPOSIXTime

toHex :: Integral a => a -> String
toHex s = N.showHex (toInteger s) ""
3 changes: 1 addition & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ packages:
# (e.g., acme-missiles-0.3)
extra-deps:
- sandi-0.4.3
- location:
git: https://github.com/aleshgo/encdec.git
- git: https://github.com/aleshgo/encdec.git
commit: 47921de2022b5245e7d8f2b2f45f3e6f19f0c3e4
- time-1.8.0.4

Expand Down
5 changes: 3 additions & 2 deletions test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Test.Hspec
import Time (toHex)

main :: IO ()
main = do
Expand All @@ -7,5 +8,5 @@ main = do
spec :: Spec
spec = do
describe "time" $ do
it "unix time to hex" $ do
Decoder.decode (Encoded "" :: Encoded 'Base32) `shouldBe` Right ""
it "toHex" $ do
(toHex 11) `shouldBe` "b"

0 comments on commit 77f745d

Please sign in to comment.