AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
HolidayDateCalculator.cpp File Reference
#include "HolidayDateCalculator.h"
#include "SharedDefines.h"
#include <cmath>

Go to the source code of this file.

Functions

double sind (double deg)
 
static bool IsLeapYear (int year)
 
static int DaysInMonth (int year, int month)
 
static void NormalizeDate (std::tm &date)
 

Variables

constexpr double PI = 3.14159265358979323846
 
constexpr double DEG_TO_RAD = PI / 180.0
 
static const std::vector< HolidayRuleHolidayRules
 

Function Documentation

◆ DaysInMonth()

static int DaysInMonth ( int  year,
int  month 
)
static
36{
37 static int const table[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
38 return (month == 2 && IsLeapYear(year)) ? 29 : table[month - 1];
39}
static bool IsLeapYear(int year)
Definition HolidayDateCalculator.cpp:30

References IsLeapYear().

Referenced by NormalizeDate().

◆ IsLeapYear()

static bool IsLeapYear ( int  year)
static
31{
32 return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
33}

Referenced by DaysInMonth(), and TEST_F().

◆ NormalizeDate()

static void NormalizeDate ( std::tm &  date)
static
42{
43 int year = date.tm_year + 1900;
44 int month = date.tm_mon + 1;
45 int day = date.tm_mday;
46
47 while (month > 12)
48 {
49 month -= 12;
50 ++year;
51 }
52 while (month < 1)
53 {
54 month += 12;
55 --year;
56 }
57 while (day > DaysInMonth(year, month))
58 {
59 day -= DaysInMonth(year, month);
60 ++month;
61 if (month > 12)
62 {
63 month = 1;
64 ++year;
65 }
66 }
67 while (day < 1)
68 {
69 --month;
70 if (month < 1)
71 {
72 month = 12;
73 --year;
74 }
75 day += DaysInMonth(year, month);
76 }
77
78 date.tm_year = year - 1900;
79 date.tm_mon = month - 1;
80 date.tm_mday = day;
81
82 // Zeller's congruence; remap 0=Sat to POSIX 0=Sun.
83 int zy = year;
84 int zm = month;
85 if (zm < 3)
86 {
87 zm += 12;
88 --zy;
89 }
90 int const K = zy % 100;
91 int const J = zy / 100;
92 int const h = (day + (13 * (zm + 1)) / 5 + K + K / 4 + J / 4 + 5 * J) % 7;
93 date.tm_wday = (h + 6) % 7;
94}
static int DaysInMonth(int year, int month)
Definition HolidayDateCalculator.cpp:35

References DaysInMonth().

Referenced by HolidayDateCalculator::CalculateAutumnEquinox(), HolidayDateCalculator::CalculateEasterSunday(), HolidayDateCalculator::CalculateHolidayDate(), HolidayDateCalculator::CalculateLunarNewYear(), HolidayDateCalculator::CalculateNthWeekday(), HolidayDateCalculator::CalculateWeekdayOnOrAfter(), HolidayDateCalculator::CalculateWinterSolstice(), and HolidayDateCalculator::GetDarkmoonFaireDates().

◆ sind()

double sind ( double  deg)
inline
27{ return std::sin(deg * DEG_TO_RAD); }
constexpr double DEG_TO_RAD
Definition HolidayDateCalculator.cpp:24

References DEG_TO_RAD.

Referenced by HolidayDateCalculator::CalculateNewMoon().

Variable Documentation

◆ DEG_TO_RAD

constexpr double DEG_TO_RAD = PI / 180.0
constexpr

◆ HolidayRules

const std::vector<HolidayRule> HolidayRules
static
97 {
98 // Lunar Festival: Chinese New Year - 1 day (event starts day before CNY)
100
101 // Love is in the Air: First Monday on or after Feb 3
103
104 // Noblegarden: Day after Easter Sunday (Easter + 1 day)
106
107 // Children's Week: First Monday on or after Apr 25 (Monday closest to May 1)
109
110 // Midsummer Fire Festival: Fixed Jun 21
112
113 // Fireworks Spectacular: Fixed Jul 4
115
116 // Pirates' Day: Fixed Sep 19
118
119 // Brewfest: Fixed Sept 20 main event, prep starts Sept 13
121
122 // Harvest Festival: 2 days before autumn equinox (Sept 20-21)
124
125 // Hallow's End: Fixed Oct 18
127
128 // Day of the Dead: Fixed Nov 1
130
131 // Pilgrim's Bounty: Sunday before Thanksgiving (4th Thursday - 4 days)
133
134 // Winter Veil: 6 days before winter solstice (Dec 15-16)
136
137 // Darkmoon Faire: First Sunday of months matching (month % 3 == locationOffset)
138 // Rotates monthly: Mulgore (Jan) -> Terokkar (Feb) -> Elwynn (Mar) -> repeat
139 // rule.month stores the location offset
140 // rule.offset is -2 (building phase starts Friday, 2 days before faire opens on Sunday)
141 { HOLIDAY_DARKMOON_FAIRE_ELWYNN, HolidayCalculationType::DARKMOON_FAIRE, 0, 0, 0, -2 }, // Mar, Jun, Sep, Dec
142 { HOLIDAY_DARKMOON_FAIRE_THUNDER, HolidayCalculationType::DARKMOON_FAIRE, 1, 0, 0, -2 }, // Jan, Apr, Jul, Oct
144};
@ HOLIDAY_NOBLEGARDEN
Definition SharedDefines.h:2979
@ HOLIDAY_DARKMOON_FAIRE_THUNDER
Definition SharedDefines.h:2993
@ HOLIDAY_HALLOWS_END
Definition SharedDefines.h:2986
@ HOLIDAY_DARKMOON_FAIRE_ELWYNN
Definition SharedDefines.h:2992
@ HOLIDAY_FIRE_FESTIVAL
Definition SharedDefines.h:2989
@ HOLIDAY_DARKMOON_FAIRE_SHATTRATH
Definition SharedDefines.h:2994
@ HOLIDAY_CHILDRENS_WEEK
Definition SharedDefines.h:2980
@ HOLIDAY_FEAST_OF_WINTER_VEIL
Definition SharedDefines.h:2978
@ HOLIDAY_LOVE_IS_IN_THE_AIR
Definition SharedDefines.h:3001
@ HOLIDAY_FIREWORKS_SPECTACULAR
Definition SharedDefines.h:2977
@ HOLIDAY_PILGRIMS_BOUNTY
Definition SharedDefines.h:2997
@ HOLIDAY_HARVEST_FESTIVAL
Definition SharedDefines.h:2985
@ HOLIDAY_DAY_OF_DEAD
Definition SharedDefines.h:2999
@ HOLIDAY_PIRATES_DAY
Definition SharedDefines.h:2995
@ HOLIDAY_LUNAR_FESTIVAL
Definition SharedDefines.h:2987
@ HOLIDAY_BREWFEST
Definition SharedDefines.h:2991

Referenced by HolidayDateCalculator::GetHolidayRules(), and HolidayDateCalculator::GetPackedHolidayDate().

◆ PI

constexpr double PI = 3.14159265358979323846
constexpr