1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2025-03-20 04:46:22 +09:00

Darcs change log view

This commit is contained in:
fr33domlover 2016-05-08 14:28:03 +00:00
parent 07b627eb9c
commit 5c288c7fdb
10 changed files with 500 additions and 57 deletions
src/Data
Attoparsec/ByteString
ByteString
Time/Clock

View file

@ -0,0 +1,38 @@
{- This file is part of Vervis.
-
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
-
- Copying is an act of love. Please copy, reuse and share.
-
- The author(s) have dedicated all copyright and related and neighboring
- rights to this software to the public domain worldwide. This software is
- distributed without any warranty.
-
- You should have received a copy of the CC0 Public Domain Dedication along
- with this software. If not, see
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
module Data.Attoparsec.ByteString.Local
( parseFileIncremental
)
where
import Prelude
import Data.Attoparsec.ByteString
import System.IO
import qualified Data.ByteString as B (hGet)
import qualified Data.ByteString.Lazy.Internal as BLI (defaultChunkSize)
parseFileIncremental :: FilePath -> Parser a -> IO (Either String a)
parseFileIncremental file parser =
withBinaryFile file ReadMode $ \ h -> do
let getChunk = B.hGet h BLI.defaultChunkSize
go (Fail _remainder _contexts msg) = return $ Left msg
go (Partial cont) = getChunk >>= go . cont
go (Done _remainder value) = return $ Right value
firstChunk <- getChunk
let firstResult = parse parser firstChunk
go firstResult

View file

@ -13,8 +13,11 @@
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
{-# LANGUAGE CPP #-}
module Data.ByteString.Local
( fromDecimal
, stripPrefix
)
where
@ -38,3 +41,11 @@ fromDecimal s =
if (not . B.null) s && B.all (\ b -> 48 <= b && b <= 57) s
then Just $ B.foldl' (\ n b -> 10 * n + fromIntegral b - 48) 0 s
else Nothing
#if !(MIN_VERSION_bytestring(0,10,8))
stripPrefix :: ByteString -> ByteString -> Maybe ByteString
stripPrefix p b =
if p `B.isPrefixOf` b
then Just $ B.drop (B.length p) b
else Nothing
#endif

View file

@ -0,0 +1,44 @@
{- This file is part of Vervis.
-
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
-
- Copying is an act of love. Please copy, reuse and share.
-
- The author(s) have dedicated all copyright and related and neighboring
- rights to this software to the public domain worldwide. This software is
- distributed without any warranty.
-
- You should have received a copy of the CC0 Public Domain Dedication along
- with this software. If not, see
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
module Data.Time.Clock.Local
(
)
where
import Prelude
import Data.Time.Clock
import Data.EventTime.Local
instance IntervalToEventTime NominalDiffTime where
intervalToEventTime t
| t < 0 = Never
| t == 0 = Now
| t < 60 * 60 = Ago $ TimeAgo Second s
| t < 60 * 60 * 24 = Ago $ TimeAgo Minute $ s `div` 60
| t < 60 * 60 * 24 * 365 = Ago $ TimeAgo Hour $ s `div` (60 * 60)
| otherwise = Ago $ TimeAgo Day $ s `div` (60 * 60 * 24)
where
s = floor t
instance SpecToEventTime UTCTime where
specToEventTime t = do
now <- getCurrentTime
return $ intervalToEventTime $ now `diffUTCTime` t
specsToEventTimes ts = do
now <- getCurrentTime
return $ fmap (\ t -> intervalToEventTime $ now `diffUTCTime` t) ts