AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
HolidayDateCalculator Class Reference

#include "HolidayDateCalculator.h"

Static Public Member Functions

static std::tm CalculateEasterSunday (int year)
 
static std::tm CalculateNthWeekday (int year, int month, Weekday weekday, int n)
 
static std::tm CalculateWeekdayOnOrAfter (int year, int month, int day, Weekday weekday)
 
static std::tm CalculateLunarNewYear (int year)
 
static std::tm CalculateAutumnEquinox (int year)
 
static std::tm CalculateWinterSolstice (int year)
 
static std::tm CalculateHolidayDate (const HolidayRule &rule, int year)
 
static uint32_t PackDate (const std::tm &date)
 
static std::tm UnpackDate (uint32_t packed)
 
static const std::vector< HolidayRule > & GetHolidayRules ()
 
static uint32_t GetPackedHolidayDate (uint32_t holidayId, int year)
 
static std::vector< uint32_t > GetDarkmoonFaireDates (int locationOffset, int startYear, int numYears, int dayOffset=0)
 

Static Private Member Functions

static double DateToJulianDay (int year, int month, double day)
 
static void JulianDayToDate (double jd, int &year, int &month, int &day)
 
static double CalculateNewMoon (double k)
 

Detailed Description

Member Function Documentation

◆ CalculateAutumnEquinox()

std::tm HolidayDateCalculator::CalculateAutumnEquinox ( int  year)
static
312{
313 // Meeus algorithm for mean September equinox (Table 27.C)
314 // Valid for years 2000-3000
315 double const Y = (year - 2000.0) / 1000.0;
316 double const Y2 = Y * Y;
317 double const Y3 = Y2 * Y;
318 double const Y4 = Y3 * Y;
319
320 // Mean equinox JDE0 (Eq 27.1 for September equinox after 2000)
321 double const JDE0 = 2451810.21715 + 365242.01767 * Y - 0.11575 * Y2
322 + 0.00337 * Y3 + 0.00078 * Y4;
323
324 // Periodic terms for correction (Table 27.B)
325 double const T = (JDE0 - 2451545.0) / 36525.0;
326 double const W = 35999.373 * T - 2.47;
327 double const deltaLambda = 1.0 + 0.0334 * std::cos(W * DEG_TO_RAD)
328 + 0.0007 * std::cos(2.0 * W * DEG_TO_RAD);
329
330 // Simplified correction (sum of periodic terms from Table 27.C)
331 // Using first few significant terms
332 double const S = 485 * std::cos((324.96 + 1934.136 * T) * DEG_TO_RAD)
333 + 203 * std::cos((337.23 + 32964.467 * T) * DEG_TO_RAD)
334 + 199 * std::cos((342.08 + 20.186 * T) * DEG_TO_RAD)
335 + 182 * std::cos((27.85 + 445267.112 * T) * DEG_TO_RAD)
336 + 156 * std::cos((73.14 + 45036.886 * T) * DEG_TO_RAD)
337 + 136 * std::cos((171.52 + 22518.443 * T) * DEG_TO_RAD)
338 + 77 * std::cos((222.54 + 65928.934 * T) * DEG_TO_RAD)
339 + 74 * std::cos((296.72 + 3034.906 * T) * DEG_TO_RAD)
340 + 70 * std::cos((243.58 + 9037.513 * T) * DEG_TO_RAD)
341 + 58 * std::cos((119.81 + 33718.147 * T) * DEG_TO_RAD)
342 + 52 * std::cos((297.17 + 150.678 * T) * DEG_TO_RAD)
343 + 50 * std::cos((21.02 + 2281.226 * T) * DEG_TO_RAD);
344
345 double const JDE = JDE0 + (0.00001 * S) / deltaLambda;
346
347 // Convert JDE to calendar date
348 int eqYear;
349 int eqMonth;
350 int eqDay;
351 JulianDayToDate(JDE, eqYear, eqMonth, eqDay);
352
353 std::tm result = {};
354 result.tm_year = eqYear - 1900;
355 result.tm_mon = eqMonth - 1;
356 result.tm_mday = eqDay;
357 mktime(&result);
358 return result;
359}
constexpr double DEG_TO_RAD
Definition HolidayDateCalculator.cpp:24
static void JulianDayToDate(double jd, int &year, int &month, int &day)
Definition HolidayDateCalculator.cpp:168

References DEG_TO_RAD, and JulianDayToDate().

Referenced by CalculateHolidayDate(), and TEST_F().

