diff --git a/headers/os/support/DateTime.h b/headers/os/support/DateTime.h index 34d41df485..d9ba24dae1 100644 --- a/headers/os/support/DateTime.h +++ b/headers/os/support/DateTime.h @@ -145,10 +145,6 @@ public: int32 DateToJulianDay() const; static BDate JulianDayToDate(int32 julianDay); - static BDate EasterSunday(int32 year); - static BDate AscensionDay(int32 year); - static BDate PentecostDay(int32 year); - bool operator!=(const BDate& date) const; bool operator==(const BDate& date) const; diff --git a/headers/private/shared/Holiday.h b/headers/private/shared/Holiday.h new file mode 100644 index 0000000000..85a4f9f2cf --- /dev/null +++ b/headers/private/shared/Holiday.h @@ -0,0 +1,85 @@ +/* + * Copyright 2010, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _HOLIDAY_H_ +#define _HOLIDAY_H_ + + +#include + + +namespace BPrivate { + + +class BHoliday { +public: + virtual ~BHoliday() { }; +}; + + +class BEasterHoliday : public BHoliday { +public: + static BDate EasterSunday(int32 year); + static BDate AscensionDay(int32 year); + static BDate PentecostDay(int32 year); +}; + + +/*! + Returns the date for easter sunday for the \c year. +*/ +/*static*/ BDate +BEasterHoliday::EasterSunday(int32 year) +{ + // http://bloggingabout.net/blogs/jschreuder/archive/2005/06/24/7019.aspx + int32 gold = year % 19; + int32 century = year / 100; + int32 h = (century - (int32)(century / 4) + - (int32)((century * 8 + 13) / 25) + 19 * gold + 15) % 30; + int32 i = h - (int32)(h / 28) * (1 - (int32)(h / 28) + * (int32)(29 / (h + 1)) * (int32)((21 - gold) / 11)); + + int32 day = i - ((year + (int32)(year / 4) + i + 2 - century + + (int32)(century / 4)) % 7) + 28; + BDate date; + if (day > 31) + date.SetDate(year, 4, day - 31); + else + date.SetDate(year, 3, day); + return date; +} + + +/*! + Returns the date for ascension day for the \c year. +*/ +/*static*/ BDate +BEasterHoliday::AscensionDay(int32 year) +{ + BDate date = EasterSunday(year); + date.AddDays(39); + return date; +} + + +/*! + Returns the date for pentecost day for the \c year. +*/ +/*static*/ BDate +BEasterHoliday::PentecostDay(int32 year) +{ + BDate date = EasterSunday(year); + date.AddDays(49); + return date; +} + + +} // namespace BPrivate + + +using BPrivate::BHoliday; +using BPrivate::BEasterHoliday; + + +#endif // _HOLIDAY_H_ diff --git a/src/kits/support/DateTime.cpp b/src/kits/support/DateTime.cpp index 1ce6ec31f0..8fd64320b1 100644 --- a/src/kits/support/DateTime.cpp +++ b/src/kits/support/DateTime.cpp @@ -1090,57 +1090,6 @@ BDate::JulianDayToDate(int32 julianDay) } -/*! - Returns the date for easter sunday for the \c year. -*/ -/*static*/ BDate -BDate::EasterSunday(int32 year) -{ - // http://bloggingabout.net/blogs/jschreuder/archive/2005/06/24/7019.aspx - int32 gold = year % 19; - int32 century = year / 100; - int32 h = (century - (int32)(century / 4) - - (int32)((century * 8 + 13) / 25) + 19 * gold + 15) % 30; - int32 i = h - (int32)(h / 28) * (1 - (int32)(h / 28) - * (int32)(29 / (h + 1)) * (int32)((21 - gold) / 11)); - - BDate date; - date.fDay = i - ((year + (int32)(year / 4) + i + 2 - century - + (int32)(century / 4)) % 7) + 28; - date.fMonth = 3; - date.fYear = year; - if (date.fDay > 31) { - date.fMonth++; - date.fDay -= 31; - } - return date; -} - - -/*! - Returns the date for ascension day for the \c year. -*/ -/*static*/ BDate -BDate::AscensionDay(int32 year) -{ - BDate date = EasterSunday(year); - date.AddDays(39); - return date; -} - - -/*! - Returns the date for pentecost day for the \c year. -*/ -/*static*/ BDate -BDate::PentecostDay(int32 year) -{ - BDate date = EasterSunday(year); - date.AddDays(49); - return date; -} - - /*! Returns true if this date is different from \c date, otherwise false. */