File tree 2 files changed +20
-6
lines changed
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -53,15 +53,13 @@ parseUtc utcText =
53
53
parseUlidUtcSection :: Text -> Maybe DateTime
54
54
parseUlidUtcSection encodedUtc = do
55
55
let
56
- decodedUtc = (Crock. decode . unpack) encodedUtc
56
+ decodedUtcMaybe = (Crock. decode . unpack) encodedUtc
57
57
getElapsed val = Elapsed $ Seconds $ val `div` 1000
58
- getMilliSeconds val =
59
- readMaybe $ T. unpack $ T. takeEnd 3 $ show val :: Maybe Int64
60
58
61
- elapsed <- fmap getElapsed decodedUtc
62
- milliSeconds <- getMilliSeconds decodedUtc
59
+ elapsed <- fmap getElapsed decodedUtcMaybe
60
+ milliSecPart <- fmap ( `mod` 1000 ) decodedUtcMaybe
63
61
64
- let nanoSeconds = NanoSeconds $ milliSeconds * 1000000
62
+ let nanoSeconds = NanoSeconds $ milliSecPart * 1000000
65
63
66
64
pure $ timeGetDateTimeOfDay $ ElapsedP elapsed nanoSeconds
67
65
Original file line number Diff line number Diff line change @@ -24,6 +24,22 @@ import Migrations
24
24
-- | and therefore the order must not be changed
25
25
testSuite :: Config -> DateTime -> Sql. Connection -> SpecWith ()
26
26
testSuite 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
+
27
43
describe " TaskLite" $ do
28
44
let
29
45
-- TODO: Make function more generic
You can’t perform that action at this time.
0 commit comments