While it's often rather straight forward to get the Unix time as an integer in other languages2, in Haskell there's a bit of type tetris involved.
- getPOSIXTime gives me a POSIXTime, which is an alias for NominalDiffTime.
NominalDiffTimeimplements RealFrac and can thus be converted to anything implementing Integral (I wanted it as
NominalDiffTimealso implements Num, so if the timestamp needs better precision than seconds it's easy to do (I needed milliseconds).
The combination of the above is something like
truncate <$> getPOSIXTime
In my case the full function of writing the timestamp to a file looks like this
writeTimestampFile :: MonadIO m => Path Abs File -> m () writeTimestampFile afn = liftIO $ do truncate @_ @Int64 . (* 1000) <$> getPOSIXTime >>= writeFile (fromAbsFile afn) . show