◆ CalculateEasterSunday()

std::tm HolidayDateCalculator::CalculateEasterSunday ( int  year)
static
85{
86 // Anonymous Gregorian algorithm (Computus)
87 // Reference: https://en.wikipedia.org/wiki/Date_of_Easter#Anonymous_Gregorian_algorithm
88 int const a = year % 19;
89 int const b = year / 100;
90 int const c = year % 100;
91 int const d = b / 4;
92 int const e = b % 4;
93 int const f = (b + 8) / 25;
94 int const g = (b - f + 1) / 3;
95 int const h = (19 * a + b - d - g + 15) % 30;
96 int const i = c / 4;
97 int const k = c % 4;
98 int const l = (32 + 2 * e + 2 * i - h - k) % 7;
99 int const m = (a + 11 * h + 22 * l) / 451;
100 int const month = (h + l - 7 * m + 114) / 31;
101 int const day = ((h + l - 7 * m + 114) % 31) + 1;
102
103 std::tm result = {};
104 result.tm_year = year - 1900;
105 result.tm_mon = month - 1;
106 result.tm_mday = day;
107 mktime(&result); // Normalize and fill in other fields
108
109 return result;
110}

Referenced by CalculateHolidayDate(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ CalculateHolidayDate()

std::tm HolidayDateCalculator::CalculateHolidayDate ( const HolidayRule rule,
int  year 
)
static
416{
417 std::tm result = {};
418
419 switch (rule.type)
420 {
422 {
423 result.tm_year = year - 1900;
424 result.tm_mon = rule.month - 1;
425 result.tm_mday = rule.day;
426 mktime(&result);
427 break;
428 }
430 {
431 result = CalculateNthWeekday(year, rule.month, static_cast<Weekday>(rule.weekday), rule.day);
432 if (rule.offset != 0)
433 {
434 result.tm_mday += rule.offset;
435 mktime(&result); // Normalize
436 }
437 break;
438 }
440 {
441 result = CalculateEasterSunday(year);
442 result.tm_mday += rule.offset;
443 mktime(&result); // Normalize
444 break;
445 }
447 {
448 result = CalculateLunarNewYear(year);
449 if (rule.offset != 0)
450 {
451 result.tm_mday += rule.offset;
452 mktime(&result); // Normalize
453 }
454 break;
455 }
457 {
458 result = CalculateWeekdayOnOrAfter(year, rule.month, rule.day, static_cast<Weekday>(rule.weekday));
459 if (rule.offset != 0)
460 {
461 result.tm_mday += rule.offset;
462 mktime(&result); // Normalize
463 }
464 break;
465 }
467 {
468 result = CalculateAutumnEquinox(year);
469 if (rule.offset != 0)
470 {
471 result.tm_mday += rule.offset;
472 mktime(&result); // Normalize
473 }
474 break;
475 }
477 {
478 result = CalculateWinterSolstice(year);
479 if (rule.offset != 0)
480 {
481 result.tm_mday += rule.offset;
482 mktime(&result); // Normalize
483 }
484 break;
485 }
487 {
488 // Return first occurrence for the year
489 // rule.month contains the location offset (0, 1, or 2)
490 int const locationOffset = rule.month;
491
492 // Find first month in the year where month % 3 == locationOffset
493 for (int month = 1; month <= 12; ++month)
494 {
495 if (month % 3 == locationOffset)
496 {
497 result = CalculateNthWeekday(year, month, Weekday::SUNDAY, 1);
498 break;
499 }
500 }
501 break;
502 }
503 }
504
505 return result;
506}
Weekday
Definition HolidayDateCalculator.h:38
static std::tm CalculateAutumnEquinox(int year)
Definition HolidayDateCalculator.cpp:311
static std::tm CalculateLunarNewYear(int year)
Definition HolidayDateCalculator.cpp:261
static std::tm CalculateNthWeekday(int year, int month, Weekday weekday, int n)
Definition HolidayDateCalculator.cpp:112
static std::tm CalculateEasterSunday(int year)
Definition HolidayDateCalculator.cpp:84
static std::tm CalculateWinterSolstice(int year)
Definition HolidayDateCalculator.cpp:366
static std::tm CalculateWeekdayOnOrAfter(int year, int month, int day, Weekday weekday)
Definition HolidayDateCalculator.cpp:132
HolidayCalculationType type
Definition HolidayDateCalculator.h:51
int day
Definition HolidayDateCalculator.h:53
int month
Definition HolidayDateCalculator.h:52
int offset
Definition HolidayDateCalculator.h:55
int weekday
Definition HolidayDateCalculator.h:54

References AUTUMN_EQUINOX, CalculateAutumnEquinox(), CalculateEasterSunday(), CalculateLunarNewYear(), CalculateNthWeekday(), CalculateWeekdayOnOrAfter(), CalculateWinterSolstice(), DARKMOON_FAIRE, HolidayRule::day, EASTER_OFFSET, FIXED_DATE, LUNAR_NEW_YEAR, HolidayRule::month, NTH_WEEKDAY, HolidayRule::offset, SUNDAY, HolidayRule::type, HolidayRule::weekday, WEEKDAY_ON_OR_AFTER, and WINTER_SOLSTICE.

Referenced by GetPackedHolidayDate(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ CalculateLunarNewYear()

std::tm HolidayDateCalculator::CalculateLunarNewYear ( int  year)
static
262{
263 // Chinese New Year always falls on the new moon between Jan 21 and Feb 20
264 double const jan21JD = DateToJulianDay(year, 1, 21.0);
265 double const feb21JD = DateToJulianDay(year, 2, 21.0);
266
267 // Approximate lunation number k for January of target year
268 double const approxK = (year - 2000.0) * 12.3685;
269 double const k = std::floor(approxK);
270
271 // Search for the new moon in the valid range
272 for (int i = -2; i <= 2; ++i)
273 {
274 double const nmJDE = CalculateNewMoon(k + i);
275
276 // Convert TT (Terrestrial Time) to UT (approximate DeltaT ~70s for 2020s)
277 double nmJD = nmJDE - 70.0 / 86400.0;
278
279 // Add 8 hours for China Standard Time (UTC+8)
280 nmJD += 8.0 / 24.0;
281
282 if (nmJD >= jan21JD && nmJD < feb21JD)
283 {
284 int cnyYear, cnyMonth, cnyDay;
285 JulianDayToDate(nmJD, cnyYear, cnyMonth, cnyDay);
286
287 std::tm result = {};
288 result.tm_year = cnyYear - 1900;
289 result.tm_mon = cnyMonth - 1;
290 result.tm_mday = cnyDay;
291 mktime(&result);
292 return result;
293 }
294 }
295
296 // Fallback (should never happen for years 2000-2031)
297 std::tm fallback = {};
298 fallback.tm_year = year - 1900;
299 fallback.tm_mon = 0; // January
300 fallback.tm_mday = 25;
301 mktime(&fallback);
302 return fallback;
303}
static double CalculateNewMoon(double k)
Definition HolidayDateCalculator.cpp:188
static double DateToJulianDay(int year, int month, double day)
Definition HolidayDateCalculator.cpp:156

References CalculateNewMoon(), DateToJulianDay(), and JulianDayToDate().

Referenced by CalculateHolidayDate(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ CalculateNewMoon()

double HolidayDateCalculator::CalculateNewMoon ( double  k)
staticprivate
189{
190 // Meeus "Astronomical Algorithms" Chapter 49
191 double const T = k / 1236.85;
192 double const T2 = T * T;
193 double const T3 = T2 * T;
194 double const T4 = T3 * T;
195
196 // Mean phase (Eq 49.1)
197 double const JDE = 2451550.09766 + 29.530588861 * k + 0.00015437 * T2
198 - 0.000000150 * T3 + 0.00000000073 * T4;
199
200 // Eccentricity correction
201 double const E = 1.0 - 0.002516 * T - 0.0000074 * T2;
202 double const E2 = E * E;
203
204 // Sun's mean anomaly (Eq 49.4)
205 double const M = 2.5534 + 29.10535670 * k - 0.0000014 * T2 - 0.00000011 * T3;
206
207 // Moon's mean anomaly (Eq 49.5)
208 double const MPrime = 201.5643 + 385.81693528 * k + 0.0107582 * T2
209 + 0.00001238 * T3 - 0.000000058 * T4;
210
211 // Moon's argument of latitude (Eq 49.6)
212 double const F = 160.7108 + 390.67050284 * k - 0.0016118 * T2
213 - 0.00000227 * T3 + 0.000000011 * T4;
214
215 // Longitude of ascending node (Eq 49.7)
216 double const Omega = 124.7746 - 1.56375588 * k + 0.0020672 * T2 + 0.00000215 * T3;
217
218 // New Moon corrections (Table 49.A)
219 double correction =
220 - 0.40720 * sind(MPrime)
221 + 0.17241 * E * sind(M)
222 + 0.01608 * sind(2 * MPrime)
223 + 0.01039 * sind(2 * F)
224 + 0.00739 * E * sind(MPrime - M)
225 - 0.00514 * E * sind(MPrime + M)
226 + 0.00208 * E2 * sind(2 * M)
227 - 0.00111 * sind(MPrime - 2 * F)
228 - 0.00057 * sind(MPrime + 2 * F)
229 + 0.00056 * E * sind(2 * MPrime + M)
230 - 0.00042 * sind(3 * MPrime)
231 + 0.00042 * E * sind(M + 2 * F)
232 + 0.00038 * E * sind(M - 2 * F)
233 - 0.00024 * E * sind(2 * MPrime - M)
234 - 0.00017 * sind(Omega);
235
236 // Additional planetary corrections (Table 49.B)
237 double const A1 = 299.77 + 0.107408 * k - 0.009173 * T2;
238 double const A2 = 251.88 + 0.016321 * k;
239 double const A3 = 251.83 + 26.651886 * k;
240 double const A4 = 349.42 + 36.412478 * k;
241 double const A5 = 84.66 + 18.206239 * k;
242 double const A6 = 141.74 + 53.303771 * k;
243 double const A7 = 207.14 + 2.453732 * k;
244 double const A8 = 154.84 + 7.306860 * k;
245 double const A9 = 34.52 + 27.261239 * k;
246 double const A10 = 207.19 + 0.121824 * k;
247 double const A11 = 291.34 + 1.844379 * k;
248 double const A12 = 161.72 + 24.198154 * k;
249 double const A13 = 239.56 + 25.513099 * k;
250 double const A14 = 331.55 + 3.592518 * k;
251
252 correction += 0.000325 * sind(A1) + 0.000165 * sind(A2) + 0.000164 * sind(A3)
253 + 0.000126 * sind(A4) + 0.000110 * sind(A5) + 0.000062 * sind(A6)
254 + 0.000060 * sind(A7) + 0.000056 * sind(A8) + 0.000047 * sind(A9)
255 + 0.000042 * sind(A10) + 0.000040 * sind(A11) + 0.000037 * sind(A12)
256 + 0.000035 * sind(A13) + 0.000023 * sind(A14);
257
258 return JDE + correction;
259}
double sind(double deg)
Definition HolidayDateCalculator.cpp:27

References sind().

Referenced by CalculateLunarNewYear().

◆ CalculateNthWeekday()

std::tm HolidayDateCalculator::CalculateNthWeekday ( int  year,
int  month,
Weekday  weekday,
int  n 
)
static
113{
114 // Start with first day of the month
115 std::tm date = {};
116 date.tm_year = year - 1900;
117 date.tm_mon = month - 1;
118 date.tm_mday = 1;
119 mktime(&date);
120
121 // Find first occurrence of the target weekday
122 int const daysUntilWeekday = (static_cast<int>(weekday) - date.tm_wday + 7) % 7;
123 date.tm_mday = 1 + daysUntilWeekday;
124
125 // Move to nth occurrence
126 date.tm_mday += (n - 1) * 7;
127
128 mktime(&date); // Normalize (handles month overflow)
129 return date;
130}

Referenced by CalculateHolidayDate(), GetDarkmoonFaireDates(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ CalculateWeekdayOnOrAfter()

std::tm HolidayDateCalculator::CalculateWeekdayOnOrAfter ( int  year,
int  month,
int  day,
Weekday  weekday 
)
static
133{
134 // Start with the specified date
135 std::tm date = {};
136 date.tm_year = year - 1900;
137 date.tm_mon = month - 1;
138 date.tm_mday = day;
139 mktime(&date);
140
141 // Find days until the target weekday (0 if already on that day)
142 int const daysUntilWeekday = (static_cast<int>(weekday) - date.tm_wday + 7) % 7;
143 date.tm_mday += daysUntilWeekday;
144
145 mktime(&date); // Normalize
146 return date;
147}

Referenced by CalculateHolidayDate(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ CalculateWinterSolstice()

std::tm HolidayDateCalculator::CalculateWinterSolstice ( int  year)
static
367{
368 // Meeus algorithm for mean December solstice (Table 27.C)
369 // Valid for years 2000-3000
370 double const Y = (year - 2000.0) / 1000.0;
371 double const Y2 = Y * Y;
372 double const Y3 = Y2 * Y;
373 double const Y4 = Y3 * Y;
374
375 // Mean solstice JDE0 (Eq 27.1 for December solstice after 2000)
376 double const JDE0 = 2451900.05952 + 365242.74049 * Y - 0.06223 * Y2
377 - 0.00823 * Y3 + 0.00032 * Y4;
378
379 // Periodic terms for correction (Table 27.B)
380 double const T = (JDE0 - 2451545.0) / 36525.0;
381 double const W = 35999.373 * T - 2.47;
382 double const deltaLambda = 1.0 + 0.0334 * std::cos(W * DEG_TO_RAD)
383 + 0.0007 * std::cos(2.0 * W * DEG_TO_RAD);
384
385 // Simplified correction (sum of periodic terms from Table 27.C)
386 double const S = 485 * std::cos((324.96 + 1934.136 * T) * DEG_TO_RAD)
387 + 203 * std::cos((337.23 + 32964.467 * T) * DEG_TO_RAD)
388 + 199 * std::cos((342.08 + 20.186 * T) * DEG_TO_RAD)
389 + 182 * std::cos((27.85 + 445267.112 * T) * DEG_TO_RAD)
390 + 156 * std::cos((73.14 + 45036.886 * T) * DEG_TO_RAD)
391 + 136 * std::cos((171.52 + 22518.443 * T) * DEG_TO_RAD)
392 + 77 * std::cos((222.54 + 65928.934 * T) * DEG_TO_RAD)
393 + 74 * std::cos((296.72 + 3034.906 * T) * DEG_TO_RAD)
394 + 70 * std::cos((243.58 + 9037.513 * T) * DEG_TO_RAD)
395 + 58 * std::cos((119.81 + 33718.147 * T) * DEG_TO_RAD)
396 + 52 * std::cos((297.17 + 150.678 * T) * DEG_TO_RAD)
397 + 50 * std::cos((21.02 + 2281.226 * T) * DEG_TO_RAD);
398
399 double const JDE = JDE0 + (0.00001 * S) / deltaLambda;
400
401 // Convert JDE to calendar date
402 int solYear;
403 int solMonth;
404 int solDay;
405 JulianDayToDate(JDE, solYear, solMonth, solDay);
406
407 std::tm result = {};
408 result.tm_year = solYear - 1900;
409 result.tm_mon = solMonth - 1;
410 result.tm_mday = solDay;
411 mktime(&result);
412 return result;
413}

References DEG_TO_RAD, and JulianDayToDate().

Referenced by CalculateHolidayDate(), and TEST_F().

◆ DateToJulianDay()

double HolidayDateCalculator::DateToJulianDay ( int  year,
int  month,
double  day 
)
staticprivate
157{
158 if (month <= 2)
159 {
160 year -= 1;
161 month += 12;
162 }
163 int const A = year / 100;
164 int const B = 2 - A + (A / 4);
165 return std::floor(365.25 * (year + 4716)) + std::floor(30.6001 * (month + 1)) + day + B - 1524.5;
166}

Referenced by CalculateLunarNewYear().

◆ GetDarkmoonFaireDates()

std::vector< uint32_t > HolidayDateCalculator::GetDarkmoonFaireDates ( int  locationOffset,
int  startYear,
int  numYears,
int  dayOffset = 0 
)
static
555{
556 std::vector<uint32_t> dates;
557
558 // Darkmoon Faire is first Sunday of months where (month % 3) == locationOffset
559 // locationOffset 0: Mar, Jun, Sep, Dec - Elwynn (Alliance)
560 // locationOffset 1: Jan, Apr, Jul, Oct - Mulgore (Horde)
561 // locationOffset 2: Feb, May, Aug, Nov - Terokkar (Outland)
562
563 for (int year = startYear; year < startYear + numYears && year <= 2030; ++year)
564 {
565 for (int month = 1; month <= 12; ++month)
566 {
567 if (month % 3 == locationOffset)
568 {
569 // Calculate first Sunday of this month, then apply day offset
570 std::tm date = CalculateNthWeekday(year, month, Weekday::SUNDAY, 1);
571 if (dayOffset != 0)
572 {
573 date.tm_mday += dayOffset;
574 mktime(&date); // Normalize
575 }
576 dates.push_back(PackDate(date));
577 }
578 }
579 }
580
581 return dates;
582}
static uint32_t PackDate(const std::tm &date)
Definition HolidayDateCalculator.cpp:508

References CalculateNthWeekday(), PackDate(), and SUNDAY.

Referenced by GameEventMgr::LoadHolidayDates(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ GetHolidayRules()

const std::vector< HolidayRule > & HolidayDateCalculator::GetHolidayRules ( )
static
80{
81 return HolidayRules;
82}
static const std::vector< HolidayRule > HolidayRules
Definition HolidayDateCalculator.cpp:30

References HolidayRules.

Referenced by GameEventMgr::LoadHolidayDates(), TEST_F(), TEST_F(), and TEST_F().

◆ GetPackedHolidayDate()

uint32_t HolidayDateCalculator::GetPackedHolidayDate ( uint32_t  holidayId,
int  year 
)
static
542{
543 for (auto const& rule : HolidayRules)
544 {
545 if (rule.holidayId == holidayId)
546 {
547 std::tm const date = CalculateHolidayDate(rule, year);
548 return PackDate(date);
549 }
550 }
551 return 0; // Holiday not found
552}
static std::tm CalculateHolidayDate(const HolidayRule &rule, int year)
Definition HolidayDateCalculator.cpp:415

References CalculateHolidayDate(), HolidayRules, and PackDate().

Referenced by GameEventMgr::LoadHolidayDates(), and TEST_F().

◆ JulianDayToDate()

void HolidayDateCalculator::JulianDayToDate ( double  jd,
int &  year,
int &  month,
int &  day 
)
staticprivate
169{
170 jd += 0.5;
171 int const Z = static_cast<int>(jd);
172 int A = Z;
173 if (Z >= 2299161)
174 {
175 int const alpha = static_cast<int>((Z - 1867216.25) / 36524.25);
176 A = Z + 1 + alpha - (alpha / 4);
177 }
178 int const B = A + 1524;
179 int const C = static_cast<int>((B - 122.1) / 365.25);
180 int const D = static_cast<int>(365.25 * C);
181 int const E = static_cast<int>((B - D) / 30.6001);
182
183 day = B - D - static_cast<int>(30.6001 * E);
184 month = (E < 14) ? E - 1 : E - 13;
185 year = (month > 2) ? C - 4716 : C - 4715;
186}

Referenced by CalculateAutumnEquinox(), CalculateLunarNewYear(), and CalculateWinterSolstice().

◆ PackDate()

uint32_t HolidayDateCalculator::PackDate ( const std::tm &  date)
static
509{
510 // WoW packed date format (same as ByteBuffer::AppendPackedTime):
511 // bits 24-28: year offset from 2000 (5 bits = 0-31, valid years 2000-2031)
512 // bits 20-23: month (0-indexed)
513 // bits 14-19: day (0-indexed)
514 // bits 11-13: weekday (0=Sunday, 6=Saturday - POSIX tm_wday)
515 // bits 6-10: hour
516 // bits 0-5: minute
517 int const year = date.tm_year + 1900;
518 // Client uses 5-bit year offset from 2000, so years before 2000 clamp to 0.
519 // If client is patched to support earlier years, update this logic.
520 uint32_t const yearOffset = (year < 2000) ? 0 : static_cast<uint32_t>(year - 2000);
521 uint32_t const month = static_cast<uint32_t>(date.tm_mon); // Already 0-indexed
522 uint32_t const day = static_cast<uint32_t>(date.tm_mday - 1); // Convert to 0-indexed
523 uint32_t const weekday = static_cast<uint32_t>(date.tm_wday); // 0=Sunday, 6=Saturday
524
525 return (yearOffset << 24) | (month << 20) | (day << 14) | (weekday << 11);
526}

Referenced by GetDarkmoonFaireDates(), GetPackedHolidayDate(), TEST_F(), TEST_F(), and TEST_F().

◆ UnpackDate()

std::tm HolidayDateCalculator::UnpackDate ( uint32_t  packed)
static
529{
530 std::tm result = {};
531 result.tm_year = static_cast<int>(((packed >> 24) & 0x1F) + 2000 - 1900);
532 result.tm_mon = static_cast<int>((packed >> 20) & 0xF);
533 result.tm_mday = static_cast<int>(((packed >> 14) & 0x3F) + 1);
534 result.tm_wday = static_cast<int>((packed >> 11) & 0x7);
535 result.tm_hour = static_cast<int>((packed >> 6) & 0x1F);
536 result.tm_min = static_cast<int>(packed & 0x3F);
537 mktime(&result); // Normalize and fill in tm_yday, tm_isdst
538 return result;
539}

Referenced by GameEventMgr::LoadHolidayDates(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().


The documentation for this class was generated from the following files: