diff --git a/doc/man/timew.1.in b/doc/man/timew.1.in index 6a8d529b..10f73e91 100644 --- a/doc/man/timew.1.in +++ b/doc/man/timew.1.in @@ -358,6 +358,7 @@ Range hints provide convenient shortcuts to date ranges: :quarter This quarter :year This year :lastweek Last week + :lastmonth Last month .SH CONFIGURATION FILE AND OVERRIDE OPTIONS diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 32f6feb0..7cacc8eb 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -302,6 +302,7 @@ int CmdHelp (const CLI& cli) << " :quarter This quarter\n" << " :year This year\n" << " :lastweek Last week\n" + << " :lastmonth Last month\n" << '\n' << '\n'; diff --git a/src/helper.cpp b/src/helper.cpp index 2be05865..95b21b89 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -149,6 +149,25 @@ bool expandIntervalHint ( range.end.toISOLocalExtended ())); return true; } + else if (hint == ":lastmonth") + { + Datetime now; + int y = now.year (); + int m = now.month () - 1; + if (m == 0) + { + m = 12; + --y; + } + + range.start = Datetime (y, m, 1); + range.end = Datetime (y, m, Datetime::daysInMonth (y, m)); + debug (format ("Hint {1} expanded to {2} - {3}", + hint, + range.start.toISOLocalExtended (), + range.end.toISOLocalExtended ())); + return true; + } return false; } diff --git a/src/init.cpp b/src/init.cpp index d893b23e..ddf4a32d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -93,6 +93,7 @@ void initializeEntities (CLI& cli) cli.entity ("hint", ":debug"); cli.entity ("hint", ":fill"); cli.entity ("hint", ":ids"); + cli.entity ("hint", ":lastmonth"); cli.entity ("hint", ":lastweek"); cli.entity ("hint", ":month"); cli.entity ("hint", ":nocolor");