From 8553811889864e481d22a84606fb1affa4b2cdbf Mon Sep 17 00:00:00 2001 From: Federico Hernandez Date: Tue, 11 May 2010 00:01:17 +0200 Subject: [PATCH] Automatic computation of easter and related holidays for the calendar --- ChangeLog | 12 ++++++--- doc/man/taskrc.5 | 13 ++++++++++ src/Date.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 83 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index eac46a9f3..8b900ef85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,16 +2,20 @@ ------ current release --------------------------- 1.9.1 () - + Fixed bug #382 in which the annotate command didn't return an error - message when called without an ID. + Summary report bar colors can now be specified with color.summary.bar and color.summary.background configuration variables. - + The configure script is more portable (thanks to Emil Sköldberg). - + Updated task-faq.5 man page. + The 'edit' command now conveniently fills in the current date for new annotations. + Deleting a task no longer clobbers any recorded end date (thanks to Seneca Cunningham). + + Following holidays are now computed automatically: + Good Friday (goodfriday), Easter (easter), Easter monday (eastermonday), + Ascension (ascension), Pentecost (pentecost) + The date is configured with the given keyword. + + The configure script is more portable (thanks to Emil Sköldberg). + + Updated task-faq.5 man page. + + Fixed bug #382 in which the annotate command didn't return an error + message when called without an ID. + Fixed bug #402 which failed compilation on Arch Linux (thanks to Johannes Schlatow). diff --git a/doc/man/taskrc.5 b/doc/man/taskrc.5 index e1d6fe7d6..89f954cf9 100644 --- a/doc/man/taskrc.5 +++ b/doc/man/taskrc.5 @@ -414,6 +414,19 @@ Dates are to be entered according to the setting in the dateformat.holiday variable. .RE +.RS +The following holidays are computed automatically: Good Friday (goodfriday), Easter (easter), Easter monday (eastermonday), Ascension (ascension), Pentecost (pentecost). The date for these holidays is the given keyword: +.RE + +.RS +.RS +.br +holiday.eastersunday.name=Easter +.br +holiday.eastersunday.date=easter +.RE +.RE + .TP .B monthsperline=3 Determines how many months the "task calendar" command renders across the diff --git a/src/Date.cpp b/src/Date.cpp index 023f39ec0..84df1ca8c 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -792,7 +792,7 @@ bool Date::sameYear (const Date& rhs) //////////////////////////////////////////////////////////////////////////////// Date Date::operator+ (const int delta) { - return Date (mT + delta); + return Date::Date (mT + delta); } //////////////////////////////////////////////////////////////////////////////// @@ -862,6 +862,13 @@ bool Date::isRelativeDate (const std::string& input) supported.push_back ("eow"); supported.push_back ("eom"); supported.push_back ("eoy"); + supported.push_back ("goodfriday"); + supported.push_back ("easter"); + supported.push_back ("eastermonday"); + supported.push_back ("ascension"); + supported.push_back ("pentecost"); + supported.push_back ("midsommar"); + supported.push_back ("midsommarafton"); std::vector matches; if (autoComplete (in, supported, matches) == 1) @@ -926,6 +933,60 @@ bool Date::isRelativeDate (const std::string& input) mT = then.mT; return true; } + else if (found == "goodfriday") + { + Date then (Date::easter(today.year())); + mT = then.mT - 86400*2; + return true; + } + else if (found == "easter") + { + Date then (Date::easter(today.year())); + mT = then.mT; + return true; + } + else if (found == "eastermonday") + { + Date then (Date::easter(today.year())); + mT = then.mT + 86400; + return true; + } + else if (found == "ascension") + { + Date then (Date::easter(today.year())); + mT = then.mT + 86400*39; + return true; + } + else if (found == "pentecost") + { + Date then (Date::easter(today.year())); + mT = then.mT + 86400*49; + return true; + } + else if (found == "midsommar") + { + for (int midsommar = 20; midsommar <= 26; midsommar++) + { + Date then (6, midsommar, today.year ()); + if (6 == then.dayOfWeek ()) + { + mT = then.mT; + return true; + } + } + } + else if (found == "midsommarafton") + { + for (int midsommar = 19; midsommar <= 25; midsommar++) + { + Date then (6, midsommar, today.year ()); + if (5 == then.dayOfWeek ()) + { + mT = then.mT; + return true; + } + } + } } // Support "21st" to indicate the next date that is the 21st day.