Utility functions for converting between date/time representations and seconds.
More...
#include <Utils/CDateTimeUtils.h>
|
| static unsigned long | getSecondByDate (const ITimer::RealTimeDate &date) |
| | Convert a ITimer::RealTimeDate structure to a total number of seconds.
|
| static unsigned long | getSecondByDate (int fromYear, int month, int day, int years, int hour, int minute, int second) |
| | Convert explicit date/time components to a total number of seconds.
|
| static unsigned long | getTimeBySecond () |
| | Get the current engine time represented in seconds.
|
| static void | setServerTime (unsigned long serverTime) |
| | Set the current synchronized server time in seconds.
|
| static void | unsetServerTime () |
| | Clear the synchronized server time state.
|
| static unsigned long | getServerTime () |
| | Get the synchronized server time in seconds.
|
| static void | getDateTimeBySecond (unsigned long second, int &day, int &hour, int &min, int &sec) |
| | Decompose a duration in seconds into days, hours, minutes and seconds.
|
| static ITimer::RealTimeDate | getDateBySecond (unsigned long second) |
| | Convert a seconds value into an ITimer::RealTimeDate.
|
| static long | getDateToSecond (int day) |
| | Convert a day count into seconds.
|
| static long | getHourToSecond (int hour) |
| | Convert an hour count into seconds.
|
Utility functions for converting between date/time representations and seconds.
CDateTimeUtils provides static helpers to:
- Convert an ITimer::RealTimeDate or date components to a number of seconds.
- Convert seconds into days/hours/minutes/seconds or into an ITimer::RealTimeDate.
- Convert simple day/hour counts into seconds.
All conversion functions use the same calendar rules (Gregorian calendar with leap years). The precise epoch or reference year used by the engine is intentionally left unspecified in these helpers; when using the overload that accepts fromYear, that parameter acts as the reference start year for the conversion.
- Note
- These utilities do not perform timezone conversions. If you need timezone-aware conversions or localization (DST shifting), handle those adjustments before calling these methods or use the engine's timer / platform time utilities.
- See also
- ITimer::RealTimeDate
◆ getDateBySecond()
| ITimer::RealTimeDate Skylicht::CDateTimeUtils::getDateBySecond |
( |
unsigned long | second | ) |
|
|
static |
Convert a seconds value into an ITimer::RealTimeDate.
This reverses the effect of getSecondByDate and returns a calendar date/time corresponding to the supplied seconds value according to the engine's conversion rules.
- Parameters
-
| second | Seconds value to convert (engine epoch). |
- Returns
- ITimer::RealTimeDate representing the given seconds value.
◆ getDateTimeBySecond()
| void Skylicht::CDateTimeUtils::getDateTimeBySecond |
( |
unsigned long | second, |
|
|
int & | day, |
|
|
int & | hour, |
|
|
int & | min, |
|
|
int & | sec ) |
|
static |
Decompose a duration in seconds into days, hours, minutes and seconds.
This converts a positive number of seconds into its equivalent component parts: days, hours, minutes and seconds. The day output is the number of full days, hour is the number of hours remaining after days are removed, etc.
- Parameters
-
| second | Input duration in seconds to decompose. |
| day | Output parameter that receives the number of full days. |
| hour | Output parameter that receives the remaining hours [0-23]. |
| min | Output parameter that receives the remaining minutes [0-59]. |
| sec | Output parameter that receives the remaining seconds [0-59]. |
◆ getDateToSecond()
| long Skylicht::CDateTimeUtils::getDateToSecond |
( |
int | day | ) |
|
|
static |
Convert a day count into seconds.
This is a simple utility that multiplies day by the number of seconds in a day (24 * 60 * 60). Use when you need to add or compare durations expressed in days.
- Parameters
-
- Returns
- Number of seconds corresponding to day days.
◆ getHourToSecond()
| long Skylicht::CDateTimeUtils::getHourToSecond |
( |
int | hour | ) |
|
|
static |
Convert an hour count into seconds.
Multiplies hour by the number of seconds in an hour (60 * 60).
- Parameters
-
- Returns
- Number of seconds corresponding to hour hours.
◆ getSecondByDate() [1/2]
| unsigned long Skylicht::CDateTimeUtils::getSecondByDate |
( |
const ITimer::RealTimeDate & | date | ) |
|
|
static |
Convert a ITimer::RealTimeDate structure to a total number of seconds.
The returned value represents the number of seconds that correspond to the provided date/time according to the engine's internal conversion rules (Gregorian calendar).
- Parameters
-
| date | The input date/time to convert. Fields are those defined in RealTimeDate (Year, Month [1-12], Day [1-31], Hour [0-23], Minute [0-59], Second). |
- Returns
- Total seconds representing the provided date relative to the engine's epoch.
◆ getSecondByDate() [2/2]
| unsigned long Skylicht::CDateTimeUtils::getSecondByDate |
( |
int | fromYear, |
|
|
int | month, |
|
|
int | day, |
|
|
int | years, |
|
|
int | hour, |
|
|
int | minute, |
|
|
int | second ) |
|
static |
Convert explicit date/time components to a total number of seconds.
Use this overload when you want to specify a reference start year (fromYear) from which to compute the total seconds. Leap years are taken into account when computing the result.
- Parameters
-
| fromYear | Reference start year (the epoch or base year for the conversion: 1970). |
| month | Month of the year [1-12]. |
| day | Day of the month [1-31]. |
| years | Absolute year value for the target date (e.g., 2026). |
| hour | Hour of the day [0-23]. |
| minute | Minute of the hour [0-59]. |
| second | Second of the minute [0-61]. |
- Returns
- Total seconds between fromYear and the specified date/time.
◆ getServerTime()
| unsigned long Skylicht::CDateTimeUtils::getServerTime |
( |
| ) |
|
|
static |
Get the synchronized server time in seconds.
If setServerTime has not been called, this returns 0. Otherwise it returns the last server time plus the elapsed application time since synchronization.
- Returns
- Current estimated server time in seconds, or 0 when not initialized.
◆ getTimeBySecond()
| unsigned long Skylicht::CDateTimeUtils::getTimeBySecond |
( |
| ) |
|
|
static |
Get the current engine time represented in seconds.
The returned value uses the same epoch/reference as the other conversion functions in this class. This is a convenience wrapper to obtain the current time as a numeric seconds value suitable for comparisons or arithmetic with values produced by getSecondByDate.
- Returns
- Current time in seconds (engine epoch).
◆ setServerTime()
| void Skylicht::CDateTimeUtils::setServerTime |
( |
unsigned long | serverTime | ) |
|
|
static |
Set the current synchronized server time in seconds.
Stores the provided server time together with the current application timer value. Later calls to getServerTime use the elapsed application time to estimate the corresponding server time.
- Parameters
-
| serverTime | Current server time in seconds. |
◆ unsetServerTime()
| void Skylicht::CDateTimeUtils::unsetServerTime |
( |
| ) |
|
|
static |
Clear the synchronized server time state.
Resets the cached server time and marks the server time as unavailable. After calling this function, getServerTime returns 0 until setServerTime is called again.
The documentation for this class was generated from the following file: