cursor-fuzzy-time 0.0.0.0 → 0.1.0.0
raw patch · 7 files changed
+147/−116 lines, 7 filesdep −containersdep −validity-timedep ~fuzzy-timesetup-changed
Dependencies removed: containers, validity-time
Dependency ranges changed: fuzzy-time
Files
- CHANGELOG.md +7/−0
- LICENSE +1/−1
- Setup.hs +0/−3
- cursor-fuzzy-time.cabal +7/−7
- src/Cursor/FuzzyDay.hs +50/−37
- src/Cursor/FuzzyLocalTime.hs +43/−36
- src/Cursor/FuzzyTimeOfDay.hs +39/−32
+ CHANGELOG.md view
@@ -0,0 +1,7 @@+# Changelog++## [0.1.0.0] - 2023-05-18++### Added++* Compatibility with `fuzzy-time >=0.3`
LICENSE view
@@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2020 Tom Sydney Kerckhove+Copyright (c) 2017-2021 Tom Sydney Kerckhove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
− Setup.hs
@@ -1,3 +0,0 @@-import Distribution.Simple--main = defaultMain
cursor-fuzzy-time.cabal view
@@ -1,22 +1,24 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack ----- hash: c846f27ba93d4449286d198b8b5148a204f0d509b0030b8fe589ff9ad4b0e717+-- hash: fae246a246155198bc4a25f68df69aa964308ea8624df53fe7e2672b7f7bdfdb name: cursor-fuzzy-time-version: 0.0.0.0+version: 0.1.0.0 description: Cursors for the fuzzy-time parser and resolver category: Time homepage: https://github.com/NorfairKing/fuzzy-time author: Tom Sydney Kerckhove maintainer: syd@cs-syd.eu-copyright: Copyright: (c) 2017-2020 Tom Sydney Kerckhove+copyright: Copyright: (c) 2017-2021 Tom Sydney Kerckhove license: MIT license-file: LICENSE build-type: Simple+extra-source-files:+ CHANGELOG.md library exposed-modules:@@ -30,14 +32,12 @@ ghc-options: -Wall build-depends: base >=4.9 && <=5- , containers , cursor , deepseq- , fuzzy-time+ , fuzzy-time >=0.3 , megaparsec , microlens , text , time , validity- , validity-time default-language: Haskell2010
src/Cursor/FuzzyDay.hs view
@@ -2,62 +2,75 @@ {-# LANGUAGE RecordWildCards #-} module Cursor.FuzzyDay- ( FuzzyDayCursor(..)- , emptyFuzzyDayCursor- , makeFuzzyDayCursor- , rebuildFuzzyDayCursor- , fuzzyDayCursorTextCursorL- , fuzzyDayCursorGuess- ) where--import GHC.Generics (Generic)+ ( FuzzyDayCursor (..),+ emptyFuzzyDayCursor,+ makeFuzzyDayCursor,+ rebuildFuzzyDayCursorForwards,+ rebuildFuzzyDayCursorBackwards,+ fuzzyDayCursorTextCursorL,+ fuzzyDayCursorGuessForwards,+ fuzzyDayCursorGuessBackwards,+ )+where +import Control.DeepSeq+import Cursor.Text+import Data.FuzzyTime import Data.Maybe import qualified Data.Text as T-import Control.DeepSeq import Data.Time import Data.Validity--import Text.Megaparsec-+import GHC.Generics (Generic) import Lens.Micro--import Data.FuzzyTime--import Cursor.Text+import Text.Megaparsec data FuzzyDayCursor = FuzzyDayCursor- { fuzzyDayCursorTextCursor :: TextCursor- , fuzzyDayCursorBaseDay :: Day- } deriving (Show, Eq, Generic)+ { fuzzyDayCursorTextCursor :: TextCursor,+ fuzzyDayCursorBaseDay :: Day+ }+ deriving (Show, Eq, Generic) instance Validity FuzzyDayCursor+ instance NFData FuzzyDayCursor emptyFuzzyDayCursor :: Day -> FuzzyDayCursor emptyFuzzyDayCursor d =- FuzzyDayCursor- {fuzzyDayCursorTextCursor = emptyTextCursor, fuzzyDayCursorBaseDay = d}+ FuzzyDayCursor+ { fuzzyDayCursorTextCursor = emptyTextCursor,+ fuzzyDayCursorBaseDay = d+ } makeFuzzyDayCursor :: Day -> FuzzyDayCursor makeFuzzyDayCursor d =- FuzzyDayCursor- { fuzzyDayCursorTextCursor =- fromJust $- makeTextCursor $ T.pack $ formatTime defaultTimeLocale "%F" d- , fuzzyDayCursorBaseDay = d- }+ FuzzyDayCursor+ { fuzzyDayCursorTextCursor =+ fromJust $+ makeTextCursor $+ T.pack $+ formatTime defaultTimeLocale "%F" d,+ fuzzyDayCursorBaseDay = d+ } -rebuildFuzzyDayCursor :: FuzzyDayCursor -> Day-rebuildFuzzyDayCursor fdc@FuzzyDayCursor {..} =- fromMaybe fuzzyDayCursorBaseDay $ fuzzyDayCursorGuess fdc+rebuildFuzzyDayCursorForwards :: FuzzyDayCursor -> Day+rebuildFuzzyDayCursorForwards fdc@FuzzyDayCursor {..} =+ fromMaybe fuzzyDayCursorBaseDay $ fuzzyDayCursorGuessForwards fdc +rebuildFuzzyDayCursorBackwards :: FuzzyDayCursor -> Day+rebuildFuzzyDayCursorBackwards fdc@FuzzyDayCursor {..} =+ fromMaybe fuzzyDayCursorBaseDay $ fuzzyDayCursorGuessBackwards fdc+ fuzzyDayCursorTextCursorL :: Lens' FuzzyDayCursor TextCursor fuzzyDayCursorTextCursorL =- lens fuzzyDayCursorTextCursor $ \fdc tc ->- fdc {fuzzyDayCursorTextCursor = tc}+ lens fuzzyDayCursorTextCursor $ \fdc tc ->+ fdc {fuzzyDayCursorTextCursor = tc} -fuzzyDayCursorGuess :: FuzzyDayCursor -> Maybe Day-fuzzyDayCursorGuess FuzzyDayCursor {..} = do- fd <- parseMaybe fuzzyDayP $ rebuildTextCursor fuzzyDayCursorTextCursor- pure $ resolveDay fuzzyDayCursorBaseDay fd+fuzzyDayCursorGuessForwards :: FuzzyDayCursor -> Maybe Day+fuzzyDayCursorGuessForwards FuzzyDayCursor {..} = do+ fd <- parseMaybe fuzzyDayP $ rebuildTextCursor fuzzyDayCursorTextCursor+ resolveDayForwards fuzzyDayCursorBaseDay fd++fuzzyDayCursorGuessBackwards :: FuzzyDayCursor -> Maybe Day+fuzzyDayCursorGuessBackwards FuzzyDayCursor {..} = do+ fd <- parseMaybe fuzzyDayP $ rebuildTextCursor fuzzyDayCursorTextCursor+ resolveDayBackwards fuzzyDayCursorBaseDay fd
src/Cursor/FuzzyLocalTime.hs view
@@ -2,36 +2,32 @@ {-# LANGUAGE RecordWildCards #-} module Cursor.FuzzyLocalTime- ( FuzzyLocalTimeCursor(..)- , emptyFuzzyLocalTimeCursor- , makeFuzzyLocalTimeCursor- , rebuildFuzzyLocalTimeCursor- , fuzzyLocalTimeCursorTextCursorL- , fuzzyLocalTimeCursorGuess- ) where--import GHC.Generics (Generic)+ ( FuzzyLocalTimeCursor (..),+ emptyFuzzyLocalTimeCursor,+ makeFuzzyLocalTimeCursor,+ rebuildFuzzyLocalTimeCursorForwards,+ rebuildFuzzyLocalTimeCursorBackwards,+ fuzzyLocalTimeCursorTextCursorL,+ fuzzyLocalTimeCursorGuessForwards,+ fuzzyLocalTimeCursorGuessBackwards,+ )+where +import Control.DeepSeq+import Cursor.Text+import Data.FuzzyTime import Data.Maybe import qualified Data.Text as T import Data.Time import Data.Validity--import Control.DeepSeq--import Text.Megaparsec-+import GHC.Generics (Generic) import Lens.Micro--import Data.FuzzyTime--import Cursor.Text+import Text.Megaparsec -data FuzzyLocalTimeCursor =- FuzzyLocalTimeCursor- { fuzzyLocalTimeCursorTextCursor :: TextCursor- , fuzzyLocalTimeCursorBaseLocalTime :: LocalTime- }+data FuzzyLocalTimeCursor = FuzzyLocalTimeCursor+ { fuzzyLocalTimeCursorTextCursor :: TextCursor,+ fuzzyLocalTimeCursorBaseLocalTime :: LocalTime+ } deriving (Show, Eq, Generic) instance Validity FuzzyLocalTimeCursor@@ -41,33 +37,44 @@ emptyFuzzyLocalTimeCursor :: LocalTime -> FuzzyLocalTimeCursor emptyFuzzyLocalTimeCursor d = FuzzyLocalTimeCursor- {fuzzyLocalTimeCursorTextCursor = emptyTextCursor, fuzzyLocalTimeCursorBaseLocalTime = d}+ { fuzzyLocalTimeCursorTextCursor = emptyTextCursor,+ fuzzyLocalTimeCursorBaseLocalTime = d+ } makeFuzzyLocalTimeCursor :: AmbiguousLocalTime -> FuzzyLocalTimeCursor makeFuzzyLocalTimeCursor alt = FuzzyLocalTimeCursor { fuzzyLocalTimeCursorTextCursor = fromJust $- makeTextCursor $- T.pack $- case alt of- OnlyDaySpecified d -> formatTime defaultTimeLocale "%F" d- BothTimeAndDay lt -> formatTime defaultTimeLocale "%F %T%Q" lt- , fuzzyLocalTimeCursorBaseLocalTime =+ makeTextCursor $+ T.pack $+ case alt of+ OnlyDaySpecified d -> formatTime defaultTimeLocale "%F" d+ BothTimeAndDay lt -> formatTime defaultTimeLocale "%F %T%Q" lt,+ fuzzyLocalTimeCursorBaseLocalTime = case alt of OnlyDaySpecified d -> LocalTime d midnight BothTimeAndDay lt -> lt } -rebuildFuzzyLocalTimeCursor :: FuzzyLocalTimeCursor -> AmbiguousLocalTime-rebuildFuzzyLocalTimeCursor fdc@FuzzyLocalTimeCursor {..} =- fromMaybe (BothTimeAndDay fuzzyLocalTimeCursorBaseLocalTime) $ fuzzyLocalTimeCursorGuess fdc+rebuildFuzzyLocalTimeCursorForwards :: FuzzyLocalTimeCursor -> AmbiguousLocalTime+rebuildFuzzyLocalTimeCursorForwards fdc@FuzzyLocalTimeCursor {..} =+ fromMaybe (BothTimeAndDay fuzzyLocalTimeCursorBaseLocalTime) $ fuzzyLocalTimeCursorGuessForwards fdc +rebuildFuzzyLocalTimeCursorBackwards :: FuzzyLocalTimeCursor -> AmbiguousLocalTime+rebuildFuzzyLocalTimeCursorBackwards fdc@FuzzyLocalTimeCursor {..} =+ fromMaybe (BothTimeAndDay fuzzyLocalTimeCursorBaseLocalTime) $ fuzzyLocalTimeCursorGuessBackwards fdc+ fuzzyLocalTimeCursorTextCursorL :: Lens' FuzzyLocalTimeCursor TextCursor fuzzyLocalTimeCursorTextCursorL = lens fuzzyLocalTimeCursorTextCursor $ \fdc tc -> fdc {fuzzyLocalTimeCursorTextCursor = tc} -fuzzyLocalTimeCursorGuess :: FuzzyLocalTimeCursor -> Maybe AmbiguousLocalTime-fuzzyLocalTimeCursorGuess FuzzyLocalTimeCursor {..} = do+fuzzyLocalTimeCursorGuessForwards :: FuzzyLocalTimeCursor -> Maybe AmbiguousLocalTime+fuzzyLocalTimeCursorGuessForwards FuzzyLocalTimeCursor {..} = do ftod <- parseMaybe fuzzyLocalTimeP $ rebuildTextCursor fuzzyLocalTimeCursorTextCursor- pure $ resolveLocalTime fuzzyLocalTimeCursorBaseLocalTime ftod+ resolveLocalTimeForwards fuzzyLocalTimeCursorBaseLocalTime ftod++fuzzyLocalTimeCursorGuessBackwards :: FuzzyLocalTimeCursor -> Maybe AmbiguousLocalTime+fuzzyLocalTimeCursorGuessBackwards FuzzyLocalTimeCursor {..} = do+ ftod <- parseMaybe fuzzyLocalTimeP $ rebuildTextCursor fuzzyLocalTimeCursorTextCursor+ resolveLocalTimeBackwards fuzzyLocalTimeCursorBaseLocalTime ftod
src/Cursor/FuzzyTimeOfDay.hs view
@@ -2,36 +2,32 @@ {-# LANGUAGE RecordWildCards #-} module Cursor.FuzzyTimeOfDay- ( FuzzyTimeOfDayCursor(..)- , emptyFuzzyTimeOfDayCursor- , makeFuzzyTimeOfDayCursor- , rebuildFuzzyTimeOfDayCursor- , fuzzyTimeOfDayCursorTextCursorL- , fuzzyTimeOfDayCursorGuess- ) where--import GHC.Generics (Generic)+ ( FuzzyTimeOfDayCursor (..),+ emptyFuzzyTimeOfDayCursor,+ makeFuzzyTimeOfDayCursor,+ rebuildFuzzyTimeOfDayCursorForwards,+ rebuildFuzzyTimeOfDayCursorBackwards,+ fuzzyTimeOfDayCursorTextCursorL,+ fuzzyTimeOfDayCursorGuessForwards,+ fuzzyTimeOfDayCursorGuessBackwards,+ )+where +import Control.DeepSeq+import Cursor.Text+import Data.FuzzyTime import Data.Maybe import qualified Data.Text as T import Data.Time import Data.Validity--import Control.DeepSeq--import Text.Megaparsec-+import GHC.Generics (Generic) import Lens.Micro--import Data.FuzzyTime--import Cursor.Text+import Text.Megaparsec -data FuzzyTimeOfDayCursor =- FuzzyTimeOfDayCursor- { fuzzyTimeOfDayCursorTextCursor :: TextCursor- , fuzzyTimeOfDayCursorBaseTimeOfDay :: TimeOfDay- }+data FuzzyTimeOfDayCursor = FuzzyTimeOfDayCursor+ { fuzzyTimeOfDayCursorTextCursor :: TextCursor,+ fuzzyTimeOfDayCursorBaseTimeOfDay :: TimeOfDay+ } deriving (Show, Eq, Generic) instance Validity FuzzyTimeOfDayCursor@@ -41,25 +37,36 @@ emptyFuzzyTimeOfDayCursor :: TimeOfDay -> FuzzyTimeOfDayCursor emptyFuzzyTimeOfDayCursor d = FuzzyTimeOfDayCursor- {fuzzyTimeOfDayCursorTextCursor = emptyTextCursor, fuzzyTimeOfDayCursorBaseTimeOfDay = d}+ { fuzzyTimeOfDayCursorTextCursor = emptyTextCursor,+ fuzzyTimeOfDayCursorBaseTimeOfDay = d+ } makeFuzzyTimeOfDayCursor :: TimeOfDay -> FuzzyTimeOfDayCursor makeFuzzyTimeOfDayCursor d = FuzzyTimeOfDayCursor { fuzzyTimeOfDayCursorTextCursor =- fromJust $ makeTextCursor $ T.pack $ formatTime defaultTimeLocale "%T%Q" d- , fuzzyTimeOfDayCursorBaseTimeOfDay = d+ fromJust $ makeTextCursor $ T.pack $ formatTime defaultTimeLocale "%T%Q" d,+ fuzzyTimeOfDayCursorBaseTimeOfDay = d } -rebuildFuzzyTimeOfDayCursor :: FuzzyTimeOfDayCursor -> TimeOfDay-rebuildFuzzyTimeOfDayCursor fdc@FuzzyTimeOfDayCursor {..} =- fromMaybe fuzzyTimeOfDayCursorBaseTimeOfDay $ fuzzyTimeOfDayCursorGuess fdc+rebuildFuzzyTimeOfDayCursorForwards :: FuzzyTimeOfDayCursor -> TimeOfDay+rebuildFuzzyTimeOfDayCursorForwards fdc@FuzzyTimeOfDayCursor {..} =+ fromMaybe fuzzyTimeOfDayCursorBaseTimeOfDay $ fuzzyTimeOfDayCursorGuessForwards fdc +rebuildFuzzyTimeOfDayCursorBackwards :: FuzzyTimeOfDayCursor -> TimeOfDay+rebuildFuzzyTimeOfDayCursorBackwards fdc@FuzzyTimeOfDayCursor {..} =+ fromMaybe fuzzyTimeOfDayCursorBaseTimeOfDay $ fuzzyTimeOfDayCursorGuessBackwards fdc+ fuzzyTimeOfDayCursorTextCursorL :: Lens' FuzzyTimeOfDayCursor TextCursor fuzzyTimeOfDayCursorTextCursorL = lens fuzzyTimeOfDayCursorTextCursor $ \fdc tc -> fdc {fuzzyTimeOfDayCursorTextCursor = tc} -fuzzyTimeOfDayCursorGuess :: FuzzyTimeOfDayCursor -> Maybe TimeOfDay-fuzzyTimeOfDayCursorGuess FuzzyTimeOfDayCursor {..} = do+fuzzyTimeOfDayCursorGuessForwards :: FuzzyTimeOfDayCursor -> Maybe TimeOfDay+fuzzyTimeOfDayCursorGuessForwards FuzzyTimeOfDayCursor {..} = do ftod <- parseMaybe fuzzyTimeOfDayP $ rebuildTextCursor fuzzyTimeOfDayCursorTextCursor- pure $ resolveTimeOfDay fuzzyTimeOfDayCursorBaseTimeOfDay ftod+ resolveTimeOfDayForwards fuzzyTimeOfDayCursorBaseTimeOfDay ftod++fuzzyTimeOfDayCursorGuessBackwards :: FuzzyTimeOfDayCursor -> Maybe TimeOfDay+fuzzyTimeOfDayCursorGuessBackwards FuzzyTimeOfDayCursor {..} = do+ ftod <- parseMaybe fuzzyTimeOfDayP $ rebuildTextCursor fuzzyTimeOfDayCursorTextCursor+ resolveTimeOfDayBackwards fuzzyTimeOfDayCursorBaseTimeOfDay ftod