diff --git a/hledger-lib/Hledger/Data/Dates.hs b/hledger-lib/Hledger/Data/Dates.hs index 04e9a72a6..30f61d310 100644 --- a/hledger-lib/Hledger/Data/Dates.hs +++ b/hledger-lib/Hledger/Data/Dates.hs @@ -650,25 +650,58 @@ parsedate s = fromMaybe (error' $ "could not parse date \"" ++ s ++ "\"") -- #endif {-| -Parse a date in any of the formats allowed in ledger's period expressions, -and maybe some others: - -> 2004 -> 2004/10 -> 2004/10/1 -> 10/1 -> 21 -> october, oct -> yesterday, today, tomorrow -> this/next/last week/day/month/quarter/year - -Returns a SmartDate, to be converted to a full date later (see fixSmartDate). +Parse a date in any of the formats allowed in Ledger's period expressions, and some others. Assumes any text in the parse stream has been lowercased. +Returns a SmartDate, to be converted to a full date later (see fixSmartDate). + +Examples: + +> 2004 (start of year, which must have 4+ digits) +> 2004/10 (start of month, which must be 1-12) +> 2004/10/1 (exact date, day must be 1-31) +> 10/1 (month and day in current year) +> 21 (day in current month) +> october, oct (start of month in current year) +> yesterday, today, tomorrow (-1, 0, 1 days from today) +> last/this/next day/week/month/quarter/year (-1, 0, 1 periods from the current period) +> 20181201 (8 digit YYYYMMDD with valid year month and day) +> 201812 (6 digit YYYYMM with valid year and month) + +Note malformed digit sequences might give surprising results: + +> 201813 (6 digits with an invalid month is parsed as start of 6-digit year) +> 20181301 (8 digits with an invalid month is parsed as start of 8-digit year) +> 20181232 (8 digits with an invalid day gives an error) +> 201801012 (9+ digits beginning with a valid YYYYMMDD gives an error) + +Eg: + +YYYYMMDD is parsed as year-month-date if those parts are valid +(>=4 digits, 1-12, and 1-31 respectively): +>>> parsewith (smartdate <* eof) "20181201" +Right ("2018","12","01") + +YYYYMM is parsed as year-month-01 if year and month are valid: +>>> parsewith (smartdate <* eof) "201804" +Right ("2018","04","01") + +With an invalid month, it's parsed as a year: +>>> parsewith (smartdate <* eof) "201813" +Right ("201813","","") + +A 9+ digit number beginning with valid YYYYMMDD gives an error: +>>> parsewith (smartdate <* eof) "201801012" +Left (TrivialError (SourcePos {sourceName = "", sourceLine = Pos 1, sourceColumn = Pos 9} :| []) (Just (Tokens ('2' :| ""))) (fromList [EndOfInput])) + +Big numbers not beginning with a valid YYYYMMDD are parsed as a year: +>>> parsewith (smartdate <* eof) "201813012" +Right ("201813012","","") + -} smartdate :: SimpleTextParser SmartDate smartdate = do -- XXX maybe obscures date errors ? see ledgerdate - (y,m,d) <- choice' [yyyymmdd, ymd, ym, md, y, d, month, mon, today, yesterday, tomorrow, lastthisnextthing] + (y,m,d) <- choice' [yyyymmdd, yyyymm, ymd, ym, md, y, d, month, mon, today, yesterday, tomorrow, lastthisnextthing] return (y,m,d) -- | Like smartdate, but there must be nothing other than whitespace after the date. @@ -703,6 +736,13 @@ yyyymmdd = do failIfInvalidDay d return (y,m,d) +yyyymm :: SimpleTextParser SmartDate +yyyymm = do + y <- count 4 digitChar + m <- count 2 digitChar + failIfInvalidMonth m + return (y,m,"01") + ymd :: SimpleTextParser SmartDate ymd = do y <- some digitChar @@ -946,6 +986,9 @@ periodexprdatespan rdate = choice $ map try [ justdatespan rdate ] +-- | +-- -- >>> parsewith (doubledatespan (parsedate "2018/01/01") <* eof) "20180101-201804" +-- Right DateSpan 2018/01/01-2018/04/01 doubledatespan :: Day -> SimpleTextParser DateSpan doubledatespan rdate = do optional (string "from" >> skipMany spacenonewline) diff --git a/hledger-lib/Hledger/Query.hs b/hledger-lib/Hledger/Query.hs index 527366135..baad59073 100644 --- a/hledger-lib/Hledger/Query.hs +++ b/hledger-lib/Hledger/Query.hs @@ -306,6 +306,7 @@ tests_parseQueryTerm = [ "real:1" `gives` (Left $ Real True) "date:2008" `gives` (Left $ Date $ DateSpan (Just $ parsedate "2008/01/01") (Just $ parsedate "2009/01/01")) "date:from 2012/5/17" `gives` (Left $ Date $ DateSpan (Just $ parsedate "2012/05/17") Nothing) + "date:20180101-201804" `gives` (Left $ Date $ DateSpan (Just $ parsedate "2018/01/01") (Just $ parsedate "2018/04/01")) "inacct:a" `gives` (Right $ QueryOptInAcct "a") "tag:a" `gives` (Left $ Tag "a" Nothing) "tag:a=some value" `gives` (Left $ Tag "a" (Just "some value")) diff --git a/hledger/hledger.1 b/hledger/hledger.1 index c4c2e6d1c..fe631940e 100644 --- a/hledger/hledger.1 +++ b/hledger/hledger.1 @@ -493,49 +493,83 @@ Examples: tab(@); l l. T{ -\f[C]2009/1/1\f[], \f[C]2009/01/01\f[], \f[C]2009\-1\-1\f[], -\f[C]2009.1.1\f[] +\f[C]2004/10/1\f[], \f[C]2004\-01\-01\f[], \f[C]2004.9.1\f[] T}@T{ -simple dates, several separators allowed +exact date, several separators allowed. +Year is 4+ digits, month is 1\-12, day is 1\-31 T} T{ -\f[C]2009/1\f[], \f[C]2009\f[] +\f[C]2004\f[] T}@T{ -same as above \- a missing day or month defaults to 1 +start of year T} T{ -\f[C]1/1\f[], \f[C]january\f[], \f[C]jan\f[], \f[C]this\ year\f[] +\f[C]2004/10\f[] T}@T{ -relative dates, meaning january 1 of the current year +start of month T} T{ -\f[C]next\ year\f[] +\f[C]10/1\f[] T}@T{ -january 1 of next year +month and day in current year T} T{ -\f[C]this\ month\f[] +\f[C]21\f[] T}@T{ -the 1st of the current month +day in current month T} T{ -\f[C]this\ week\f[] +\f[C]october,\ oct\f[] T}@T{ -the most recent monday +start of month in current year T} T{ -\f[C]last\ week\f[] +\f[C]yesterday,\ today,\ tomorrow\f[] T}@T{ -the monday of the week before this one +\-1, 0, 1 days from today T} T{ -\f[C]lastweek\f[] +\f[C]last/this/next\ day/week/month/quarter/year\f[] T}@T{ -spaces are optional +\-1, 0, 1 periods from the current period T} T{ -\f[C]today\f[], \f[C]yesterday\f[], \f[C]tomorrow\f[] +\f[C]20181201\f[] T}@T{ +8 digit YYYYMMDD with valid year month and day +T} +T{ +\f[C]201812\f[] +T}@T{ +6 digit YYYYMM with valid year and month +T} +.TE +.PP +Counterexamples \- malformed digit sequences might give surprising +results: +.PP +.TS +tab(@); +l l. +T{ +\f[C]201813\f[] +T}@T{ +6 digits with an invalid month is parsed as start of 6\-digit year +T} +T{ +\f[C]20181301\f[] +T}@T{ +8 digits with an invalid month is parsed as start of 8\-digit year +T} +T{ +\f[C]20181232\f[] +T}@T{ +8 digits with an invalid day gives an error +T} +T{ +\f[C]201801012\f[] +T}@T{ +9+ digits beginning with a valid YYYYMMDD gives an error T} .TE .SS Report start & end date diff --git a/hledger/hledger.info b/hledger/hledger.info index ee48104f0..d74b870db 100644 --- a/hledger/hledger.info +++ b/hledger/hledger.info @@ -390,15 +390,25 @@ omitted (defaulting to 1). Examples: -'2009/1/1', '2009/01/01', '2009-1-1', '2009.1.1' simple dates, several separators allowed -'2009/1', '2009' same as above - a missing day or month defaults to 1 -'1/1', 'january', 'jan', 'this year' relative dates, meaning january 1 of the current year -'next year' january 1 of next year -'this month' the 1st of the current month -'this week' the most recent monday -'last week' the monday of the week before this one -'lastweek' spaces are optional -'today', 'yesterday', 'tomorrow' +'2004/10/1', '2004-01-01', '2004.9.1' exact date, several separators allowed. Year is 4+ digits, month is 1-12, day is 1-31 +'2004' start of year +'2004/10' start of month +'10/1' month and day in current year +'21' day in current month +'october, oct' start of month in current year +'yesterday, today, tomorrow' -1, 0, 1 days from today +'last/this/next -1, 0, 1 periods from the current period +day/week/month/quarter/year' +'20181201' 8 digit YYYYMMDD with valid year month and day +'201812' 6 digit YYYYMM with valid year and month + + Counterexamples - malformed digit sequences might give surprising +results: + +'201813' 6 digits with an invalid month is parsed as start of 6-digit year +'20181301' 8 digits with an invalid month is parsed as start of 8-digit year +'20181232' 8 digits with an invalid day gives an error +'201801012' 9+ digits beginning with a valid YYYYMMDD gives an error  File: hledger.info, Node: Report start & end date, Next: Report intervals, Prev: Smart dates, Up: OPTIONS @@ -2411,117 +2421,117 @@ Node: Input files9632 Ref: #input-files9768 Node: Smart dates11738 Ref: #smart-dates11879 -Node: Report start & end date12858 -Ref: #report-start-end-date13028 -Node: Report intervals14093 -Ref: #report-intervals14256 -Node: Period expressions14657 -Ref: #period-expressions14817 -Node: Depth limiting18774 -Ref: #depth-limiting18918 -Node: Pivoting19260 -Ref: #pivoting19378 -Node: Cost21054 -Ref: #cost21162 -Node: Market value21280 -Ref: #market-value21415 -Node: Combining -B and -V22598 -Ref: #combining--b-and--v22761 -Node: Output destination22908 -Ref: #output-destination23070 -Node: Output format23353 -Ref: #output-format23505 -Node: Regular expressions23890 -Ref: #regular-expressions24027 -Node: QUERIES25388 -Ref: #queries25490 -Node: COMMANDS29457 -Ref: #commands29569 -Node: accounts30551 -Ref: #accounts30649 -Node: activity31895 -Ref: #activity32005 -Node: add32365 -Ref: #add32464 -Node: balance35125 -Ref: #balance35236 -Node: Flat mode38740 -Ref: #flat-mode38865 -Node: Depth limited balance reports39285 -Ref: #depth-limited-balance-reports39486 -Node: Multicolumn balance reports39906 -Ref: #multicolumn-balance-reports40101 -Node: Budgets44790 -Ref: #budgets44937 -Node: Custom balance output48906 -Ref: #custom-balance-output49068 -Node: Colour support51234 -Ref: #colour-support51366 -Node: balancesheet51539 -Ref: #balancesheet51675 -Node: balancesheetequity53986 -Ref: #balancesheetequity54135 -Node: cashflow54672 -Ref: #cashflow54800 -Node: check-dates56923 -Ref: #check-dates57050 -Node: check-dupes57167 -Ref: #check-dupes57291 -Node: close57428 -Ref: #close57535 -Node: help57865 -Ref: #help57965 -Node: import59039 -Ref: #import59153 -Node: incomestatement59883 -Ref: #incomestatement60017 -Node: prices62421 -Ref: #prices62536 -Node: print62579 -Ref: #print62689 -Node: print-unique67583 -Ref: #print-unique67709 -Node: register67777 -Ref: #register67904 -Node: Custom register output72405 -Ref: #custom-register-output72534 -Node: register-match73764 -Ref: #register-match73898 -Node: rewrite74081 -Ref: #rewrite74198 -Node: stats74267 -Ref: #stats74370 -Node: tags75240 -Ref: #tags75338 -Node: test75574 -Ref: #test75658 -Node: ADD-ON COMMANDS76026 -Ref: #add-on-commands76136 -Node: Official add-ons77423 -Ref: #official-add-ons77563 -Node: api77650 -Ref: #api77739 -Node: ui77791 -Ref: #ui77890 -Node: web77948 -Ref: #web78037 -Node: Third party add-ons78083 -Ref: #third-party-add-ons78258 -Node: diff78393 -Ref: #diff78490 -Node: iadd78589 -Ref: #iadd78703 -Node: interest78786 -Ref: #interest78907 -Node: irr79002 -Ref: #irr79100 -Node: Experimental add-ons79178 -Ref: #experimental-add-ons79330 -Node: autosync79610 -Ref: #autosync79721 -Node: chart79960 -Ref: #chart80079 -Node: check80150 -Ref: #check80252 +Node: Report start & end date13285 +Ref: #report-start-end-date13455 +Node: Report intervals14520 +Ref: #report-intervals14683 +Node: Period expressions15084 +Ref: #period-expressions15244 +Node: Depth limiting19201 +Ref: #depth-limiting19345 +Node: Pivoting19687 +Ref: #pivoting19805 +Node: Cost21481 +Ref: #cost21589 +Node: Market value21707 +Ref: #market-value21842 +Node: Combining -B and -V23025 +Ref: #combining--b-and--v23188 +Node: Output destination23335 +Ref: #output-destination23497 +Node: Output format23780 +Ref: #output-format23932 +Node: Regular expressions24317 +Ref: #regular-expressions24454 +Node: QUERIES25815 +Ref: #queries25917 +Node: COMMANDS29884 +Ref: #commands29996 +Node: accounts30978 +Ref: #accounts31076 +Node: activity32322 +Ref: #activity32432 +Node: add32792 +Ref: #add32891 +Node: balance35552 +Ref: #balance35663 +Node: Flat mode39167 +Ref: #flat-mode39292 +Node: Depth limited balance reports39712 +Ref: #depth-limited-balance-reports39913 +Node: Multicolumn balance reports40333 +Ref: #multicolumn-balance-reports40528 +Node: Budgets45217 +Ref: #budgets45364 +Node: Custom balance output49333 +Ref: #custom-balance-output49495 +Node: Colour support51661 +Ref: #colour-support51793 +Node: balancesheet51966 +Ref: #balancesheet52102 +Node: balancesheetequity54413 +Ref: #balancesheetequity54562 +Node: cashflow55099 +Ref: #cashflow55227 +Node: check-dates57350 +Ref: #check-dates57477 +Node: check-dupes57594 +Ref: #check-dupes57718 +Node: close57855 +Ref: #close57962 +Node: help58292 +Ref: #help58392 +Node: import59466 +Ref: #import59580 +Node: incomestatement60310 +Ref: #incomestatement60444 +Node: prices62848 +Ref: #prices62963 +Node: print63006 +Ref: #print63116 +Node: print-unique68010 +Ref: #print-unique68136 +Node: register68204 +Ref: #register68331 +Node: Custom register output72832 +Ref: #custom-register-output72961 +Node: register-match74191 +Ref: #register-match74325 +Node: rewrite74508 +Ref: #rewrite74625 +Node: stats74694 +Ref: #stats74797 +Node: tags75667 +Ref: #tags75765 +Node: test76001 +Ref: #test76085 +Node: ADD-ON COMMANDS76453 +Ref: #add-on-commands76563 +Node: Official add-ons77850 +Ref: #official-add-ons77990 +Node: api78077 +Ref: #api78166 +Node: ui78218 +Ref: #ui78317 +Node: web78375 +Ref: #web78464 +Node: Third party add-ons78510 +Ref: #third-party-add-ons78685 +Node: diff78820 +Ref: #diff78917 +Node: iadd79016 +Ref: #iadd79130 +Node: interest79213 +Ref: #interest79334 +Node: irr79429 +Ref: #irr79527 +Node: Experimental add-ons79605 +Ref: #experimental-add-ons79757 +Node: autosync80037 +Ref: #autosync80148 +Node: chart80387 +Ref: #chart80506 +Node: check80577 +Ref: #check80679  End Tag Table diff --git a/hledger/hledger.txt b/hledger/hledger.txt index eaa7c5a50..e3f2148b4 100644 --- a/hledger/hledger.txt +++ b/hledger/hledger.txt @@ -332,35 +332,56 @@ OPTIONS Examples: - 2009/1/1, 2009/01/01, simple dates, several sep- - 2009-1-1, 2009.1.1 arators allowed - 2009/1, 2009 same as above - a missing - day or month defaults to 1 - 1/1, january, jan, relative dates, meaning - this year january 1 of the current - year - next year january 1 of next year - this month the 1st of the current - month - this week the most recent monday - last week the monday of the week - before this one - lastweek spaces are optional - today, yesterday, tomorrow + + + 2004/10/1, 2004-01-01, exact date, several sepa- + 2004.9.1 rators allowed. Year is + 4+ digits, month is 1-12, + day is 1-31 + 2004 start of year + 2004/10 start of month + 10/1 month and day in current + year + 21 day in current month + october, oct start of month in current + year + yesterday, today, tomorrow -1, 0, 1 days from today + last/this/next day/week/month/quar- -1, 0, 1 periods from the + ter/year current period + 20181201 8 digit YYYYMMDD with + valid year month and day + 201812 6 digit YYYYMM with valid + year and month + + Counterexamples - malformed digit sequences might give surprising + results: + + + 201813 6 digits with an invalid + month is parsed as start + of 6-digit year + 20181301 8 digits with an invalid + month is parsed as start + of 8-digit year + 20181232 8 digits with an invalid + day gives an error + 201801012 9+ digits beginning with a + valid YYYYMMDD gives an + error Report start & end date - Most hledger reports show the full span of time represented by the + Most hledger reports show the full span of time represented by the journal data, by default. So, the effective report start and end dates - will be the earliest and latest transaction or posting dates found in + will be the earliest and latest transaction or posting dates found in the journal. - Often you will want to see a shorter time span, such as the current - month. You can specify a start and/or end date using -b/--begin, + Often you will want to see a shorter time span, such as the current + month. You can specify a start and/or end date using -b/--begin, -e/--end, -p/--period or a date: query (described below). All of these - accept the smart date syntax. One important thing to be aware of when - specifying end dates: as in Ledger, end dates are exclusive, so you + accept the smart date syntax. One important thing to be aware of when + specifying end dates: as in Ledger, end dates are exclusive, so you need to write the date after the last day you want to include. Examples: @@ -370,10 +391,10 @@ OPTIONS 2016 -e 12/1 end at the start of decem- ber 1st of the current - year (11/30 will be the + year (11/30 will be the last date included) - -b thismonth all transactions on or - after the 1st of the cur- + -b thismonth all transactions on or + after the 1st of the cur- rent month -p thismonth all transactions in the current month @@ -385,24 +406,24 @@ OPTIONS Report intervals A report interval can be specified so that commands like register, bal- - ance and activity will divide their reports into multiple subperiods. - The basic intervals can be selected with one of -D/--daily, - -W/--weekly, -M/--monthly, -Q/--quarterly, or -Y/--yearly. More com- - plex intervals may be specified with a period expression. Report + ance and activity will divide their reports into multiple subperiods. + The basic intervals can be selected with one of -D/--daily, + -W/--weekly, -M/--monthly, -Q/--quarterly, or -Y/--yearly. More com- + plex intervals may be specified with a period expression. Report intervals can not be specified with a query, currently. Period expressions - The -p/--period option accepts period expressions, a shorthand way of - expressing a start date, end date, and/or report interval all at once. + The -p/--period option accepts period expressions, a shorthand way of + expressing a start date, end date, and/or report interval all at once. - Here's a basic period expression specifying the first quarter of 2009. - Note, hledger always treats start dates as inclusive and end dates as + Here's a basic period expression specifying the first quarter of 2009. + Note, hledger always treats start dates as inclusive and end dates as exclusive: -p "from 2009/1/1 to 2009/4/1" - Keywords like "from" and "to" are optional, and so are the spaces, as - long as you don't run two dates together. "to" can also be written as + Keywords like "from" and "to" are optional, and so are the spaces, as + long as you don't run two dates together. "to" can also be written as "-". These are equivalent to the above: @@ -410,7 +431,7 @@ OPTIONS -p2009/1/1to2009/4/1 -p2009/1/1-2009/4/1 - Dates are smart dates, so if the current year is 2009, the above can + Dates are smart dates, so if the current year is 2009, the above can also be written as: @@ -426,25 +447,25 @@ OPTIONS 1, 2009 -p "from 2009/1" the same -p "from 2009" the same - -p "to 2009" everything before january + -p "to 2009" everything before january 1, 2009 - A single date with no "from" or "to" defines both the start and end + A single date with no "from" or "to" defines both the start and end date like so: - -p "2009" the year 2009; equivalent + -p "2009" the year 2009; equivalent to "2009/1/1 to 2010/1/1" - -p "2009/1" the month of jan; equiva- + -p "2009/1" the month of jan; equiva- lent to "2009/1/1 to 2009/2/1" - -p "2009/1/1" just that day; equivalent + -p "2009/1/1" just that day; equivalent to "2009/1/1 to 2009/1/2" - The argument of -p can also begin with, or be, a report interval - expression. The basic report intervals are daily, weekly, monthly, + The argument of -p can also begin with, or be, a report interval + expression. The basic report intervals are daily, weekly, monthly, quarterly, or yearly, which have the same effect as the -D,-W,-M,-Q, or - -Y flags. Between report interval and start/end dates (if any), the + -Y flags. Between report interval and start/end dates (if any), the word in is optional. Examples: @@ -452,23 +473,23 @@ OPTIONS -p "monthly in 2008" -p "quarterly" - Note that weekly, monthly, quarterly and yearly intervals will always + Note that weekly, monthly, quarterly and yearly intervals will always start on the first day on week, month, quarter or year accordingly, and - will end on the last day of same period, even if associated period + will end on the last day of same period, even if associated period expression specifies different explicit start and end date. For example: -p "weekly from 2009/1/1 to 2009/4/1" - - starts on 2008/12/29, closest preceed- + starts on 2008/12/29, closest preceed- ing Monday - -p "monthly in 2008/11/25" - starts on + -p "monthly in 2008/11/25" - starts on 2018/11/01 -p "quar- terly from 2009-05-05 to 2009-06-01" - - starts on 2009/04/01, ends on - 2009/06/30, which are first and last + starts on 2009/04/01, ends on + 2009/06/30, which are first and last days of Q2 2009 -p "yearly from 2009-12-29" - starts on 2009/01/01, first day of 2009 @@ -477,7 +498,7 @@ OPTIONS biweekly, bimonthly, every day|week|month|quarter|year, every N days|weeks|months|quarters|years. - All of these will start on the first day of the requested period and + All of these will start on the first day of the requested period and end on the last one, as described above. Examples: @@ -486,13 +507,13 @@ OPTIONS -p "bimonthly from 2008" - periods will have boundaries on 2008/01/01, 2008/03/01, ... - -p "every 2 weeks" - starts on closest + -p "every 2 weeks" - starts on closest preceeding Monday -p "every 5 month from 2009/03" - peri- ods will have boundaries on 2009/03/01, 2009/08/01, ... - If you want intervals that start on arbitrary day of your choosing and + If you want intervals that start on arbitrary day of your choosing and span a week, month or year, you need to use any of the following: every Nth day of week, every , every Nth day [of month], @@ -502,47 +523,47 @@ OPTIONS Examples: - -p "every 2nd day of week" - periods + -p "every 2nd day of week" - periods will go from Tue to Tue -p "every Tue" - same -p "every 15th day" - period boundaries will be on 15th of each month - -p "every 2nd Monday" - period bound- - aries will be on second Monday of each + -p "every 2nd Monday" - period bound- + aries will be on second Monday of each month - -p "every 11/05" - yearly periods with + -p "every 11/05" - yearly periods with boundaries on 5th of Nov -p "every 5th Nov" - same -p "every Nov 5th" - same - Show historical balances at end of 15th each month (N is exclusive end + Show historical balances at end of 15th each month (N is exclusive end date): hledger balance -H -p "every 16th day" - Group postings from start of wednesday to end of next tuesday (N is + Group postings from start of wednesday to end of next tuesday (N is start date and exclusive end date): hledger register checking -p "every 3rd day of week" Depth limiting With the --depth N option (short form: -N), commands like account, bal- - ance and register will show only the uppermost accounts in the account - tree, down to level N. Use this when you want a summary with less - detail. This flag has the same effect as a depth: query argument (so + ance and register will show only the uppermost accounts in the account + tree, down to level N. Use this when you want a summary with less + detail. This flag has the same effect as a depth: query argument (so -2, --depth=2 or depth:2 are basically equivalent). Pivoting Normally hledger sums amounts, and organizes them in a hierarchy, based - on account name. The --pivot FIELD option causes it to sum and orga- - nize hierarchy based on the value of some other field instead. FIELD + on account name. The --pivot FIELD option causes it to sum and orga- + nize hierarchy based on the value of some other field instead. FIELD can be: code, description, payee, note, or the full name (case insensi- tive) of any tag. As with account names, values containing colon:sepa- rated:parts will be displayed hierarchically in reports. - --pivot is a general option affecting all reports; you can think of + --pivot is a general option affecting all reports; you can think of hledger transforming the journal before any other processing, replacing - every posting's account name with the value of the specified field on + every posting's account name with the value of the specified field on that posting, inheriting it from the transaction or using a blank value if it's not present. @@ -568,7 +589,7 @@ OPTIONS -------------------- 0 - One way to show only amounts with a member: value (using a query, + One way to show only amounts with a member: value (using a query, described below): $ hledger balance --pivot member tag:member=. @@ -576,7 +597,7 @@ OPTIONS -------------------- -2 EUR - Another way (the acct: query matches against the pivoted "account + Another way (the acct: query matches against the pivoted "account name"): $ hledger balance --pivot member acct:. @@ -585,17 +606,17 @@ OPTIONS -2 EUR Cost - The -B/--cost flag converts amounts to their cost at transaction time, + The -B/--cost flag converts amounts to their cost at transaction time, if they have a transaction price specified. Market value - The -V/--value flag converts reported amounts to their current market - value. Specifically, when there is a market price (P directive) for - the amount's commodity, dated on or before today's date (or the report - end date if specified), the amount will be converted to the price's + The -V/--value flag converts reported amounts to their current market + value. Specifically, when there is a market price (P directive) for + the amount's commodity, dated on or before today's date (or the report + end date if specified), the amount will be converted to the price's commodity. - When there are multiple applicable P directives, -V chooses the most + When there are multiple applicable P directives, -V chooses the most recent one, or in case of equal dates, the last-parsed one. For example: @@ -627,25 +648,25 @@ OPTIONS $ hledger -f t.j bal euros -V -e 2016/12/21 $103.00 assets:euros - Currently, hledger's -V only uses market prices recorded with P direc- + Currently, hledger's -V only uses market prices recorded with P direc- tives, not transaction prices (unlike Ledger). Combining -B and -V - Using -B/-cost and -V/-value together is currently allowed, but the + Using -B/-cost and -V/-value together is currently allowed, but the results are probably not meaningful. Let us know if you find a use for this. Output destination - Some commands (print, register, stats, the balance commands) can write - their output to a destination other than the console. This is con- + Some commands (print, register, stats, the balance commands) can write + their output to a destination other than the console. This is con- trolled by the -o/--output-file option. $ hledger balance -o - # write to stdout (the default) $ hledger balance -o FILE # write to FILE Output format - Some commands can write their output in other formats. Eg print and - register can output CSV, and the balance commands can output CSV or + Some commands can write their output in other formats. Eg print and + register can output CSV, and the balance commands can output CSV or HTML. This is controlled by the -O/--output-format option, or by spec- ifying a .csv or .html file extension with -o/--output-file. @@ -655,56 +676,56 @@ OPTIONS Regular expressions hledger uses regular expressions in a number of places: - o query terms, on the command line and in the hledger-web search form: + o query terms, on the command line and in the hledger-web search form: REGEX, desc:REGEX, cur:REGEX, tag:...=REGEX o CSV rules conditional blocks: if REGEX ... - o account alias directives and options: alias /REGEX/ = REPLACEMENT, + o account alias directives and options: alias /REGEX/ = REPLACEMENT, --alias /REGEX/=REPLACEMENT - hledger's regular expressions come from the regex-tdfa library. In + hledger's regular expressions come from the regex-tdfa library. In general they: o are case insensitive - o are infix matching (do not need to match the entire thing being + o are infix matching (do not need to match the entire thing being matched) o are POSIX extended regular expressions o also support GNU word boundaries (\<, \>, \b, \B) - o and parenthesised capturing groups and numeric backreferences in + o and parenthesised capturing groups and numeric backreferences in replacement strings o do not support mode modifiers like (?s) Some things to note: - o In the alias directive and --alias option, regular expressions must - be enclosed in forward slashes (/REGEX/). Elsewhere in hledger, + o In the alias directive and --alias option, regular expressions must + be enclosed in forward slashes (/REGEX/). Elsewhere in hledger, these are not required. - o In queries, to match a regular expression metacharacter like $ as a - literal character, prepend a backslash. Eg to search for amounts + o In queries, to match a regular expression metacharacter like $ as a + literal character, prepend a backslash. Eg to search for amounts with the dollar sign in hledger-web, write cur:\$. - o On the command line, some metacharacters like $ have a special mean- + o On the command line, some metacharacters like $ have a special mean- ing to the shell and so must be escaped at least once more. See Spe- cial characters. QUERIES - One of hledger's strengths is being able to quickly report on precise - subsets of your data. Most commands accept an optional query expres- - sion, written as arguments after the command name, to filter the data - by date, account name or other criteria. The syntax is similar to a + One of hledger's strengths is being able to quickly report on precise + subsets of your data. Most commands accept an optional query expres- + sion, written as arguments after the command name, to filter the data + by date, account name or other criteria. The syntax is similar to a web search: one or more space-separated search terms, quotes to enclose - whitespace, prefixes to match specific fields, a not: prefix to negate + whitespace, prefixes to match specific fields, a not: prefix to negate the match. - We do not yet support arbitrary boolean combinations of search terms; - instead most commands show transactions/postings/accounts which match + We do not yet support arbitrary boolean combinations of search terms; + instead most commands show transactions/postings/accounts which match (or negatively match): o any of the description terms AND @@ -725,32 +746,32 @@ QUERIES o match all the other terms. - The following kinds of search terms can be used. Remember these can + The following kinds of search terms can be used. Remember these can also be prefixed with not:, eg to exclude a particular subaccount. - REGEX match account names by this regular expression. (No prefix is + REGEX match account names by this regular expression. (No prefix is equivalent to acct:). acct:REGEX same as above amt:N, amt:N, amt:>=N - match postings with a single-commodity amount that is equal to, - less than, or greater than N. (Multi-commodity amounts are not + match postings with a single-commodity amount that is equal to, + less than, or greater than N. (Multi-commodity amounts are not tested, and will always match.) The comparison has two modes: if N is preceded by a + or - sign (or is 0), the two signed numbers - are compared. Otherwise, the absolute magnitudes are compared, + are compared. Otherwise, the absolute magnitudes are compared, ignoring sign. code:REGEX match by transaction code (eg check number) cur:REGEX - match postings or transactions including any amounts whose cur- - rency/commodity symbol is fully matched by REGEX. (For a par- + match postings or transactions including any amounts whose cur- + rency/commodity symbol is fully matched by REGEX. (For a par- tial match, use .*REGEX.*). Note, to match characters which are regex-significant, like the dollar sign ($), you need to prepend - \. And when using the command line you need to add one more + \. And when using the command line you need to add one more level of quoting to hide it from the shell, so eg do: hledger print cur:'\$' or hledger print cur:\\$. @@ -759,20 +780,20 @@ QUERIES date:PERIODEXPR match dates within the specified period. PERIODEXPR is a period - expression (with no report interval). Examples: date:2016, - date:thismonth, date:2000/2/1-2/15, date:lastweek-. If the - --date2 command line flag is present, this matches secondary + expression (with no report interval). Examples: date:2016, + date:thismonth, date:2000/2/1-2/15, date:lastweek-. If the + --date2 command line flag is present, this matches secondary dates instead. date2:PERIODEXPR match secondary dates within the specified period. depth:N - match (or display, depending on command) accounts at or above + match (or display, depending on command) accounts at or above this depth note:REGEX - match transaction notes (part of description right of |, or + match transaction notes (part of description right of |, or whole description when there's no |) payee:REGEX @@ -786,38 +807,38 @@ QUERIES match unmarked, pending, or cleared transactions respectively tag:REGEX[=REGEX] - match by tag name, and optionally also by tag value. Note a - tag: query is considered to match a transaction if it matches - any of the postings. Also remember that postings inherit the + match by tag name, and optionally also by tag value. Note a + tag: query is considered to match a transaction if it matches + any of the postings. Also remember that postings inherit the tags of their parent transaction. The following special search term is used automatically in hledger-web, only: inacct:ACCTNAME - tells hledger-web to show the transaction register for this + tells hledger-web to show the transaction register for this account. Can be filtered further with acct etc. Some of these can also be expressed as command-line options (eg depth:2 - is equivalent to --depth 2). Generally you can mix options and query - arguments, and the resulting query will be their intersection (perhaps + is equivalent to --depth 2). Generally you can mix options and query + arguments, and the resulting query will be their intersection (perhaps excluding the -p/--period option). COMMANDS - hledger provides a number of subcommands; hledger with no arguments + hledger provides a number of subcommands; hledger with no arguments shows a list. If you install additional hledger-* packages, or if you put programs or - scripts named hledger-NAME in your PATH, these will also be listed as + scripts named hledger-NAME in your PATH, these will also be listed as subcommands. - Run a subcommand by writing its name as first argument (eg + Run a subcommand by writing its name as first argument (eg hledger incomestatement). You can also write one of the standard short - aliases displayed in parentheses in the command list (hledger b), or + aliases displayed in parentheses in the command list (hledger b), or any any unambiguous prefix of a command name (hledger inc). - Here are all the builtin commands in alphabetical order. See also - hledger for a more organised command list, and hledger CMD -h for + Here are all the builtin commands in alphabetical order. See also + hledger for a more organised command list, and hledger CMD -h for detailed command help. accounts @@ -835,12 +856,12 @@ COMMANDS --drop=N in flat mode: omit N leading account name parts - This command lists account names, either declared with account direc- - tives (-declared), posted to (-used), or both (default). With query - arguments, only matched account names and account names referenced by - matched postings are shown. It shows a flat list by default. With - --tree, it uses indentation to show the account hierarchy. In flat - mode you can add --drop N to omit the first few account name compo- + This command lists account names, either declared with account direc- + tives (-declared), posted to (-used), or both (default). With query + arguments, only matched account names and account names referenced by + matched postings are shown. It shows a flat list by default. With + --tree, it uses indentation to show the account hierarchy. In flat + mode you can add --drop N to omit the first few account name compo- nents. Account names can be depth-clipped with --depth N or depth:N. Examples: @@ -883,8 +904,8 @@ COMMANDS activity Show an ascii barchart of posting counts per interval. - The activity command displays an ascii histogram showing transaction - counts by day, week, month or other reporting interval (by day is the + The activity command displays an ascii histogram showing transaction + counts by day, week, month or other reporting interval (by day is the default). With query arguments, it counts only matched transactions. $ hledger activity --quarterly @@ -897,24 +918,24 @@ COMMANDS Prompt for transactions and add them to the journal. --no-new-accounts - don't allow creating new accounts; helps prevent typos when + don't allow creating new accounts; helps prevent typos when entering account names - Many hledger users edit their journals directly with a text editor, or - generate them from CSV. For more interactive data entry, there is the - add command, which prompts interactively on the console for new trans- - actions, and appends them to the journal file (if there are multiple + Many hledger users edit their journals directly with a text editor, or + generate them from CSV. For more interactive data entry, there is the + add command, which prompts interactively on the console for new trans- + actions, and appends them to the journal file (if there are multiple -f FILE options, the first file is used.) Existing transactions are not - changed. This is the only hledger command that writes to the journal + changed. This is the only hledger command that writes to the journal file. To use it, just run hledger add and follow the prompts. You can add as - many transactions as you like; when you are finished, enter . or press + many transactions as you like; when you are finished, enter . or press control-d or control-c to exit. Features: - o add tries to provide useful defaults, using the most similar recent + o add tries to provide useful defaults, using the most similar recent transaction (by description) as a template. o You can also set the initial defaults with command line arguments. @@ -922,20 +943,20 @@ COMMANDS o Readline-style edit keys can be used during data entry. o The tab key will auto-complete whenever possible - accounts, descrip- - tions, dates (yesterday, today, tomorrow). If the input area is + tions, dates (yesterday, today, tomorrow). If the input area is empty, it will insert the default value. - o If the journal defines a default commodity, it will be added to any + o If the journal defines a default commodity, it will be added to any bare numbers entered. o A parenthesised transaction code may be entered following a date. o Comments and tags may be entered following a description or amount. - o If you make a mistake, enter < at any prompt to restart the transac- + o If you make a mistake, enter < at any prompt to restart the transac- tion. - o Input prompts are displayed in a different colour when the terminal + o Input prompts are displayed in a different colour when the terminal supports it. Example (see the tutorial for a detailed explanation): @@ -972,7 +993,7 @@ COMMANDS show balance change in each period (default) --cumulative - show balance change accumulated across periods (in multicolumn + show balance change accumulated across periods (in multicolumn reports) -H --historical @@ -1007,14 +1028,14 @@ COMMANDS select the output format. Supported formats: txt, csv, html. -o FILE --output-file=FILE - write output to FILE. A file extension matching one of the + write output to FILE. A file extension matching one of the above formats selects that format. --pretty-tables use unicode to display prettier tables. --sort-amount - sort by amount instead of account code/name (in flat mode). + sort by amount instead of account code/name (in flat mode). With multiple columns, sorts by the row total, or by row average if that is displayed. @@ -1022,13 +1043,13 @@ COMMANDS display all amounts with reversed sign --budget - show performance compared to budget goals defined by periodic + show performance compared to budget goals defined by periodic transactions --show-unbudgeted with -budget, show unbudgeted accounts also - The balance command displays accounts and balances. It is hledger's + The balance command displays accounts and balances. It is hledger's most featureful and versatile command. $ hledger balance @@ -1045,28 +1066,28 @@ COMMANDS -------------------- 0 - More precisely, the balance command shows the change to each account's + More precisely, the balance command shows the change to each account's balance caused by all (matched) postings. In the common case where you - do not filter by date and your journal sets the correct opening bal- + do not filter by date and your journal sets the correct opening bal- ances, this is the same as the account's ending balance. - By default, accounts are displayed hierarchically, with subaccounts - indented below their parent. At each level of the tree, accounts are - sorted by account code if any, then by account name. Or with + By default, accounts are displayed hierarchically, with subaccounts + indented below their parent. At each level of the tree, accounts are + sorted by account code if any, then by account name. Or with -S/--sort-amount, by their balance amount. "Boring" accounts, which contain a single interesting subaccount and no - balance of their own, are elided into the following line for more com- + balance of their own, are elided into the following line for more com- pact output. (Not yet supported in tabular reports.) Use --no-elide to prevent this. - Account balances are "inclusive" - they include the balances of any + Account balances are "inclusive" - they include the balances of any subaccounts. - Accounts which have zero balance (and no non-zero subaccounts) are + Accounts which have zero balance (and no non-zero subaccounts) are omitted. Use -E/--empty to show them. - A final total is displayed by default; use -N/--no-total to suppress + A final total is displayed by default; use -N/--no-total to suppress it: $ hledger balance -p 2008/6 expenses --no-total @@ -1076,9 +1097,9 @@ COMMANDS Flat mode To see a flat list of full account names instead of the default hierar- - chical display, use --flat. In this mode, accounts (unless + chical display, use --flat. In this mode, accounts (unless depth-clipped) show their "exclusive" balance, excluding any subaccount - balances. In this mode, you can also use --drop N to omit the first + balances. In this mode, you can also use --drop N to omit the first few account name components. $ hledger balance -p 2008/6 expenses -N --flat --drop 1 @@ -1086,9 +1107,9 @@ COMMANDS $1 supplies Depth limited balance reports - With --depth N, balance shows accounts only to the specified depth. - This is very useful to show a complex charts of accounts in less - detail. In flat mode, balances from accounts below the depth limit + With --depth N, balance shows accounts only to the specified depth. + This is very useful to show a complex charts of accounts in less + detail. In flat mode, balances from accounts below the depth limit will be shown as part of a parent account at the depth limit. $ hledger balance -N --depth 1 @@ -1098,12 +1119,12 @@ COMMANDS $1 liabilities Multicolumn balance reports - With a reporting interval, multiple balance columns will be shown, one - for each report period. There are three types of multi-column balance + With a reporting interval, multiple balance columns will be shown, one + for each report period. There are three types of multi-column balance report, showing different information: 1. By default: each column shows the sum of postings in that period, ie - the account's change of balance in that period. This is useful eg + the account's change of balance in that period. This is useful eg for a monthly income statement: $ hledger balance --quarterly income expenses -E @@ -1118,8 +1139,8 @@ COMMANDS -------------------++--------------------------------- || $-1 $1 0 0 - 2. With --cumulative: each column shows the ending balance for that - period, accumulating the changes across periods, starting from 0 at + 2. With --cumulative: each column shows the ending balance for that + period, accumulating the changes across periods, starting from 0 at the report start date: $ hledger balance --quarterly income expenses -E --cumulative @@ -1135,8 +1156,8 @@ COMMANDS || $-1 0 0 0 3. With --historical/-H: each column shows the actual historical ending - balance for that period, accumulating the changes across periods, - starting from the actual balance at the report start date. This is + balance for that period, accumulating the changes across periods, + starting from the actual balance at the report start date. This is useful eg for a multi-period balance sheet, and when you are showing only the data after a certain start date: @@ -1152,26 +1173,26 @@ COMMANDS ----------------------++------------------------------------- || 0 0 0 - Multi-column balance reports display accounts in flat mode by default; + Multi-column balance reports display accounts in flat mode by default; to see the hierarchy, use --tree. - With a reporting interval (like --quarterly above), the report - start/end dates will be adjusted if necessary so that they encompass + With a reporting interval (like --quarterly above), the report + start/end dates will be adjusted if necessary so that they encompass the displayed report periods. This is so that the first and last peri- ods will be "full" and comparable to the others. - The -E/--empty flag does two things in multicolumn balance reports: - first, the report will show all columns within the specified report - period (without -E, leading and trailing columns with all zeroes are - not shown). Second, all accounts which existed at the report start - date will be considered, not just the ones with activity during the + The -E/--empty flag does two things in multicolumn balance reports: + first, the report will show all columns within the specified report + period (without -E, leading and trailing columns with all zeroes are + not shown). Second, all accounts which existed at the report start + date will be considered, not just the ones with activity during the report period (use -E to include low-activity accounts which would oth- erwise would be omitted). The -T/--row-total flag adds an additional column showing the total for each row. - The -A/--average flag adds a column showing the average value in each + The -A/--average flag adds a column showing the average value in each row. Here's an example of all three: @@ -1193,13 +1214,13 @@ COMMANDS # Average is rounded to the dollar here since all journal amounts are Budgets - With --budget and a report interval, all periodic transactions in your - journal with that interval, active during the requested report period, - are interpreted as recurring budget goals for the specified accounts - (and subaccounts), and the report will show the difference between + With --budget and a report interval, all periodic transactions in your + journal with that interval, active during the requested report period, + are interpreted as recurring budget goals for the specified accounts + (and subaccounts), and the report will show the difference between actual and budgeted balances. - For example, you can take average monthly expenses in the common + For example, you can take average monthly expenses in the common expense categories to construct a minimal monthly budget: ;; Budget @@ -1258,8 +1279,8 @@ COMMANDS -----------------------++------------------------------------------------- || 0 0 - Accounts with no budget goals (not mentioned in the periodic transac- - tions) will be aggregated under , unless you add the + Accounts with no budget goals (not mentioned in the periodic transac- + tions) will be aggregated under , unless you add the --show-unbudgeted flag to display them normally: $ hledger balance --budget --show-unbudgeted @@ -1278,13 +1299,13 @@ COMMANDS || 0 0 Note -budget first arrived in hledger in 1.5 and is still pretty young; - join the discussions on mail list and issue tracker to help us refine + join the discussions on mail list and issue tracker to help us refine it. For more examples, see Budgeting and Forecasting. Custom balance output - You can customise the layout of simple (non-tabular) balance reports + You can customise the layout of simple (non-tabular) balance reports with --format FMT: $ hledger balance --format "%20(account) %12(total)" @@ -1302,7 +1323,7 @@ COMMANDS 0 The FMT format string (plus a newline) specifies the formatting applied - to each account/balance pair. It may contain any suitable text, with + to each account/balance pair. It may contain any suitable text, with data fields interpolated like so: %[MIN][.MAX](FIELDNAME) @@ -1313,14 +1334,14 @@ COMMANDS o FIELDNAME must be enclosed in parentheses, and can be one of: - o depth_spacer - a number of spaces equal to the account's depth, or + o depth_spacer - a number of spaces equal to the account's depth, or if MIN is specified, MIN * depth spaces. o account - the account's name o total - the account's balance/posted total, right justified - Also, FMT can begin with an optional prefix to control how multi-com- + Also, FMT can begin with an optional prefix to control how multi-com- modity amounts are rendered: o %_ - render on multiple lines, bottom-aligned (the default) @@ -1329,7 +1350,7 @@ COMMANDS o %, - render on one line, comma-separated - There are some quirks. Eg in one-line mode, %(depth_spacer) has no + There are some quirks. Eg in one-line mode, %(depth_spacer) has no effect, instead %(account) has indentation built in. Experimentation may be needed to get pleasing results. @@ -1337,17 +1358,17 @@ COMMANDS o %(total) - the account's total - o %-20.20(account) - the account's name, left justified, padded to 20 + o %-20.20(account) - the account's name, left justified, padded to 20 characters and clipped at 20 characters - o %,%-50(account) %25(total) - account name padded to 50 characters, - total padded to 20 characters, with multiple commodities rendered on + o %,%-50(account) %25(total) - account name padded to 50 characters, + total padded to 20 characters, with multiple commodities rendered on one line - o %20(total) %2(depth_spacer)%-(account) - the default format for the + o %20(total) %2(depth_spacer)%-(account) - the default format for the single-column balance report - This command also supports output destination and output format selec- + This command also supports output destination and output format selec- tion. Colour support @@ -1359,11 +1380,11 @@ COMMANDS balancesheet This command displays a simple balance sheet, showing historical ending - balances of asset and liability accounts (ignoring any report begin - date). It assumes that these accounts are under a top-level asset or - liability account (case insensitive, plural forms also allowed). Note - this report shows all account balances with normal positive sign (like - conventional financial statements, unlike balance/print/register) + balances of asset and liability accounts (ignoring any report begin + date). It assumes that these accounts are under a top-level asset or + liability account (case insensitive, plural forms also allowed). Note + this report shows all account balances with normal positive sign (like + conventional financial statements, unlike balance/print/register) (experimental). (bs) --change @@ -1371,7 +1392,7 @@ COMMANDS balances --cumulative - show balance change accumulated across periods (in multicolumn + show balance change accumulated across periods (in multicolumn reports), instead of historical ending balances -H --historical @@ -1427,16 +1448,16 @@ COMMANDS 0 With a reporting interval, multiple columns will be shown, one for each - report period. As with multicolumn balance reports, you can alter the - report mode with --change/--cumulative/--historical. Normally bal- - ancesheet shows historical ending balances, which is what you need for + report period. As with multicolumn balance reports, you can alter the + report mode with --change/--cumulative/--historical. Normally bal- + ancesheet shows historical ending balances, which is what you need for a balance sheet; note this means it ignores report begin dates. - This command also supports output destination and output format selec- + This command also supports output destination and output format selec- tion. balancesheetequity - Just like balancesheet, but also reports Equity (which it assumes is + Just like balancesheet, but also reports Equity (which it assumes is under a top-level equity account). Example: @@ -1466,10 +1487,10 @@ COMMANDS 0 cashflow - This command displays a simple cashflow statement, showing changes in - "cash" accounts. It assumes that these accounts are under a top-level - asset account (case insensitive, plural forms also allowed) and do not - contain receivable or A/R in their name. Note this report shows all + This command displays a simple cashflow statement, showing changes in + "cash" accounts. It assumes that these accounts are under a top-level + asset account (case insensitive, plural forms also allowed) and do not + contain receivable or A/R in their name. Note this report shows all account balances with normal positive sign (like conventional financial statements, unlike balance/print/register) (experimental). (cf) @@ -1477,7 +1498,7 @@ COMMANDS show balance change in each period (default) --cumulative - show balance change accumulated across periods (in multicolumn + show balance change accumulated across periods (in multicolumn reports), instead of changes during periods -H --historical @@ -1528,38 +1549,38 @@ COMMANDS $-1 With a reporting interval, multiple columns will be shown, one for each - report period. Normally cashflow shows changes in assets per period, - though as with multicolumn balance reports you can alter the report + report period. Normally cashflow shows changes in assets per period, + though as with multicolumn balance reports you can alter the report mode with --change/--cumulative/--historical. - This command also supports output destination and output format selec- + This command also supports output destination and output format selec- tion. check-dates - Check that transactions are sorted by increasing date. With a query, + Check that transactions are sorted by increasing date. With a query, only matched transactions' dates are checked. check-dupes - Report account names having the same leaf but different prefixes. An + Report account names having the same leaf but different prefixes. An example: http://stefanorodighiero.net/software/hledger-dupes.html close - Print closing/opening transactions that bring some or all account bal- - ances to zero and back. Can be useful for bringing asset/liability + Print closing/opening transactions that bring some or all account bal- + ances to zero and back. Can be useful for bringing asset/liability balances across file boundaries, or for closing out income/expenses for - a period. This was formerly called "equity", as in Ledger, and that + a period. This was formerly called "equity", as in Ledger, and that alias is also accepted. See close -help for more. help Show any of the hledger manuals. - The help command displays any of the main hledger manuals, in one of - several ways. Run it with no argument to list the manuals, or provide + The help command displays any of the main hledger manuals, in one of + several ways. Run it with no argument to list the manuals, or provide a full or partial manual name to select one. - hledger manuals are available in several formats. hledger help will - use the first of these display methods that it finds: info, man, - $PAGER, less, stdout (or when non-interactive, just stdout). You can + hledger manuals are available in several formats. hledger help will + use the first of these display methods that it finds: info, man, + $PAGER, less, stdout (or when non-interactive, just stdout). You can force a particular viewer with the --info, --man, --pager, --cat flags. $ hledger help @@ -1583,7 +1604,7 @@ COMMANDS ... import - Read new transactions added to each FILE since last run, and add them + Read new transactions added to each FILE since last run, and add them to the main journal file. --dry-run @@ -1593,28 +1614,28 @@ COMMANDS each one. So eg to add new transactions from all CSV files to the main journal, it's just: hledger import *.csv - New transactions are detected in the same way as print -new: by assum- + New transactions are detected in the same way as print -new: by assum- ing transactions are always added to the input files in increasing date order, and by saving .latest.FILE state files. - The -dry-run output is in journal format, so you can filter it, eg to + The -dry-run output is in journal format, so you can filter it, eg to see only uncategorised transactions: $ hledger import --dry ... | hledger -f- print unknown --ignore-assertions incomestatement - This command displays a simple income statement, showing revenues and - expenses during a period. It assumes that these accounts are under a - top-level revenue or income or expense account (case insensitive, plu- - ral forms also allowed). Note this report shows all account balances - with normal positive sign (like conventional financial statements, + This command displays a simple income statement, showing revenues and + expenses during a period. It assumes that these accounts are under a + top-level revenue or income or expense account (case insensitive, plu- + ral forms also allowed). Note this report shows all account balances + with normal positive sign (like conventional financial statements, unlike balance/print/register) (experimental). (is) --change show balance change in each period (default) --cumulative - show balance change accumulated across periods (in multicolumn + show balance change accumulated across periods (in multicolumn reports), instead of changes during periods -H --historical @@ -1648,8 +1669,8 @@ COMMANDS --sort-amount sort by amount instead of account code/name - This command displays a simple income statement. It currently assumes - that you have top-level accounts named income (or revenue) and expense + This command displays a simple income statement. It currently assumes + that you have top-level accounts named income (or revenue) and expense (plural forms also allowed.) $ hledger incomestatement @@ -1674,11 +1695,11 @@ COMMANDS 0 With a reporting interval, multiple columns will be shown, one for each - report period. Normally incomestatement shows revenues/expenses per - period, though as with multicolumn balance reports you can alter the + report period. Normally incomestatement shows revenues/expenses per + period, though as with multicolumn balance reports you can alter the report mode with --change/--cumulative/--historical. - This command also supports output destination and output format selec- + This command also supports output destination and output format selec- tion. prices @@ -1688,7 +1709,7 @@ COMMANDS Show transactions from the journal. Aliases: p, txns. -m STR --match=STR - show the transaction whose description is most similar to STR, + show the transaction whose description is most similar to STR, and is most recent --new show only newer-dated transactions added in each file since last @@ -1701,7 +1722,7 @@ COMMANDS select the output format. Supported formats: txt, csv. -o FILE --output-file=FILE - write output to FILE. A file extension matching one of the + write output to FILE. A file extension matching one of the above formats selects that format. $ hledger print @@ -1732,39 +1753,39 @@ COMMANDS it does not preserve directives or inter-transaction comments Normally, the journal entry's explicit or implicit amount style is pre- - served. Ie when an amount is omitted in the journal, it will be omit- - ted in the output. You can use the -x/--explicit flag to make all + served. Ie when an amount is omitted in the journal, it will be omit- + ted in the output. You can use the -x/--explicit flag to make all amounts explicit, which can be useful for troubleshooting or for making your journal more readable and robust against data entry errors. Note, - -x will cause postings with a multi-commodity amount (these can arise - when a multi-commodity transaction has an implicit amount) will be - split into multiple single-commodity postings, for valid journal out- + -x will cause postings with a multi-commodity amount (these can arise + when a multi-commodity transaction has an implicit amount) will be + split into multiple single-commodity postings, for valid journal out- put. - With -B/--cost, amounts with transaction prices are converted to cost + With -B/--cost, amounts with transaction prices are converted to cost using that price. This can be used for troubleshooting. - With -m/--match and a STR argument, print will show at most one trans- - action: the one one whose description is most similar to STR, and is - most recent. STR should contain at least two characters. If there is + With -m/--match and a STR argument, print will show at most one trans- + action: the one one whose description is most similar to STR, and is + most recent. STR should contain at least two characters. If there is no similar-enough match, no transaction will be shown. With --new, for each FILE being read, hledger reads (and writes) a spe- - cial state file (.latest.FILE in the same directory), containing the - latest transaction date(s) that were seen last time FILE was read. - When this file is found, only transactions with newer dates (and new - transactions on the latest date) are printed. This is useful for - ignoring already-seen entries in import data, such as downloaded CSV + cial state file (.latest.FILE in the same directory), containing the + latest transaction date(s) that were seen last time FILE was read. + When this file is found, only transactions with newer dates (and new + transactions on the latest date) are printed. This is useful for + ignoring already-seen entries in import data, such as downloaded CSV files. Eg: $ hledger -f bank1.csv print --new # shows transactions added since last print --new on this file - This assumes that transactions added to FILE always have same or - increasing dates, and that transactions on the same day do not get + This assumes that transactions added to FILE always have same or + increasing dates, and that transactions on the same day do not get reordered. See also the import command. - This command also supports output destination and output format selec- + This command also supports output destination and output format selec- tion. Here's an example of print's CSV output: $ hledger print -Ocsv @@ -1781,20 +1802,20 @@ COMMANDS "5","2008/12/31","","*","","pay off","","liabilities:debts","1","$","","1","","" "5","2008/12/31","","*","","pay off","","assets:bank:checking","-1","$","1","","","" - o There is one CSV record per posting, with the parent transaction's + o There is one CSV record per posting, with the parent transaction's fields repeated. o The "txnidx" (transaction index) field shows which postings belong to - the same transaction. (This number might change if transactions are - reordered within the file, files are parsed/included in a different + the same transaction. (This number might change if transactions are + reordered within the file, files are parsed/included in a different order, etc.) - o The amount is separated into "commodity" (the symbol) and "amount" + o The amount is separated into "commodity" (the symbol) and "amount" (numeric quantity) fields. o The numeric amount is repeated in either the "credit" or "debit" col- - umn, for convenience. (Those names are not accurate in the account- - ing sense; it just puts negative amounts under credit and zero or + umn, for convenience. (Those names are not accurate in the account- + ing sense; it just puts negative amounts under credit and zero or greater amounts under debit.) print-unique @@ -1807,7 +1828,7 @@ COMMANDS show running total from report start date (default) -H --historical - show historical running total/balance (includes postings before + show historical running total/balance (includes postings before report start date) -A --average @@ -1818,18 +1839,18 @@ COMMANDS show postings' siblings instead -w N --width=N - set output width (default: terminal width or COLUMNS. -wN,M + set output width (default: terminal width or COLUMNS. -wN,M sets description width as well) -O FMT --output-format=FMT select the output format. Supported formats: txt, csv. -o FILE --output-file=FILE - write output to FILE. A file extension matching one of the + write output to FILE. A file extension matching one of the above formats selects that format. The register command displays postings, one per line, and their running - total. This is typically used with a query selecting a particular + total. This is typically used with a query selecting a particular account, to see that account's activity: $ hledger register checking @@ -1838,8 +1859,8 @@ COMMANDS 2008/06/02 save assets:bank:checking $-1 $1 2008/12/31 pay off assets:bank:checking $-1 0 - The --historical/-H flag adds the balance from any undisplayed prior - postings to the running total. This is useful when you want to see + The --historical/-H flag adds the balance from any undisplayed prior + postings to the running total. This is useful when you want to see only recent activity, with a historically accurate running balance: $ hledger register checking -b 2008/6 --historical @@ -1849,23 +1870,23 @@ COMMANDS The --depth option limits the amount of sub-account detail displayed. - The --average/-A flag shows the running average posting amount instead + The --average/-A flag shows the running average posting amount instead of the running total (so, the final number displayed is the average for - the whole report period). This flag implies --empty (see below). It - is affected by --historical. It works best when showing just one + the whole report period). This flag implies --empty (see below). It + is affected by --historical. It works best when showing just one account and one commodity. - The --related/-r flag shows the other postings in the transactions of + The --related/-r flag shows the other postings in the transactions of the postings which would normally be shown. - With a reporting interval, register shows summary postings, one per + With a reporting interval, register shows summary postings, one per interval, aggregating the postings to each account: $ hledger register --monthly income 2008/01 income:salary $-1 $-1 2008/06 income:gifts $-1 $-2 - Periods with no activity, and summary postings with a zero amount, are + Periods with no activity, and summary postings with a zero amount, are not shown by default; use the --empty/-E flag to see them: $ hledger register --monthly income -E @@ -1882,7 +1903,7 @@ COMMANDS 2008/11 0 $-2 2008/12 0 $-2 - Often, you'll want to see just one line per interval. The --depth + Often, you'll want to see just one line per interval. The --depth option helps with this, causing subaccounts to be aggregated: $ hledger register --monthly assets --depth 1h @@ -1890,18 +1911,18 @@ COMMANDS 2008/06 assets $-1 0 2008/12 assets $-1 $-1 - Note when using report intervals, if you specify start/end dates these - will be adjusted outward if necessary to contain a whole number of - intervals. This ensures that the first and last intervals are full + Note when using report intervals, if you specify start/end dates these + will be adjusted outward if necessary to contain a whole number of + intervals. This ensures that the first and last intervals are full length and comparable to the others in the report. Custom register output - register uses the full terminal width by default, except on windows. - You can override this by setting the COLUMNS environment variable (not + register uses the full terminal width by default, except on windows. + You can override this by setting the COLUMNS environment variable (not a bash shell variable) or by using the --width/-w option. - The description and account columns normally share the space equally - (about half of (width - 40) each). You can adjust this by adding a + The description and account columns normally share the space equally + (about half of (width - 40) each). You can adjust this by adding a description width as part of -width's argument, comma-separated: --width W,D . Here's a diagram: @@ -1918,12 +1939,12 @@ COMMANDS $ hledger reg -w 100,40 # set overall width 100, description width 40 $ hledger reg -w $COLUMNS,40 # use terminal width, and set description width - This command also supports output destination and output format selec- + This command also supports output destination and output format selec- tion. register-match Print the one posting whose transaction description is closest to DESC, - in the style of the register command. Helps ledger-autosync detect + in the style of the register command. Helps ledger-autosync detect already-seen transactions when importing. rewrite @@ -1933,7 +1954,7 @@ COMMANDS Show some journal statistics. -o FILE --output-file=FILE - write output to FILE. A file extension matching one of the + write output to FILE. A file extension matching one of the above formats selects that format. $ hledger stats @@ -1948,16 +1969,16 @@ COMMANDS Accounts : 8 (depth 3) Commodities : 1 ($) - The stats command displays summary information for the whole journal, - or a matched part of it. With a reporting interval, it shows a report + The stats command displays summary information for the whole journal, + or a matched part of it. With a reporting interval, it shows a report for each report period. - This command also supports output destination and output format selec- + This command also supports output destination and output format selec- tion. tags - List all the tag names used in the journal. With a TAGREGEX argument, - only tag names matching the regular expression (case insensitive) are + List all the tag names used in the journal. With a TAGREGEX argument, + only tag names matching the regular expression (case insensitive) are shown. With additional QUERY arguments, only transactions matching the query are considered. @@ -1967,34 +1988,34 @@ COMMANDS $ hledger test Cases: 74 Tried: 74 Errors: 0 Failures: 0 - This command runs hledger's built-in unit tests and displays a quick + This command runs hledger's built-in unit tests and displays a quick report. With a regular expression argument, it selects only tests with matching names. It's mainly used in development, but it's also nice to be able to check your hledger executable for smoke at any time. ADD-ON COMMANDS - hledger also searches for external add-on commands, and will include + hledger also searches for external add-on commands, and will include these in the commands list. These are programs or scripts in your PATH - whose name starts with hledger- and ends with a recognised file exten- + whose name starts with hledger- and ends with a recognised file exten- sion (currently: no extension, bat,com,exe, hs,lhs,pl,py,rb,rkt,sh). - Add-ons can be invoked like any hledger command, but there are a few + Add-ons can be invoked like any hledger command, but there are a few things to be aware of. Eg if the hledger-web add-on is installed, o hledger -h web shows hledger's help, while hledger web -h shows hledger-web's help. - o Flags specific to the add-on must have a preceding -- to hide them - from hledger. So hledger web --serve --port 9000 will be rejected; + o Flags specific to the add-on must have a preceding -- to hide them + from hledger. So hledger web --serve --port 9000 will be rejected; you must use hledger web -- --serve --port 9000. - o You can always run add-ons directly if preferred: + o You can always run add-ons directly if preferred: hledger-web --serve --port 9000. - Add-ons are a relatively easy way to add local features or experiment - with new ideas. They can be written in any language, but haskell - scripts have a big advantage: they can use the same hledger (and - haskell) library functions that built-in commands do, for command-line + Add-ons are a relatively easy way to add local features or experiment + with new ideas. They can be written in any language, but haskell + scripts have a big advantage: they can use the same hledger (and + haskell) library functions that built-in commands do, for command-line options, journal parsing, reporting, etc. Here are some hledger add-ons available: @@ -2012,7 +2033,7 @@ ADD-ON COMMANDS hledger-web provides a simple web interface. Third party add-ons - These are maintained separately, and usually updated shortly after a + These are maintained separately, and usually updated shortly after a hledger release. diff @@ -2020,7 +2041,7 @@ ADD-ON COMMANDS journal file and another. iadd - hledger-iadd is a curses-style, more interactive replacement for the + hledger-iadd is a curses-style, more interactive replacement for the add command. interest @@ -2028,19 +2049,19 @@ ADD-ON COMMANDS ing to various schemes. irr - hledger-irr calculates the internal rate of return of an investment + hledger-irr calculates the internal rate of return of an investment account. Experimental add-ons - These are available in source form in the hledger repo's bin/ direc- + These are available in source form in the hledger repo's bin/ direc- tory; installing them is pretty easy. They may be less mature and doc- - umented than built-in commands. Reading and tweaking these is a good + umented than built-in commands. Reading and tweaking these is a good way to start making your own! autosync hledger-autosync is a symbolic link for easily running ledger-autosync, - if installed. ledger-autosync does deduplicating conversion of OFX - data and some CSV formats, and can also download the data if your bank + if installed. ledger-autosync does deduplicating conversion of OFX + data and some CSV formats, and can also download the data if your bank offers OFX Direct Connect. chart @@ -2050,21 +2071,21 @@ ADD-ON COMMANDS hledger-check.hs checks more powerful account balance assertions. ENVIRONMENT - COLUMNS The screen width used by the register command. Default: the + COLUMNS The screen width used by the register command. Default: the full terminal width. LEDGER_FILE The journal file path when not specified with -f. Default: - ~/.hledger.journal (on windows, perhaps C:/Users/USER/.hledger.jour- + ~/.hledger.journal (on windows, perhaps C:/Users/USER/.hledger.jour- nal). FILES - Reads data from one or more files in hledger journal, timeclock, time- - dot, or CSV format specified with -f, or $LEDGER_FILE, or - $HOME/.hledger.journal (on windows, perhaps + Reads data from one or more files in hledger journal, timeclock, time- + dot, or CSV format specified with -f, or $LEDGER_FILE, or + $HOME/.hledger.journal (on windows, perhaps C:/Users/USER/.hledger.journal). BUGS - The need to precede addon command options with -- when invoked from + The need to precede addon command options with -- when invoked from hledger is awkward. When input data contains non-ascii characters, a suitable system locale @@ -2077,33 +2098,33 @@ BUGS In a Cygwin/MSYS/Mintty window, the tab key is not supported in hledger add. - Not all of Ledger's journal file syntax is supported. See file format + Not all of Ledger's journal file syntax is supported. See file format differences. - On large data files, hledger is slower and uses more memory than + On large data files, hledger is slower and uses more memory than Ledger. TROUBLESHOOTING - Here are some issues you might encounter when you run hledger (and - remember you can also seek help from the IRC channel, mail list or bug + Here are some issues you might encounter when you run hledger (and + remember you can also seek help from the IRC channel, mail list or bug tracker): Successfully installed, but "No command `hledger' found" stack and cabal install binaries into a special directory, which should - be added to your PATH environment variable. Eg on unix-like systems, + be added to your PATH environment variable. Eg on unix-like systems, that is ~/.local/bin and ~/.cabal/bin respectively. I set a custom LEDGER_FILE, but hledger is still using the default file - LEDGER_FILE should be a real environment variable, not just a shell - variable. The command env | grep LEDGER_FILE should show it. You may + LEDGER_FILE should be a real environment variable, not just a shell + variable. The command env | grep LEDGER_FILE should show it. You may need to use export. Here's an explanation. - "Illegal byte sequence" or "Invalid or incomplete multibyte or wide + "Illegal byte sequence" or "Invalid or incomplete multibyte or wide character" errors In order to handle non-ascii letters and symbols (like ), hledger needs an appropriate locale. This is usually configured system-wide; you can also configure it temporarily. The locale may need to be one that sup- - ports UTF-8, if you built hledger with GHC < 7.2 (or possibly always, + ports UTF-8, if you built hledger with GHC < 7.2 (or possibly always, I'm not sure yet). Here's an example of setting the locale temporarily, on ubuntu @@ -2122,7 +2143,7 @@ TROUBLESHOOTING $ echo "export LANG=en_US.UTF-8" >>~/.bash_profile $ bash --login - If we preferred to use eg fr_FR.utf8, we might have to install that + If we preferred to use eg fr_FR.utf8, we might have to install that first: $ apt-get install language-pack-fr @@ -2143,7 +2164,7 @@ TROUBLESHOOTING REPORTING BUGS - Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel + Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel or hledger mail list) @@ -2157,7 +2178,7 @@ COPYRIGHT SEE ALSO - hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1), + hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1), hledger_csv(5), hledger_journal(5), hledger_timeclock(5), hledger_time- dot(5), ledger(1) diff --git a/hledger/hledger_options.m4.md b/hledger/hledger_options.m4.md index 270b606f4..ef0d9a174 100644 --- a/hledger/hledger_options.m4.md +++ b/hledger/hledger_options.m4.md @@ -128,17 +128,27 @@ and can have less-significant date parts omitted (defaulting to 1). Examples: -------------------------------------------------- ----------------------------------------------------------------------------- -`2009/1/1`, `2009/01/01`, `2009-1-1`, `2009.1.1` simple dates, several separators allowed -`2009/1`, `2009` same as above - a missing day or month defaults to 1 -`1/1`, `january`, `jan`, `this year` relative dates, meaning january 1 of the current year -`next year` january 1 of next year -`this month` the 1st of the current month -`this week` the most recent monday -`last week` the monday of the week before this one -`lastweek` spaces are optional -`today`, `yesterday`, `tomorrow` ---- +--------------------------------------------- ----------------------------------------------------------------------------- +`2004/10/1`, `2004-01-01`, `2004.9.1` exact date, several separators allowed. Year is 4+ digits, month is 1-12, day is 1-31 +`2004` start of year +`2004/10` start of month +`10/1` month and day in current year +`21` day in current month +`october, oct` start of month in current year +`yesterday, today, tomorrow` -1, 0, 1 days from today +`last/this/next day/week/month/quarter/year` -1, 0, 1 periods from the current period +`20181201` 8 digit YYYYMMDD with valid year month and day +`201812` 6 digit YYYYMM with valid year and month +--------------------------------------------- ----------------------------------------------------------------------------- + +Counterexamples - malformed digit sequences might give surprising results: + +--------------------------------------------- ----------------------------------------------------------------------------- +`201813` 6 digits with an invalid month is parsed as start of 6-digit year +`20181301` 8 digits with an invalid month is parsed as start of 8-digit year +`20181232` 8 digits with an invalid day gives an error +`201801012` 9+ digits beginning with a valid YYYYMMDD gives an error +--------------------------------------------- ----------------------------------------------------------------------------- ## Report start & end date