diff --git a/include/date.cpp b/include/date.cpp index c933fbe30..db01e94ff 100755 --- a/include/date.cpp +++ b/include/date.cpp @@ -99,7 +99,7 @@ TDate::TDate(int day, int month, int year) } } -void TDate::set_end_month() +int TDate::last_day(int month, int year) // parse_filastrok( // "trenta giorni case novembre // con april, giugno e settembre @@ -107,7 +107,7 @@ void TDate::set_end_month() // per default ce n'ha trentuno"); { int d; - switch(month()) + switch(month) { case 4: case 6: @@ -116,21 +116,29 @@ void TDate::set_end_month() d = 30; break; case 2: - d = year() % 4 ? 28 : 29; + d = year % 4 ? 28 : 29; break; default: d = 31; break; } - _val = makedata(d,month(),year()); + return d; +} + +void TDate::set_end_month() +{ + _val = makedata(last_day(month(),year()),month(),year()); +} + +bool TDate::is_end_month() +{ + return day() == last_day(month(),year()); } void TDate::set_day(int n) { _val = makedata(n, month(), year()); } void TDate::set_month(int n) { _val = makedata(day(), n, year()); } void TDate::set_year(int n) { _val = makedata(day(), month(), n); } - - TDate::operator const char*() const { return string(4); diff --git a/include/date.h b/include/date.h index ca41b3598..d9e3290e5 100755 --- a/include/date.h +++ b/include/date.h @@ -26,6 +26,8 @@ class TDate : TObject friend bool operator ==(const TDate& a, const TDate& b); friend bool operator !=(const TDate& a, const TDate& b); + static int last_day(int month, int year); + public: // @FPUB char* string(int yeardgts = 4, char sep = '-') const ; @@ -39,6 +41,7 @@ public: bool ok() const; // Vero se la data e' corretta static bool isdate(const char*); // Vero se la stringa passata e' una data corretta + bool is_end_month(); void set_end_month(); // setta il giorno del mese all'ultimo possibile // implementando la filastrocchina