Moved Easter holidays methods to a Holiday class, an hopefully better place.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40125 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
89c389ebcb
commit
23281fb2c1
@ -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;
|
||||
|
||||
|
85
headers/private/shared/Holiday.h
Normal file
85
headers/private/shared/Holiday.h
Normal file
@ -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 <DateTime.h>
|
||||
|
||||
|
||||
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_
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user