diff --git a/hledger/Hledger/Cli/Commands/Add.hs b/hledger/Hledger/Cli/Commands/Add.hs index 6c6bd02f6..b4a3efab2 100644 --- a/hledger/Hledger/Cli/Commands/Add.hs +++ b/hledger/Hledger/Cli/Commands/Add.hs @@ -29,7 +29,7 @@ import qualified Data.Text as T import qualified Data.Text.IO as T import qualified Data.Text.Lazy 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 Lens.Micro ((^.)) import Safe (headDef, headMay, atMay) @@ -384,7 +384,7 @@ amountAndCommentWizard previnput@PrevInput{..} entrystate@EntryState{..} = do lift skipNonNewlineSpaces assertion <- optional balanceassertionp 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 -- Keep our original comment string from the user to add to the journal Right (_, tags, date1', date2') -> return $ (a, assertion, (com, tags, date1', date2')) diff --git a/hledger/test/add.test b/hledger/test/add.test index 01050c732..988992749 100644 --- a/hledger/test/add.test +++ b/hledger/test/add.test @@ -233,7 +233,20 @@ $ rm -f nosuch.journal; hledger -f nosuch.journal -I add; rm -f nosuch.journal > /Save this transaction to the journal/ >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 # < #