Merge pull request #4625 from urbit/pp/femtosecond

king: remove the "hardware femtosecond clock"
This commit is contained in:
pilfer-pandex 2021-03-22 15:30:07 -04:00 committed by GitHub
commit 1b6ac81073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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