From 6e845a304d9ed416f16338319a276dcfe9e2f539 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 5 Jun 2020 14:00:23 -0700 Subject: Calculate age automatically --- hledger-fire.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hledger-fire.hs b/hledger-fire.hs index b07f012..68ea5a8 100755 --- a/hledger-fire.hs +++ b/hledger-fire.hs @@ -5,18 +5,19 @@ import Data.Decimal (Decimal(..), DecimalRaw(..), roundTo, divide) import Data.Either (fromRight) import qualified Data.List as List import Data.Text (pack) -import Data.Time.Calendar (Day) +import Data.Time.Calendar (Day, toGregorian) import Data.Time.Clock (UTCTime(utctDay), getCurrentTime) import Hledger data Config = Config - { age :: Decimal -- ^ How the heck do i convert btw Decimal and Integer? + { age :: Decimal } main = do - let cfg = Config { age = 27 } j <- getJournal today <- getCurrentTime >>= return . utctDay + let (thisyear, _, _) = toGregorian today + let cfg = Config { age = (fromInteger thisyear) - 1992 } say [ "savings rate:", show $ savingsRate j today ] say [ "target fund:", show $ targetFund j today ] let n = whenFreedom j today -- cgit v1.2.3