Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions core/src/Pos/Core/Slotting/SlotId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import Universum
import Control.Lens (Iso', iso, lens, makeLensesFor)
import Data.Aeson.TH (defaultOptions, deriveJSON)
import Data.SafeCopy (base, deriveSafeCopySimple)
import Formatting (Format, bprint, build, ords, (%))
import Data.Text (pack)
import Data.Text.Lazy.Builder (fromText)
import Formatting (Format, bprint, build, later, (%))
import qualified Formatting.Buildable as Buildable

import Pos.Binary.Class (Cons (..), Field (..), deriveSimpleBi)
Expand All @@ -50,7 +52,25 @@ data SlotId = SlotId

instance Buildable SlotId where
build SlotId {..} =
bprint (ords%" slot of "%ords%" epoch") (getSlotIndex siSlot) siEpoch
bprint (intords%" slot of "%intords%" epoch")
(getSlotIndex siSlot) (getEpochIndex siEpoch)

-- | temporary reimplementation of 'ords' from "Formatting"
-- because the original function converts the integer value to a real number
intords :: (Show n, Integral n) => Format r (n -> r)
intords = later go
where
fmt = fromText . pack . show
go n
| tens > 3 && tens < 21 = fmt n <> "th"
| otherwise =
fmt n <>
case n `mod` 10 of
1 -> "st"
2 -> "nd"
3 -> "rd"
_ -> "th"
where tens = n `mod` 100

instance NFData SlotId

Expand Down