From 27e11b20b06f2f2dbfb56c0998a63169b4b8abc4 Mon Sep 17 00:00:00 2001 From: Joris Date: Wed, 8 Nov 2017 23:47:26 +0100 Subject: Use a better project structure --- common/src/Common/Util/Text.hs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 common/src/Common/Util/Text.hs (limited to 'common/src/Common/Util') diff --git a/common/src/Common/Util/Text.hs b/common/src/Common/Util/Text.hs new file mode 100644 index 0000000..4af7a4c --- /dev/null +++ b/common/src/Common/Util/Text.hs @@ -0,0 +1,41 @@ +module Common.Util.Text + ( unaccent + ) where + +import Data.Text (Text) +import qualified Data.Text as T + +unaccent :: Text -> Text +unaccent = T.map unaccentChar + +unaccentChar :: Char -> Char +unaccentChar c = case c of + 'à' -> 'a' + 'á' -> 'a' + 'â' -> 'a' + 'ã' -> 'a' + 'ä' -> 'a' + 'ç' -> 'c' + 'è' -> 'e' + 'é' -> 'e' + 'ê' -> 'e' + 'ë' -> 'e' + 'ì' -> 'i' + 'í' -> 'i' + 'î' -> 'i' + 'ï' -> 'i' + 'ñ' -> 'n' + 'ò' -> 'o' + 'ó' -> 'o' + 'ô' -> 'o' + 'õ' -> 'o' + 'ö' -> 'o' + 'š' -> 's' + 'ù' -> 'u' + 'ú' -> 'u' + 'û' -> 'u' + 'ü' -> 'u' + 'ý' -> 'y' + 'ÿ' -> 'y' + 'ž' -> 'z' + _ -> c -- cgit v1.2.3 From 5a63f7be9375e3ab888e4232dd7ef72c2f1ffae1 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 13 Nov 2017 23:56:40 +0100 Subject: Setup stylish-haskell --- common/src/Common/Util/Text.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common/src/Common/Util') diff --git a/common/src/Common/Util/Text.hs b/common/src/Common/Util/Text.hs index 4af7a4c..7e5c8c2 100644 --- a/common/src/Common/Util/Text.hs +++ b/common/src/Common/Util/Text.hs @@ -2,7 +2,7 @@ module Common.Util.Text ( unaccent ) where -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text as T unaccent :: Text -> Text @@ -38,4 +38,4 @@ unaccentChar c = case c of 'ý' -> 'y' 'ÿ' -> 'y' 'ž' -> 'z' - _ -> c + _ -> c -- cgit v1.2.3 From 49426740e8e0c59040f4f3721a658f225572582b Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 28 Nov 2017 09:11:19 +0100 Subject: Add search for payments --- common/src/Common/Util/Text.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'common/src/Common/Util') diff --git a/common/src/Common/Util/Text.hs b/common/src/Common/Util/Text.hs index 7e5c8c2..b49fc55 100644 --- a/common/src/Common/Util/Text.hs +++ b/common/src/Common/Util/Text.hs @@ -1,10 +1,16 @@ module Common.Util.Text - ( unaccent + ( search + , unaccent ) where import Data.Text (Text) import qualified Data.Text as T +search :: Text -> Text -> Bool +search s t = + (format s) `T.isInfixOf` (format t) + where format = T.toLower . unaccent + unaccent :: Text -> Text unaccent = T.map unaccentChar -- cgit v1.2.3 From 33b85b7f12798f5762d940ed5c30f775cdd7b751 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 28 Jan 2018 12:13:09 +0100 Subject: WIP --- common/src/Common/Util/Time.hs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 common/src/Common/Util/Time.hs (limited to 'common/src/Common/Util') diff --git a/common/src/Common/Util/Time.hs b/common/src/Common/Util/Time.hs new file mode 100644 index 0000000..9ab7ab5 --- /dev/null +++ b/common/src/Common/Util/Time.hs @@ -0,0 +1,26 @@ +module Common.Util.Time + ( timeToDay + , parseDay + ) where + +import Data.Text (Text) +import qualified Data.Text as T +import Data.Time (UTCTime) +import qualified Data.Time as Time +import Data.Time.Calendar (Day) +import Data.Time.LocalTime +import qualified Text.Read as T + +timeToDay :: UTCTime -> IO Day +timeToDay time = localDay . (flip utcToLocalTime time) <$> getTimeZone time + +parseDay :: Text -> Maybe Day +parseDay str = do + (d, m, y) <- + case T.splitOn str "/" of + [d, m, y] -> Just (d, m, y) + _ -> Nothing + d' <- T.readMaybe . T.unpack $ d + m' <- T.readMaybe . T.unpack $ m + y' <- T.readMaybe . T.unpack $ y + return $ Time.fromGregorian y' m' d' -- cgit v1.2.3 From 50fb8fa48d1c4881da20b4ecf6d68a772301e713 Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 30 Oct 2018 18:04:58 +0100 Subject: Update table when adding or removing a payment --- common/src/Common/Util/Time.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'common/src/Common/Util') diff --git a/common/src/Common/Util/Time.hs b/common/src/Common/Util/Time.hs index 9ab7ab5..6240720 100644 --- a/common/src/Common/Util/Time.hs +++ b/common/src/Common/Util/Time.hs @@ -16,9 +16,9 @@ timeToDay time = localDay . (flip utcToLocalTime time) <$> getTimeZone time parseDay :: Text -> Maybe Day parseDay str = do - (d, m, y) <- - case T.splitOn str "/" of - [d, m, y] -> Just (d, m, y) + (y, m, d) <- + case T.splitOn "-" str of + [y, m, d] -> Just (y, m, d) _ -> Nothing d' <- T.readMaybe . T.unpack $ d m' <- T.readMaybe . T.unpack $ m -- cgit v1.2.3 From 2741f47ef7b87255203bc2f7f7b2b9140c70b8f0 Mon Sep 17 00:00:00 2001 From: Joris Date: Thu, 1 Nov 2018 13:14:25 +0100 Subject: Implementing client side validation --- common/src/Common/Util/Validation.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 common/src/Common/Util/Validation.hs (limited to 'common/src/Common/Util') diff --git a/common/src/Common/Util/Validation.hs b/common/src/Common/Util/Validation.hs new file mode 100644 index 0000000..f195d95 --- /dev/null +++ b/common/src/Common/Util/Validation.hs @@ -0,0 +1,13 @@ +module Common.Util.Validation + ( isSuccess + , isFailure + ) where + +import Data.Validation (Validation (Failure, Success)) + +isSuccess :: forall a b. Validation a b -> Bool +isSuccess (Failure _) = False +isSuccess (Success _) = True + +isFailure :: forall a b. Validation a b -> Bool +isFailure = not . isSuccess -- cgit v1.2.3 From fc8be14dd0089eb12b78af7aaaecd8ed57896677 Mon Sep 17 00:00:00 2001 From: Joris Date: Wed, 7 Aug 2019 21:27:59 +0200 Subject: Update category according to payment in add overlay --- common/src/Common/Util/Text.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'common/src/Common/Util') diff --git a/common/src/Common/Util/Text.hs b/common/src/Common/Util/Text.hs index b49fc55..d7f1db4 100644 --- a/common/src/Common/Util/Text.hs +++ b/common/src/Common/Util/Text.hs @@ -1,15 +1,16 @@ module Common.Util.Text ( search - , unaccent + , formatSearch ) where import Data.Text (Text) import qualified Data.Text as T search :: Text -> Text -> Bool -search s t = - (format s) `T.isInfixOf` (format t) - where format = T.toLower . unaccent +search s t = (formatSearch s) `T.isInfixOf` (formatSearch t) + +formatSearch :: Text -> Text +formatSearch = T.toLower . unaccent unaccent :: Text -> Text unaccent = T.map unaccentChar -- cgit v1.2.3 From c0ea63f8c1a8c7123b78798cec99726b113fb1f3 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 17 Nov 2019 18:08:28 +0100 Subject: Optimize and refactor payments --- common/src/Common/Util/Text.hs | 1 + 1 file changed, 1 insertion(+) (limited to 'common/src/Common/Util') diff --git a/common/src/Common/Util/Text.hs b/common/src/Common/Util/Text.hs index d7f1db4..0f9c187 100644 --- a/common/src/Common/Util/Text.hs +++ b/common/src/Common/Util/Text.hs @@ -1,6 +1,7 @@ module Common.Util.Text ( search , formatSearch + , unaccent ) where import Data.Text (Text) -- cgit v1.2.3