mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-05 22:03:50 +03:00
Merge pull request #4625 from urbit/pp/femtosecond
king: remove the "hardware femtosecond clock"
This commit is contained in:
commit
1b6ac81073
@ -17,22 +17,22 @@ import Data.Time.Clock.System (systemToUTCTime, utcToSystemTime)
|
||||
import Data.Time.LocalTime (TimeOfDay(..), timeToTimeOfDay)
|
||||
import Data.Word (Word64)
|
||||
import Text.Printf (printf)
|
||||
import Urbit.Noun (FromNoun, ToNoun)
|
||||
import Urbit.Noun (deriveToNoun, FromNoun, ToNoun(..))
|
||||
|
||||
|
||||
-- Types -----------------------------------------------------------------------
|
||||
|
||||
newtype Gap = Gap { _fractoSecs :: Integer }
|
||||
deriving newtype (Eq, Ord, Show, Num, ToNoun, FromNoun)
|
||||
deriving newtype (Eq, Ord, Show, Num, FromNoun)
|
||||
|
||||
newtype Unix = Unix { _sinceUnixEpoch :: Gap }
|
||||
deriving newtype (Eq, Ord, Show, ToNoun, FromNoun)
|
||||
deriving newtype (Eq, Ord, Show, FromNoun)
|
||||
|
||||
newtype Wen = Wen { _sinceUrbitEpoch :: Gap }
|
||||
deriving newtype (Eq, Ord, Show, Num, ToNoun, FromNoun)
|
||||
deriving newtype (Eq, Ord, Show, Num, FromNoun)
|
||||
|
||||
newtype Date = MkDate { _dateWen :: Wen }
|
||||
deriving newtype (Eq, Ord, Num, ToNoun, FromNoun)
|
||||
deriving newtype (Eq, Ord, Num, FromNoun)
|
||||
|
||||
|
||||
-- Record Lenses ---------------------------------------------------------------
|
||||
@ -45,6 +45,20 @@ makeLenses ''Date
|
||||
|
||||
-- Instances -------------------------------------------------------------------
|
||||
|
||||
instance ToNoun Gap where
|
||||
toNoun (reducePrecision -> Gap fs) = toNoun fs
|
||||
|
||||
-- | Produce a Gap with fewer digits after the binary point, more
|
||||
-- appropriately capturing the precision our clock gives us.
|
||||
reducePrecision :: Gap -> Gap
|
||||
reducePrecision (Gap fs) = Gap (chop fs)
|
||||
where
|
||||
chop fs = shiftL (shiftR fs 32) 32
|
||||
|
||||
deriveToNoun ''Unix
|
||||
deriveToNoun ''Wen
|
||||
deriveToNoun ''Date
|
||||
|
||||
instance Show Date where
|
||||
show (MkDate wen) = if fs == 0
|
||||
then printf "~%i.%u.%u..%02u.%02u.%02u" y m d h min s
|
||||
|
Loading…
Reference in New Issue
Block a user