File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed
Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -53,15 +53,13 @@ parseUtc utcText =
5353parseUlidUtcSection :: Text -> Maybe DateTime
5454parseUlidUtcSection encodedUtc = do
5555 let
56- decodedUtc = (Crock. decode . unpack) encodedUtc
56+ decodedUtcMaybe = (Crock. decode . unpack) encodedUtc
5757 getElapsed val = Elapsed $ Seconds $ val `div` 1000
58- getMilliSeconds val =
59- readMaybe $ T. unpack $ T. takeEnd 3 $ show val :: Maybe Int64
6058
61- elapsed <- fmap getElapsed decodedUtc
62- milliSeconds <- getMilliSeconds decodedUtc
59+ elapsed <- fmap getElapsed decodedUtcMaybe
60+ milliSecPart <- fmap ( `mod` 1000 ) decodedUtcMaybe
6361
64- let nanoSeconds = NanoSeconds $ milliSeconds * 1000000
62+ let nanoSeconds = NanoSeconds $ milliSecPart * 1000000
6563
6664 pure $ timeGetDateTimeOfDay $ ElapsedP elapsed nanoSeconds
6765
Original file line number Diff line number Diff line change @@ -24,6 +24,22 @@ import Migrations
2424-- | and therefore the order must not be changed
2525testSuite :: Config -> DateTime -> Sql. Connection -> SpecWith ()
2626testSuite conf now connection = do
27+ describe " Utils" $ do
28+ it " correctly parses beginning of UNIX epoch" $ do
29+ (parseUlidUtcSection " 0000000000" )
30+ `shouldBe`
31+ (Just $ timeGetDateTimeOfDay $ Elapsed 0 )
32+
33+ it " correctly parses 36 ms after UNIX epoch" $ do
34+ (parseUlidUtcSection " 0000000014" )
35+ `shouldBe`
36+ (Just $ timeGetDateTimeOfDay $ ElapsedP 0 36000000 )
37+
38+ it " correctly parses a ULID string" $ do
39+ let ulidText = " 0000000014T4R3JR7HMQNREEW8" :: Text
40+
41+ (fmap show $ parseUlidText ulidText) `shouldBe` (Just ulidText)
42+
2743 describe " TaskLite" $ do
2844 let
2945 -- TODO: Make function more generic
You can’t perform that action at this time.
0 commit comments