Handle partial dates in added transactions

This commit is contained in:
Michael Rees 2025-05-31 21:22:55 -05:00 committed by Simon Michael
parent b042115692
commit 19a2a70f2d
2 changed files with 16 additions and 3 deletions

View File

@ -29,7 +29,7 @@ import qualified Data.Text as T
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.IO as TL import qualified Data.Text.Lazy.IO as TL
import Data.Time.Calendar (Day) import Data.Time.Calendar (Day, toGregorian)
import Data.Time.Format (formatTime, defaultTimeLocale) import Data.Time.Format (formatTime, defaultTimeLocale)
import Lens.Micro ((^.)) import Lens.Micro ((^.))
import Safe (headDef, headMay, atMay) import Safe (headDef, headMay, atMay)
@ -384,7 +384,7 @@ amountAndCommentWizard previnput@PrevInput{..} entrystate@EntryState{..} = do
lift skipNonNewlineSpaces lift skipNonNewlineSpaces
assertion <- optional balanceassertionp assertion <- optional balanceassertionp
com <- T.pack <$> fromMaybe "" `fmap` optional (char ';' >> many anySingle) com <- T.pack <$> fromMaybe "" `fmap` optional (char ';' >> many anySingle)
case rtp (postingcommentp Nothing) (T.cons ';' com) of case rtp (postingcommentp (let (y,_,_) = toGregorian esDefDate in Just y)) (T.cons ';' com) of
Left err -> fail $ customErrorBundlePretty err Left err -> fail $ customErrorBundlePretty err
-- Keep our original comment string from the user to add to the journal -- Keep our original comment string from the user to add to the journal
Right (_, tags, date1', date2') -> return $ (a, assertion, (com, tags, date1', date2')) Right (_, tags, date1', date2') -> return $ (a, assertion, (com, tags, date1', date2'))

View File

@ -233,7 +233,20 @@ $ rm -f nosuch.journal; hledger -f nosuch.journal -I add; rm -f nosuch.journal
> /Save this transaction to the journal/ > /Save this transaction to the journal/
>2 // >2 //
## 17. shouldn't add decimals if there aren't any ## 17. Partial dates in added transaction
<
2025-05-01
x
a
10 USD ; date:5/2
b
-10 USD
.
$ rm -f nosuch.journal; hledger -f nosuch.journal add; rm -f nosuch.journal
> /Save this transaction to the journal/
>2 //
## 18. shouldn't add decimals if there aren't any
## printf '\n\na\n1\nb\n' | hledger -f /dev/null add ## printf '\n\na\n1\nb\n' | hledger -f /dev/null add
# < # <
# #