1#define CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
10#include <cppunit/TestFixture.h>
11#include <cppunit/extensions/HelperMacros.h>
21using namespace CPPUNIT_NS;
24static_assert(
DateTime().isNull(),
"isNull()");
25static_assert(
DateTime(1).totalTicks() == 1,
"construction with ticks");
31static constexpr auto dateFromUnixEpoch(
33static_assert(dateFromUnixEpoch.dayOfWeek() == DayOfWeek::Thursday,
"dayOfWeek()");
34static_assert(dateFromUnixEpoch.hour() == 1,
"hour()");
35static_assert(dateFromUnixEpoch.minute() == 2,
"minute()");
36static_assert(dateFromUnixEpoch.second() == 3,
"second()");
37static_assert(dateFromUnixEpoch.millisecond() == 125,
"millisecond()");
38static_assert(dateFromUnixEpoch.microsecond() == 678,
"microsecond()");
39static_assert(dateFromUnixEpoch.nanosecond() == 900,
"nanosecond()");
78 CPPUNIT_TEST_SUITE_END();
133 CPPUNIT_ASSERT_EQUAL(
"Tue 2016-01-26 20:32:11"s, fromTimeStampGmt.toString(DateTimeOutputFormat::DateTimeAndShortWeekday));
140 CPPUNIT_ASSERT_EQUAL(
"Tue 2016-01-26 20:32:11"s, fromChronoTimePointGmt.toString(DateTimeOutputFormat::DateTimeAndShortWeekday));
210 "1234-05-06T07:08:09.010"s,
DateTime::fromDateAndTime(1234, 5, 6, 7, 8, 9, 10).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
212 "1234-05-06T07:08:09"s,
DateTime::fromDateAndTime(1234, 5, 6, 7, 8, 9).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
214 "1234-05-06T07:08"s,
DateTime::fromDateAndTime(1234, 5, 6, 7, 8).toString(DateTimeOutputFormat::IsoOmittingDefaultComponents));
222#if defined(PLATFORM_UNIX)
235 auto parts = DateTimeParts::Year;
344 CPPUNIT_ASSERT(
test1.totalMinutes() > (2 * 24 * 60 + 34 * 60 + 53) &&
test1.totalHours() < (2 * 24 * 60 + 34 * 60 + 54));
390 const auto begin(
DateTime::fromDateAndTime(1994, 7, 18, 15, 30, 21)), end(
DateTime::fromDateAndTime(2017, 12, 2, 15, 30, 21));
CPPUNIT_TEST_SUITE_REGISTRATION(ChronoTests)
The ChronoTests class tests classes and functions provided by the files inside the chrono directory.
void testTimeSpan()
Tests most important TimeSpan features.
void testHashing()
Tests hashing DateTime / TimeSpan by using in a set.
void testOperators()
Tests operators of DateTime / TimeSpan.
void testDateTime()
Tests most important DateTime features.
void testPeriod()
Tests Period.
void testDateTimeExpression()
Tests parsing a DateTimeExpression.
The ConversionException class is thrown by the various conversion functions of this library when a co...
static constexpr DateTime fromTimeStampGmt(std::time_t timeStamp)
Constructs a new DateTime object with the GMT time from the specified UNIX timeStamp.
static constexpr DateTime unixEpochStart()
Returns the DateTime object for the "1970-01-01T00:00:00Z".
static constexpr DateTime fromChronoTimePointGmt(TimePoint timePoint)
Constructs a new DateTime object with the GMT time from the specified std::chrono::time_point.
static std::pair< DateTime, TimeSpan > fromIsoString(const char *str)
Parses the specified ISO date time denotation provided as C-style string.
static DateTime fromString(const std::string &str)
Parses the given std::string as DateTime.
static DateTime fromDateAndTime(int year=1, int month=1, int day=1, int hour=0, int minute=0, int second=0, double millisecond=0.0)
Constructs a DateTime to the specified year, month, day, hour, minute, second and millisecond.
static DateTime fromDate(int year=1, int month=1, int day=1)
Constructs a DateTime to the specified year, month, and day.
static DateTime gmtNow()
Returns a DateTime object that is set to the current date and time on this computer,...
static DateTime fromTimeStamp(std::time_t timeStamp)
Constructs a new DateTime object with the local time from the specified UNIX timeStamp.
constexpr bool isEternity() const
Returns whether the instance has the maximal number of ticks.
static DateTime fromIsoStringGmt(const char *str)
Parses the specified ISO date time denotation provided as C-style string.
static int daysInMonth(int year, int month)
Returns the number of days in the specified month and year.
static constexpr DateTime eternity()
Constructs a new instance of the DateTime class with the maximal number of ticks.
Represents a period of time.
Represents a time interval.
constexpr double totalHours() const
Returns the value of the current TimeSpan class expressed in whole and fractional hours.
constexpr double totalSeconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional seconds.
constexpr bool isNull() const
Returns true if the time interval represented by the current TimeSpan class is null.
constexpr int seconds() const
Returns the seconds component of the time interval represented by the current TimeSpan class.
constexpr bool isNegativeInfinity() const
Returns whether the time interval represented by the current instance is the smallest representable T...
constexpr int minutes() const
Returns the minutes component of the time interval represented by the current TimeSpan class.
constexpr double totalMicroseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional microseconds.
constexpr TickType totalTicks() const
Returns the number of ticks that represent the value of the current TimeSpan class.
constexpr int days() const
Returns the days component of the time interval represented by the current TimeSpan class.
constexpr int milliseconds() const
Returns the milliseconds component of the time interval represented by the current TimeSpan class.
static constexpr TimeSpan fromDays(double days)
Constructs a new instance of the TimeSpan class with the specified number of days.
static constexpr TimeSpan fromHours(double hours)
Constructs a new instance of the TimeSpan class with the specified number of hours.
static constexpr TimeSpan fromMinutes(double minutes)
Constructs a new instance of the TimeSpan class with the specified number of minutes.
static constexpr TimeSpan infinity()
Constructs a new instance of the TimeSpan class with the maximal number of ticks.
static constexpr TimeSpan fromSeconds(double seconds)
Constructs a new instance of the TimeSpan class with the specified number of seconds.
constexpr bool isInfinity() const
Returns whether the time interval represented by the current instance is the longest representable Ti...
static constexpr TimeSpan negativeInfinity()
Constructs a new instance of the TimeSpan class with the minimal number of ticks.
constexpr int microseconds() const
Returns the microseconds component of the time interval represented by the current TimeSpan class.
constexpr double totalDays() const
Returns the value of the current TimeSpan class expressed in whole and fractional days.
static TimeSpan fromString(const std::string &str, char separator=':')
Parses the given std::string as TimeSpan.
constexpr double totalMilliseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional milliseconds.
constexpr bool isNegative() const
Returns true if the time interval represented by the current TimeSpan class is negative.
constexpr int hours() const
Returns the hours component of the time interval represented by the current TimeSpan class.
constexpr double totalMinutes() const
Returns the value of the current TimeSpan class expressed in whole and fractional minutes.
constexpr int nanoseconds() const
Returns the nanoseconds component of the time interval represented by the current TimeSpan class.
static constexpr TimeSpan fromMilliseconds(double milliseconds)
Constructs a new instance of the TimeSpan class with the specified number of milliseconds.
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
Contains all utilities provides by the c++utilities library.
IntegralType stringToNumber(const StringType &string, BaseType base=10)
Converts the given string to an unsigned/signed number assuming string uses the specified base.
static DateTimeExpression fromString(const char *str)
Parses the given C-style string.
static DateTimeExpression fromIsoString(const char *str)
Parses the specified ISO date time denotation provided as C-style string.