AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Time Namespace Reference

Functions

template<class T >
AC_COMMON_API uint32 TimeStringTo (std::string_view timeString)
 
template<class T >
AC_COMMON_API std::string ToTimeString (uint64 durationTime, TimeOutput timeOutput=TimeOutput::Seconds, TimeFormat timeFormat=TimeFormat::ShortText)
 
template<class T >
AC_COMMON_API std::string ToTimeString (std::string_view durationTime, TimeOutput timeOutput=TimeOutput::Seconds, TimeFormat timeFormat=TimeFormat::ShortText)
 
AC_COMMON_API std::string ToTimeString (Microseconds durationTime, TimeOutput timeOutput=TimeOutput::Seconds, TimeFormat timeFormat=TimeFormat::ShortText)
 
AC_COMMON_API time_t LocalTimeToUTCTime (time_t time)
 
AC_COMMON_API time_t GetLocalHourTimestamp (time_t time, uint8 hour, bool onlyAfterTime=true)
 
AC_COMMON_API std::tm TimeBreakdown (time_t t=0)
 
AC_COMMON_API std::string TimeToTimestampStr (Seconds time=0s, std::string_view fmt={})
 
AC_COMMON_API std::string TimeToHumanReadable (Seconds time=0s, std::string_view fmt={})
 
AC_COMMON_API time_t GetNextTimeWithDayAndHour (int8 dayOfWeek, int8 hour)
 
AC_COMMON_API time_t GetNextTimeWithMonthAndHour (int8 month, int8 hour)
 
AC_COMMON_API uint32 GetSeconds (Seconds time=0s)
 
AC_COMMON_API uint32 GetMinutes (Seconds time=0s)
 
AC_COMMON_API uint32 GetHours (Seconds time=0s)
 
AC_COMMON_API uint32 GetDayInWeek (Seconds time=0s)
 
AC_COMMON_API uint32 GetDayInMonth (Seconds time=0s)
 
AC_COMMON_API uint32 GetDayInYear (Seconds time=0s)
 
AC_COMMON_API uint32 GetMonth (Seconds time=0s)
 
AC_COMMON_API uint32 GetYear (Seconds time=0s)
 

Function Documentation

◆ GetDayInMonth()

uint32 Acore::Time::GetDayInMonth ( Seconds  time = 0s)
405{
406 if (time == 0s)
407 {
408 time = GetEpochTime();
409 }
410
411 return TimeBreakdown(time.count()).tm_mday;
412}
Seconds GetEpochTime()
Definition: Timer.h:141

References GetEpochTime(), and TimeBreakdown().

◆ GetDayInWeek()

uint32 Acore::Time::GetDayInWeek ( Seconds  time = 0s)
395{
396 if (time == 0s)
397 {
398 time = GetEpochTime();
399 }
400
401 return TimeBreakdown(time.count()).tm_wday;
402}

References GetEpochTime(), and TimeBreakdown().

◆ GetDayInYear()

uint32 Acore::Time::GetDayInYear ( Seconds  time = 0s)
415{
416 if (time == 0s)
417 {
418 time = GetEpochTime();
419 }
420
421 return TimeBreakdown(time.count()).tm_yday;
422}

References GetEpochTime(), and TimeBreakdown().

Referenced by Weather::ReGenerate().

◆ GetHours()

uint32 Acore::Time::GetHours ( Seconds  time = 0s)
385{
386 if (time == 0s)
387 {
388 time = GetEpochTime();
389 }
390
391 return TimeBreakdown(time.count()).tm_hour;
392}

References GetEpochTime(), and TimeBreakdown().

◆ GetLocalHourTimestamp()

time_t Acore::Time::GetLocalHourTimestamp ( time_t  time,
uint8  hour,
bool  onlyAfterTime = true 
)
255{
256 tm timeLocal = TimeBreakdown(time);
257 timeLocal.tm_hour = 0;
258 timeLocal.tm_min = 0;
259 timeLocal.tm_sec = 0;
260
261 time_t midnightLocal = mktime(&timeLocal);
262 time_t hourLocal = midnightLocal + hour * HOUR;
263
264 if (onlyAfterTime && hourLocal <= time)
265 {
266 hourLocal += DAY;
267 }
268
269 return hourLocal;
270}
constexpr auto DAY
Definition: Common.h:49
constexpr auto HOUR
Definition: Common.h:48
AC_COMMON_API std::tm TimeBreakdown(time_t t=0)
Definition: Timer.cpp:233

References DAY, HOUR, and TimeBreakdown().

◆ GetMinutes()

uint32 Acore::Time::GetMinutes ( Seconds  time = 0s)
375{
376 if (time == 0s)
377 {
378 time = GetEpochTime();
379 }
380
381 return TimeBreakdown(time.count()).tm_min;
382}

References GetEpochTime(), and TimeBreakdown().

Referenced by npc_dark_iron_attack_generator::AllowStart().

◆ GetMonth()

uint32 Acore::Time::GetMonth ( Seconds  time = 0s)
425{
426 if (time == 0s)
427 {
428 time = GetEpochTime();
429 }
430
431 return TimeBreakdown(time.count()).tm_mon;
432}

References GetEpochTime(), and TimeBreakdown().

Referenced by Player::_LoadBrewOfTheMonth().

◆ GetNextTimeWithDayAndHour()

