cursor-fuzzy-time (empty) → 0.0.0.0
raw patch · 6 files changed
+268/−0 lines, 6 filesdep +basedep +containersdep +cursorsetup-changed
Dependencies added: base, containers, cursor, deepseq, fuzzy-time, megaparsec, microlens, text, time, validity, validity-time
Files
- LICENSE +21/−0
- Setup.hs +3/−0
- cursor-fuzzy-time.cabal +43/−0
- src/Cursor/FuzzyDay.hs +63/−0
- src/Cursor/FuzzyLocalTime.hs +73/−0
- src/Cursor/FuzzyTimeOfDay.hs +65/−0
+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2017-2020 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+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ cursor-fuzzy-time.cabal view
@@ -0,0 +1,43 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.33.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: c846f27ba93d4449286d198b8b5148a204f0d509b0030b8fe589ff9ad4b0e717++name: cursor-fuzzy-time+version: 0.0.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+license: MIT+license-file: LICENSE+build-type: Simple++library+ exposed-modules:+ Cursor.FuzzyDay+ Cursor.FuzzyLocalTime+ Cursor.FuzzyTimeOfDay+ other-modules:+ Paths_cursor_fuzzy_time+ hs-source-dirs:+ src/+ ghc-options: -Wall+ build-depends:+ base >=4.9 && <=5+ , containers+ , cursor+ , deepseq+ , fuzzy-time+ , megaparsec+ , microlens+ , text+ , time+ , validity+ , validity-time+ default-language: Haskell2010
+ src/Cursor/FuzzyDay.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE RecordWildCards #-}++module Cursor.FuzzyDay+ ( FuzzyDayCursor(..)+ , emptyFuzzyDayCursor+ , makeFuzzyDayCursor+ , rebuildFuzzyDayCursor+ , fuzzyDayCursorTextCursorL+ , fuzzyDayCursorGuess+ ) where++import GHC.Generics (Generic)++import Data.Maybe+import qualified Data.Text as T+import Control.DeepSeq+import Data.Time+import Data.Validity++import Text.Megaparsec++import Lens.Micro++import Data.FuzzyTime++import Cursor.Text++data FuzzyDayCursor = FuzzyDayCursor+ { fuzzyDayCursorTextCursor :: TextCursor+ , fuzzyDayCursorBaseDay :: Day+ } deriving (Show, Eq, Generic)++instance Validity FuzzyDayCursor+instance NFData FuzzyDayCursor++emptyFuzzyDayCursor :: Day -> FuzzyDayCursor+emptyFuzzyDayCursor d =+ FuzzyDayCursor+ {fuzzyDayCursorTextCursor = emptyTextCursor, fuzzyDayCursorBaseDay = d}++makeFuzzyDayCursor :: Day -> FuzzyDayCursor+makeFuzzyDayCursor d =+ FuzzyDayCursor+ { fuzzyDayCursorTextCursor =+ fromJust $+ makeTextCursor $ T.pack $ formatTime defaultTimeLocale "%F" d+ , fuzzyDayCursorBaseDay = d+ }++rebuildFuzzyDayCursor :: FuzzyDayCursor -> Day+rebuildFuzzyDayCursor fdc@FuzzyDayCursor {..} =+ fromMaybe fuzzyDayCursorBaseDay $ fuzzyDayCursorGuess fdc++fuzzyDayCursorTextCursorL :: Lens' FuzzyDayCursor TextCursor+fuzzyDayCursorTextCursorL =+ lens fuzzyDayCursorTextCursor $ \fdc tc ->+ fdc {fuzzyDayCursorTextCursor = tc}++fuzzyDayCursorGuess :: FuzzyDayCursor -> Maybe Day+fuzzyDayCursorGuess FuzzyDayCursor {..} = do+ fd <- parseMaybe fuzzyDayP $ rebuildTextCursor fuzzyDayCursorTextCursor+ pure $ resolveDay fuzzyDayCursorBaseDay fd
+ src/Cursor/FuzzyLocalTime.hs view
@@ -0,0 +1,73 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE RecordWildCards #-}++module Cursor.FuzzyLocalTime+ ( FuzzyLocalTimeCursor(..)+ , emptyFuzzyLocalTimeCursor+ , makeFuzzyLocalTimeCursor+ , rebuildFuzzyLocalTimeCursor+ , fuzzyLocalTimeCursorTextCursorL+ , fuzzyLocalTimeCursorGuess+ ) where++import GHC.Generics (Generic)++import Data.Maybe+import qualified Data.Text as T+import Data.Time+import Data.Validity++import Control.DeepSeq++import Text.Megaparsec++import Lens.Micro++import Data.FuzzyTime++import Cursor.Text++data FuzzyLocalTimeCursor =+ FuzzyLocalTimeCursor+ { fuzzyLocalTimeCursorTextCursor :: TextCursor+ , fuzzyLocalTimeCursorBaseLocalTime :: LocalTime+ }+ deriving (Show, Eq, Generic)++instance Validity FuzzyLocalTimeCursor++instance NFData FuzzyLocalTimeCursor++emptyFuzzyLocalTimeCursor :: LocalTime -> FuzzyLocalTimeCursor+emptyFuzzyLocalTimeCursor d =+ FuzzyLocalTimeCursor+ {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 =+ case alt of+ OnlyDaySpecified d -> LocalTime d midnight+ BothTimeAndDay lt -> lt+ }++rebuildFuzzyLocalTimeCursor :: FuzzyLocalTimeCursor -> AmbiguousLocalTime+rebuildFuzzyLocalTimeCursor fdc@FuzzyLocalTimeCursor {..} =+ fromMaybe (BothTimeAndDay fuzzyLocalTimeCursorBaseLocalTime) $ fuzzyLocalTimeCursorGuess fdc++fuzzyLocalTimeCursorTextCursorL :: Lens' FuzzyLocalTimeCursor TextCursor+fuzzyLocalTimeCursorTextCursorL =+ lens fuzzyLocalTimeCursorTextCursor $ \fdc tc -> fdc {fuzzyLocalTimeCursorTextCursor = tc}++fuzzyLocalTimeCursorGuess :: FuzzyLocalTimeCursor -> Maybe AmbiguousLocalTime+fuzzyLocalTimeCursorGuess FuzzyLocalTimeCursor {..} = do+ ftod <- parseMaybe fuzzyLocalTimeP $ rebuildTextCursor fuzzyLocalTimeCursorTextCursor+ pure $ resolveLocalTime fuzzyLocalTimeCursorBaseLocalTime ftod
+ src/Cursor/FuzzyTimeOfDay.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE RecordWildCards #-}++module Cursor.FuzzyTimeOfDay+ ( FuzzyTimeOfDayCursor(..)+ , emptyFuzzyTimeOfDayCursor+ , makeFuzzyTimeOfDayCursor+ , rebuildFuzzyTimeOfDayCursor+ , fuzzyTimeOfDayCursorTextCursorL+ , fuzzyTimeOfDayCursorGuess+ ) where++import GHC.Generics (Generic)++import Data.Maybe+import qualified Data.Text as T+import Data.Time+import Data.Validity++import Control.DeepSeq++import Text.Megaparsec++import Lens.Micro++import Data.FuzzyTime++import Cursor.Text++data FuzzyTimeOfDayCursor =+ FuzzyTimeOfDayCursor+ { fuzzyTimeOfDayCursorTextCursor :: TextCursor+ , fuzzyTimeOfDayCursorBaseTimeOfDay :: TimeOfDay+ }+ deriving (Show, Eq, Generic)++instance Validity FuzzyTimeOfDayCursor++instance NFData FuzzyTimeOfDayCursor++emptyFuzzyTimeOfDayCursor :: TimeOfDay -> FuzzyTimeOfDayCursor+emptyFuzzyTimeOfDayCursor d =+ FuzzyTimeOfDayCursor+ {fuzzyTimeOfDayCursorTextCursor = emptyTextCursor, fuzzyTimeOfDayCursorBaseTimeOfDay = d}++makeFuzzyTimeOfDayCursor :: TimeOfDay -> FuzzyTimeOfDayCursor+makeFuzzyTimeOfDayCursor d =+ FuzzyTimeOfDayCursor+ { fuzzyTimeOfDayCursorTextCursor =+ fromJust $ makeTextCursor $ T.pack $ formatTime defaultTimeLocale "%T%Q" d+ , fuzzyTimeOfDayCursorBaseTimeOfDay = d+ }++rebuildFuzzyTimeOfDayCursor :: FuzzyTimeOfDayCursor -> TimeOfDay+rebuildFuzzyTimeOfDayCursor fdc@FuzzyTimeOfDayCursor {..} =+ fromMaybe fuzzyTimeOfDayCursorBaseTimeOfDay $ fuzzyTimeOfDayCursorGuess fdc++fuzzyTimeOfDayCursorTextCursorL :: Lens' FuzzyTimeOfDayCursor TextCursor+fuzzyTimeOfDayCursorTextCursorL =+ lens fuzzyTimeOfDayCursorTextCursor $ \fdc tc -> fdc {fuzzyTimeOfDayCursorTextCursor = tc}++fuzzyTimeOfDayCursorGuess :: FuzzyTimeOfDayCursor -> Maybe TimeOfDay+fuzzyTimeOfDayCursorGuess FuzzyTimeOfDayCursor {..} = do+ ftod <- parseMaybe fuzzyTimeOfDayP $ rebuildTextCursor fuzzyTimeOfDayCursorTextCursor+ pure $ resolveTimeOfDay fuzzyTimeOfDayCursorBaseTimeOfDay ftod