151 DateTime::operator time_t()
const 157 DateTime::operator tm()
const 165 DateTime::operator std::string()
const 173 time_t t = time(
nullptr);
183 time_t timeInSeconds = *
this;
187 double floorSec = std::floor(seconds);
189 timeInSeconds += time_t(floorSec);
198 float adjustmentToMake = newGMTOffset -
mGMTOffset;
199 double adjustmentToMakeInSec = adjustmentToMake * 60.0 * 60.0;
201 mGMTOffset = newGMTOffset;
207 time_t t = time(
nullptr);
218 time_t t = time(
nullptr);
228 void DateTime::GetTime(
unsigned& year,
unsigned& month,
unsigned& day,
unsigned& hour,
unsigned& min,
float& sec)
const 239 void DateTime::GetTime(
unsigned& year,
unsigned& month,
unsigned& day,
unsigned& hour,
unsigned& min,
unsigned& sec)
const 246 sec = unsigned(floorf((
float)
mSeconds));
250 void DateTime::GetGMTTime(
unsigned& year,
unsigned& month,
unsigned& day,
unsigned& hour,
unsigned& min,
float& sec)
const 262 void DateTime::GetGMTTime(
unsigned& year,
unsigned& month,
unsigned& day,
unsigned& hour,
unsigned& min,
unsigned& sec)
const 270 sec = unsigned(floorf((
float)dt.
mSeconds));
274 void DateTime::SetTime(
unsigned year,
unsigned month,
unsigned day,
unsigned hour,
unsigned min,
float sec)
286 void DateTime::SetTime(
unsigned year,
unsigned month,
unsigned day,
unsigned hour,
unsigned min,
unsigned sec)
309 mt.tm_year =
mYears - 1900;
342 time_t ret = _mkgmtime(&mt);
344 time_t ret = timegm(&mt);
386 mYears = mt.tm_year + 1900;
397 mGMTOffset = hourOffset + int(dayLightSavings);
408 float result = tz / 3600.0f;
410 if (factorLocalDayLightSavingsIntoGMTOffset)
412 result += timeParts.tm_isdst;
418 long tz = timeParts.tm_gmtoff;
419 float result = tz / 3600.0f;
421 if (!factorLocalDayLightSavingsIntoGMTOffset)
423 result -= timeParts.tm_isdst;
434 if (longitude < 0.0f)
439 mGMTOffset = float(
int(dayLightSavings) +
int((longitude + offset) / 15.0));
457 float seconds = std::floor(sec);
593 struct tm timeParts = *
this;
605 int tzHour = (int)floorf(tz);
606 int tzMin = (int)(tz -
float(tzHour));
609 _snprintf_s(buffer, 80,
"%04d-%02d-%02d T%02d:%02d:%02d%+03d:%02d",
611 snprintf(buffer, 80,
"%04d-%02d-%02d T%02d:%02d:%02d%+03d:%02d",
613 timeParts.tm_year + 1900, timeParts.tm_mon + 1, timeParts.tm_mday,
614 timeParts.tm_hour, timeParts.tm_min, timeParts.tm_sec,
621 strftime(buffer, 80,
"%F %T", &timeParts);
625 strftime(buffer, 80,
"%I:%M:%S %p", &timeParts);
629 strftime(buffer, 80,
"%x", &timeParts);
633 strftime(buffer, 80,
"%B %d, %Y", &timeParts);
637 strftime(buffer, 80,
"%Y-%m-%d", &timeParts);
641 strftime(buffer, 80,
"%H:%M:%S", &timeParts);
645 strftime(buffer, 80,
"%Y-W%U-%w", &timeParts);
649 strftime(buffer, 80,
"%Y-%j", &timeParts);
664 bool result = gmtime_s(&timeParts, t) != EINVAL;
666 bool result = gmtime_r(t, &timeParts) !=
nullptr;
674 memset(&timeParts, 0,
sizeof(tm));
683 bool result = localtime_s(&timeParts, t) != EINVAL;
685 bool result = localtime_r(t, &timeParts) !=
nullptr;
693 memset(&timeParts, 0,
sizeof(tm));
DateTime()
The default constructor just zeros.
unsigned GetMinute() const
Gets the minute.
void SetGMTOffset(float hourOffset, bool dayLightSavings)
Sets the GMTOffset which is added to the time when getting GMT time,.
void SetToGMTTime()
Changes time to be GMT- or Greenwich Mean Time.
static const TimeFormat CALENDAR_DATE_AND_TIME_FORMAT
CALENDAR_DATE_AND_TIME_FORMAT: 2008-04-18T13:22:50-05:00.
DateTime & operator=(const DateTime &)
Assignment operator.
static const TimeType TRIP_TIME
The trip time.
void SetToLocalTime()
Changes time to be system local time.
static void GetLocalTime(time_t *t, tm &timeParts)
Gets local time.
float mTimeScale
The time scale.
const TimeFormat * mStringFormat
The string format.
unsigned GetDay() const
Gets the day.
const TimeType & GetTimeType() const
The TimeType enumeration is used to identify the purpose of a DateTime instance.
void SetMonth(unsigned month)
Sets a month.
void SetSecond(float sec)
Sets a second.
static float CalcGMTOffset(tm &timeParts, bool factorLocalDayLightSavingsIntoGMTOffset)
Sets the GMTOffset using the systems local time this offset is added to the time when getting GMT tim...
virtual ~DateTime()
Destructor.
float GetTimeScale() const
The TimeScale can be used to scale the time when incrementing the clock.
static const TimeType TIME_STAMP
The time stamp.
void AdjustTimeZone(float newGMTOffset)
Every date time has a GMT offset.
static const TimeFormat LOCAL_DATE_AND_TIME_FORMAT
LOCAL_DATE_AND_TIME_FORMAT: 04-18-08 13:22:50.
double GetTimeInSeconds() const
Returns the total clock time in seconds elapsed since midnight, January 1, 1970 This time includes fr...
void IncrementClock(double seconds)
Increments the clock time by the number of seconds specified.
float GetGMTOffset() const
Gets the GMTOffset, this will be 0 unless SetGMTOffset was called or SetToLocalTime() was called...
const TimeType * mTimeType
Type of the time.
static const TimeFormat LOCAL_DATE_FORMAT
LOCAL_DATE_FORMAT: 04/18/08.
time_t GetTime() const
Gets the time in the standard time_t format, specified as seconds elapsed since midnight, January 1, 1970.
#define IMPLEMENT_ENUM(EnumType)
A macro that defines implement enum.
static const TimeType CLOCK_TIME
The clock time.
void SetYear(unsigned year)
Sets a year.
float GetSecond() const
Gets the second.
void SetDay(unsigned day)
Sets a day.
void SetMinute(unsigned min)
Sets a minute.
static float GetLocalGMTOffset(bool accountForDST=false)
Gets local GMT offset.
static const TimeFormat CLOCK_TIME_12_HOUR_FORMAT
CLOCK_TIME_12_HOUR_FORMAT: 01:22:50 PM.
void SetTimeScale(float percentScaleInSeconds)
The TimeScale can be used to scale the time when incrementing the clock.
void SetTimeOrigin(const TimeOrigin &)
The TimeOrigin enumeration determines how the instance of DateTime should be interpreted.
unsigned GetHour() const
Gets the hour.
float mGMTOffset
The GMT offset.
static const TimeOrigin LOCAL_TIME
The local time.
const TimeOrigin & GetTimeOrigin() const
The TimeOrigin enumeration determines how the instance of DateTime should be interpreted.
void ResetToDefaultValues()
Resets to default values.
void SetTimeFormat(const TimeFormat &)
The TimeFormat enumeration is used to specify how to map a DateTime object to a string.
static const TimeFormat CALENDAR_DATE_FORMAT
CALENDAR_DATE_FORMAT: 2008-04-18.
Namespace that holds various utility classes for the engine.
void SetHour(unsigned hour)
Sets a hour.
unsigned GetMonth() const
Gets the month.
time_t GetGMTTime() const
Gets the time in standard time_t format, the GMTOffset is added to the time before calculating time_t...
const TimeFormat & GetTimeFormat() const
The TimeFormat enumeration is used to specify how to map a DateTime object to a string.
unsigned GetYear() const
Gets the year.
static const TimeFormat WEEK_DATE_FORMAT
WEEK_DATE_FORMAT: 2008-W15-5.
std::string ToString() const
The no parameter version of ToString uses the internal TimeFormat, see the TimeFormat enumeration abo...
static const TimeOrigin GMT_TIME
The GMT time.
static const TimeFormat CLOCK_TIME_24_HOUR_FORMAT
CLOCK_TIME_24_HOUR_FORMAT: 13:22:50.
unsigned mYears
Store parts of time.
static const TimeType TIME_TYPE_OTHER
The time type other.
static const TimeFormat LEXICAL_DATE_FORMAT
LEXICAL_DATE_FORMAT: April 18, 2008.
const TimeOrigin * mTimeOrigin
The time origin.
void SetTimeType(const TimeType &)
The TimeType enumeration is used to identify the purpose of a DateTime instance.
double mFractionalSeconds
The fractional in seconds.
static const TimeType SIMULATION_TIME
The simulation time.
void GetTime(unsigned &year, unsigned &month, unsigned &day, unsigned &hour, unsigned &min, float &sec) const
Gets the time internally stored using unsigned year, month, day, hour, minute, and seconds...
void SetTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned min, float sec)
Sets the full time using year, month, day, hour, minute, and second.
static const TimeType SCENARIO_TIME
The scenario time.
static const TimeFormat ORDINAL_DATE_FORMAT
ORDINAL_DATE_FORMAT: 2008-109.