moved module and relicensed
This commit is contained in:
parent
5d97898a7c
commit
2e9f128dea
9 changed files with 13 additions and 12 deletions
|
@ -38,8 +38,9 @@ last = Prelude.last
|
|||
|
||||
{- Attempts to read a value from a String.
|
||||
-
|
||||
- Unlike Text.Read.readMaybe, this ignores leading/trailing whitespace,
|
||||
- and throws away any trailing text after the part that can be read.
|
||||
- Unlike Text.Read.readMaybe, this ignores some trailing text
|
||||
- after the part that can be read. However, if the trailing text looks
|
||||
- like another readable value, it fails.
|
||||
-}
|
||||
readish :: Read a => String -> Maybe a
|
||||
readish s = case reads s of
|
||||
|
|
39
Utility/TimeStamp.hs
Normal file
39
Utility/TimeStamp.hs
Normal file
|
@ -0,0 +1,39 @@
|
|||
{- timestamp parsing and formatting
|
||||
-
|
||||
- Copyright 2015-2016 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- License: BSD-2-clause
|
||||
-}
|
||||
|
||||
{-# LANGUAGE CPP #-}
|
||||
|
||||
module Utility.TimeStamp where
|
||||
|
||||
import Utility.PartialPrelude
|
||||
import Utility.Misc
|
||||
|
||||
import Data.Time.Clock.POSIX
|
||||
import Data.Time
|
||||
import Data.Ratio
|
||||
#if ! MIN_VERSION_time(1,5,0)
|
||||
import System.Locale
|
||||
#endif
|
||||
|
||||
{- Parses how POSIXTime shows itself: "1431286201.113452s"
|
||||
- Also handles the format with no fractional seconds. -}
|
||||
parsePOSIXTime :: String -> Maybe POSIXTime
|
||||
parsePOSIXTime s = do
|
||||
let (sn, sd) = separate (== '.') s
|
||||
n <- readi sn
|
||||
if null sd
|
||||
then return (fromIntegral n)
|
||||
else do
|
||||
d <- readi sd
|
||||
let r = d % (10 ^ (length sd - 1))
|
||||
return (fromIntegral n + fromRational r)
|
||||
where
|
||||
readi :: String -> Maybe Integer
|
||||
readi = readish
|
||||
|
||||
formatPOSIXTime :: String -> POSIXTime -> String
|
||||
formatPOSIXTime fmt t = formatTime defaultTimeLocale fmt (posixSecondsToUTCTime t)
|
Loading…
Add table
Add a link
Reference in a new issue