From 2e6a8dc6a84322aab28fb0e600ee014a7d5db5e7 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 15 Feb 2016 20:29:52 +0100 Subject: [PATCH] added DateTime::gmtNow() --- chrono/datetime.cpp | 22 +++++++++++++++++----- chrono/datetime.h | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/chrono/datetime.cpp b/chrono/datetime.cpp index 0dc4e7e..e3f3d2d 100644 --- a/chrono/datetime.cpp +++ b/chrono/datetime.cpp @@ -36,20 +36,32 @@ inline bool inRangeExclMax(num1 val, num2 min, num3 max) } /*! - * \brief Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time. + * \brief Returns a DateTime object that is set to the current date and time on this computer, expressed as the local time. */ DateTime DateTime::now() { return DateTime::fromTimeStamp(time(nullptr)); } +/*! + * \brief Returns a DateTime object that is set to the current date and time on this computer, expressed as the GMT time. + */ +DateTime DateTime::gmtNow() +{ + return DateTime::fromTimeStampGmt(time(nullptr)); +} + /*! * \class ChronoUtilities::DateTime * \brief Represents an instant in time, typically expressed as a date and time of day. - * \remarks Time values are measured in 100-nanosecond units called ticks, - * and a particular date is the number of ticks since 12:00 midnight, January 1, - * 0001 A.D. (C.E.) in the GregorianCalendar calendar (excluding ticks that would - * be added by leap seconds). + * \remarks + * - Time values are measured in 100-nanosecond units called ticks, + * and a particular date is the number of ticks since 12:00 midnight, January 1, + * 0001 A.D. (C.E.) in the GregorianCalendar calendar (excluding ticks that would + * be added by leap seconds). + * - There is no time zone information associated. Hence different time zones are + * not taken into account when comparing two instances. For instance the + * expression (DateTime::now() - DateTime::gmtNow()) returns one hour in Germany (instead of zero). */ /*! diff --git a/chrono/datetime.h b/chrono/datetime.h index 1218a89..5398a80 100644 --- a/chrono/datetime.h +++ b/chrono/datetime.h @@ -84,6 +84,7 @@ public: static constexpr DateTime eternity(); static DateTime now(); + static DateTime gmtNow(); constexpr static bool isLeapYear(int year); static int daysInMonth(int year, int month);