time_t Acore::Time::GetNextTimeWithDayAndHour ( int8  dayOfWeek,
int8  hour 
)
303{
304 if (hour < 0 || hour > 23)
305 {
306 hour = 0;
307 }
308
309 tm localTm = TimeBreakdown();
310 localTm.tm_hour = hour;
311 localTm.tm_min = 0;
312 localTm.tm_sec = 0;
313
314 if (dayOfWeek < 0 || dayOfWeek > 6)
315 {
316 dayOfWeek = (localTm.tm_wday + 1) % 7;
317 }
318
319 uint32 add;
320
321 if (localTm.tm_wday >= dayOfWeek)
322 {
323 add = (7 - (localTm.tm_wday - dayOfWeek)) * DAY;
324 }
325 else
326 {
327 add = (dayOfWeek - localTm.tm_wday) * DAY;
328 }
329
330 return mktime(&localTm) + add;
331}
std::uint32_t uint32
Definition: Define.h:107

References DAY, and TimeBreakdown().

Referenced by World::CalendarDeleteOldEvents(), World::InitCalendarOldEventsDeletionTime(), World::InitDailyQuestResetTime(), World::InitGuildResetTime(), World::InitMonthlyQuestResetTime(), World::InitRandomBGResetTime(), World::InitWeeklyQuestResetTime(), World::ResetDailyQuests(), World::ResetGuildCap(), World::ResetRandomBG(), and World::ResetWeeklyQuests().

◆ GetNextTimeWithMonthAndHour()

time_t Acore::Time::GetNextTimeWithMonthAndHour ( int8  month,
int8  hour 
)
334{
335 if (hour < 0 || hour > 23)
336 {
337 hour = 0;
338 }
339
340 tm localTm = TimeBreakdown();
341 localTm.tm_mday = 1;
342 localTm.tm_hour = hour;
343 localTm.tm_min = 0;
344 localTm.tm_sec = 0;
345
346 if (month < 0 || month > 11)
347 {
348 month = (localTm.tm_mon + 1) % 12;
349
350 if (!month)
351 {
352 localTm.tm_year += 1;
353 }
354 }
355 else if (localTm.tm_mon >= month)
356 {
357 localTm.tm_year += 1;
358 }
359
360 localTm.tm_mon = month;
361 return mktime(&localTm);
362}

References TimeBreakdown().

Referenced by World::ResetMonthlyQuests().

◆ GetSeconds()

uint32 Acore::Time::GetSeconds ( Seconds  time = 0s)
365{
366 if (time == 0s)
367 {
368 time = GetEpochTime();
369 }
370
371 return TimeBreakdown(time.count()).tm_sec;
372}

References GetEpochTime(), and TimeBreakdown().

◆ GetYear()

uint32 Acore::Time::GetYear ( Seconds  time = 0s)
435{
436 if (time == 0s)
437 {
438 time = GetEpochTime();
439 }
440
441 return TimeBreakdown(time.count()).tm_year;
442}

References GetEpochTime(), and TimeBreakdown().

◆ LocalTimeToUTCTime()

time_t Acore::Time::LocalTimeToUTCTime ( time_t  time)
246{
247#if AC_PLATFORM == AC_PLATFORM_WINDOWS
248 return time + _timezone;
249#else
250 return time + timezone;
251#endif
252}

◆ TimeBreakdown()

◆ TimeStringTo()

template<class T >
AC_COMMON_API uint32 Acore::Time::TimeStringTo ( std::string_view  timeString)

◆ TimeToHumanReadable()

std::string Acore::Time::TimeToHumanReadable ( Seconds  time = 0s,
std::string_view  fmt = {} 
)
288{
289 std::stringstream ss;
290 std::string format{ fmt };
291 time_t t = time.count();
292
293 if (format.empty())
294 {
295 format = "%a %b %d %Y %X";
296 }
297
298 ss << std::put_time(std::localtime(&t), format.c_str());
299 return ss.str();
300}

Referenced by misc_commandscript::HandleMuteInfoHelper().

◆ TimeToTimestampStr()

std::string Acore::Time::TimeToTimestampStr ( Seconds  time = 0s,
std::string_view  fmt = {} 
)
273{
274 std::stringstream ss;
275 std::string format{ fmt };
276 time_t t = time.count();
277
278 if (format.empty())
279 {
280 format = "%Y-%m-%d %X";
281 }
282
283 ss << std::put_time(std::localtime(&t), format.c_str());
284 return ss.str();
285}

Referenced by Log::GetTimestampStr(), LogMessage::getTimeStr(), character_commandscript::HandleCharacterDeletedListHelper(), and event_commandscript::HandleEventInfoCommand().

◆ ToTimeString() [1/3]

std::string Acore::Time::ToTimeString ( Microseconds  durationTime,
TimeOutput  timeOutput = TimeOutput::Seconds,
TimeFormat  timeFormat = TimeFormat::ShortText 
)
221{
222 return ToTimeString<Microseconds>(durationTime.count(), timeOutput, timeFormat);
223}

◆ ToTimeString() [2/3]

template<class T >
AC_COMMON_API std::string Acore::Time::ToTimeString ( std::string_view  durationTime,
TimeOutput  timeOutput = TimeOutput::Seconds,
TimeFormat  timeFormat = TimeFormat::ShortText 
)

◆ ToTimeString() [3/3]

template<class T >
AC_COMMON_API std::string Acore::Time::ToTimeString ( uint64  durationTime,
TimeOutput  timeOutput = TimeOutput::Seconds,
TimeFormat  timeFormat = TimeFormat::ShortText 
)