The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

670 lines
22KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace TimeHelpers
  18. {
  19. static std::tm millisToLocal (int64 millis) noexcept
  20. {
  21. #if JUCE_WINDOWS && JUCE_MINGW
  22. time_t now = (time_t) (millis / 1000);
  23. return *localtime (&now);
  24. #elif JUCE_WINDOWS
  25. std::tm result;
  26. millis /= 1000;
  27. if (_localtime64_s (&result, &millis) != 0)
  28. zerostruct (result);
  29. return result;
  30. #else
  31. std::tm result;
  32. time_t now = (time_t) (millis / 1000);
  33. if (localtime_r (&now, &result) == nullptr)
  34. zerostruct (result);
  35. return result;
  36. #endif
  37. }
  38. static std::tm millisToUTC (int64 millis) noexcept
  39. {
  40. #if JUCE_WINDOWS && JUCE_MINGW
  41. time_t now = (time_t) (millis / 1000);
  42. return *gmtime (&now);
  43. #elif JUCE_WINDOWS
  44. std::tm result;
  45. millis /= 1000;
  46. if (_gmtime64_s (&result, &millis) != 0)
  47. zerostruct (result);
  48. return result;
  49. #else
  50. std::tm result;
  51. time_t now = (time_t) (millis / 1000);
  52. if (gmtime_r (&now, &result) == nullptr)
  53. zerostruct (result);
  54. return result;
  55. #endif
  56. }
  57. static int getUTCOffsetSeconds (const int64 millis) noexcept
  58. {
  59. std::tm utc = millisToUTC (millis);
  60. utc.tm_isdst = -1; // Treat this UTC time as local to find the offset
  61. return (int) ((millis / 1000) - (int64) mktime (&utc));
  62. }
  63. static int extendedModulo (const int64 value, const int modulo) noexcept
  64. {
  65. return (int) (value >= 0 ? (value % modulo)
  66. : (value - ((value / modulo) + 1) * modulo));
  67. }
  68. static inline String formatString (const String& format, const std::tm* const tm)
  69. {
  70. #if JUCE_ANDROID
  71. typedef CharPointer_UTF8 StringType;
  72. #elif JUCE_WINDOWS
  73. typedef CharPointer_UTF16 StringType;
  74. #else
  75. typedef CharPointer_UTF32 StringType;
  76. #endif
  77. #ifdef JUCE_MSVC
  78. if (tm->tm_year < -1900 || tm->tm_year > 8099)
  79. return {}; // Visual Studio's library can only handle 0 -> 9999 AD
  80. #endif
  81. for (size_t bufferSize = 256; ; bufferSize += 256)
  82. {
  83. HeapBlock<StringType::CharType> buffer (bufferSize);
  84. const size_t numChars =
  85. #if JUCE_ANDROID
  86. strftime (buffer, bufferSize - 1, format.toUTF8(), tm);
  87. #elif JUCE_WINDOWS
  88. wcsftime (buffer, bufferSize - 1, format.toWideCharPointer(), tm);
  89. #else
  90. wcsftime (buffer, bufferSize - 1, format.toUTF32(), tm);
  91. #endif
  92. if (numChars > 0 || format.isEmpty())
  93. return String (StringType (buffer),
  94. StringType (buffer) + (int) numChars);
  95. }
  96. }
  97. //==============================================================================
  98. static inline bool isLeapYear (int year) noexcept
  99. {
  100. return (year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0));
  101. }
  102. static inline int daysFromJan1 (int year, int month) noexcept
  103. {
  104. const short dayOfYear[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
  105. 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
  106. return dayOfYear [(isLeapYear (year) ? 12 : 0) + month];
  107. }
  108. static inline int64 daysFromYear0 (int year) noexcept
  109. {
  110. --year;
  111. return 365 * year + (year / 400) - (year / 100) + (year / 4);
  112. }
  113. static inline int64 daysFrom1970 (int year) noexcept
  114. {
  115. return daysFromYear0 (year) - daysFromYear0 (1970);
  116. }
  117. static inline int64 daysFrom1970 (int year, int month) noexcept
  118. {
  119. if (month > 11)
  120. {
  121. year += month / 12;
  122. month %= 12;
  123. }
  124. else if (month < 0)
  125. {
  126. const int numYears = (11 - month) / 12;
  127. year -= numYears;
  128. month += 12 * numYears;
  129. }
  130. return daysFrom1970 (year) + daysFromJan1 (year, month);
  131. }
  132. // There's no posix function that does a UTC version of mktime,
  133. // so annoyingly we need to implement this manually..
  134. static inline int64 mktime_utc (const std::tm& t) noexcept
  135. {
  136. return 24 * 3600 * (daysFrom1970 (t.tm_year + 1900, t.tm_mon) + (t.tm_mday - 1))
  137. + 3600 * t.tm_hour
  138. + 60 * t.tm_min
  139. + t.tm_sec;
  140. }
  141. static uint32 lastMSCounterValue = 0;
  142. }
  143. //==============================================================================
  144. Time::Time() noexcept : millisSinceEpoch (0)
  145. {
  146. }
  147. Time::Time (const Time& other) noexcept : millisSinceEpoch (other.millisSinceEpoch)
  148. {
  149. }
  150. Time::Time (const int64 ms) noexcept : millisSinceEpoch (ms)
  151. {
  152. }
  153. Time::Time (const int year,
  154. const int month,
  155. const int day,
  156. const int hours,
  157. const int minutes,
  158. const int seconds,
  159. const int milliseconds,
  160. const bool useLocalTime) noexcept
  161. {
  162. std::tm t;
  163. t.tm_year = year - 1900;
  164. t.tm_mon = month;
  165. t.tm_mday = day;
  166. t.tm_hour = hours;
  167. t.tm_min = minutes;
  168. t.tm_sec = seconds;
  169. t.tm_isdst = -1;
  170. millisSinceEpoch = 1000 * (useLocalTime ? (int64) mktime (&t)
  171. : TimeHelpers::mktime_utc (t))
  172. + milliseconds;
  173. }
  174. Time::~Time() noexcept
  175. {
  176. }
  177. Time& Time::operator= (const Time& other) noexcept
  178. {
  179. millisSinceEpoch = other.millisSinceEpoch;
  180. return *this;
  181. }
  182. //==============================================================================
  183. int64 Time::currentTimeMillis() noexcept
  184. {
  185. #if JUCE_WINDOWS && ! JUCE_MINGW
  186. struct _timeb t;
  187. _ftime_s (&t);
  188. return ((int64) t.time) * 1000 + t.millitm;
  189. #else
  190. struct timeval tv;
  191. gettimeofday (&tv, nullptr);
  192. return ((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
  193. #endif
  194. }
  195. Time JUCE_CALLTYPE Time::getCurrentTime() noexcept
  196. {
  197. return Time (currentTimeMillis());
  198. }
  199. //==============================================================================
  200. uint32 juce_millisecondsSinceStartup() noexcept;
  201. uint32 Time::getMillisecondCounter() noexcept
  202. {
  203. const uint32 now = juce_millisecondsSinceStartup();
  204. if (now < TimeHelpers::lastMSCounterValue)
  205. {
  206. // in multi-threaded apps this might be called concurrently, so
  207. // make sure that our last counter value only increases and doesn't
  208. // go backwards..
  209. if (now < TimeHelpers::lastMSCounterValue - 1000)
  210. TimeHelpers::lastMSCounterValue = now;
  211. }
  212. else
  213. {
  214. TimeHelpers::lastMSCounterValue = now;
  215. }
  216. return now;
  217. }
  218. uint32 Time::getApproximateMillisecondCounter() noexcept
  219. {
  220. if (TimeHelpers::lastMSCounterValue == 0)
  221. getMillisecondCounter();
  222. return TimeHelpers::lastMSCounterValue;
  223. }
  224. void Time::waitForMillisecondCounter (const uint32 targetTime) noexcept
  225. {
  226. for (;;)
  227. {
  228. const uint32 now = getMillisecondCounter();
  229. if (now >= targetTime)
  230. break;
  231. const int toWait = (int) (targetTime - now);
  232. if (toWait > 2)
  233. {
  234. Thread::sleep (jmin (20, toWait >> 1));
  235. }
  236. else
  237. {
  238. // xxx should consider using mutex_pause on the mac as it apparently
  239. // makes it seem less like a spinlock and avoids lowering the thread pri.
  240. for (int i = 10; --i >= 0;)
  241. Thread::yield();
  242. }
  243. }
  244. }
  245. //==============================================================================
  246. double Time::highResolutionTicksToSeconds (const int64 ticks) noexcept
  247. {
  248. return ticks / (double) getHighResolutionTicksPerSecond();
  249. }
  250. int64 Time::secondsToHighResolutionTicks (const double seconds) noexcept
  251. {
  252. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  253. }
  254. //==============================================================================
  255. String Time::toString (const bool includeDate,
  256. const bool includeTime,
  257. const bool includeSeconds,
  258. const bool use24HourClock) const noexcept
  259. {
  260. String result;
  261. if (includeDate)
  262. {
  263. result << getDayOfMonth() << ' '
  264. << getMonthName (true) << ' '
  265. << getYear();
  266. if (includeTime)
  267. result << ' ';
  268. }
  269. if (includeTime)
  270. {
  271. const int mins = getMinutes();
  272. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  273. << (mins < 10 ? ":0" : ":") << mins;
  274. if (includeSeconds)
  275. {
  276. const int secs = getSeconds();
  277. result << (secs < 10 ? ":0" : ":") << secs;
  278. }
  279. if (! use24HourClock)
  280. result << (isAfternoon() ? "pm" : "am");
  281. }
  282. return result.trimEnd();
  283. }
  284. String Time::formatted (const String& format) const
  285. {
  286. std::tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  287. return TimeHelpers::formatString (format, &t);
  288. }
  289. //==============================================================================
  290. int Time::getYear() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900; }
  291. int Time::getMonth() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon; }
  292. int Time::getDayOfYear() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_yday; }
  293. int Time::getDayOfMonth() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday; }
  294. int Time::getDayOfWeek() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday; }
  295. int Time::getHours() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour; }
  296. int Time::getMinutes() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min; }
  297. int Time::getSeconds() const noexcept { return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60); }
  298. int Time::getMilliseconds() const noexcept { return TimeHelpers::extendedModulo (millisSinceEpoch, 1000); }
  299. int Time::getHoursInAmPmFormat() const noexcept
  300. {
  301. const int hours = getHours();
  302. if (hours == 0) return 12;
  303. if (hours <= 12) return hours;
  304. return hours - 12;
  305. }
  306. bool Time::isAfternoon() const noexcept
  307. {
  308. return getHours() >= 12;
  309. }
  310. bool Time::isDaylightSavingTime() const noexcept
  311. {
  312. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  313. }
  314. String Time::getTimeZone() const noexcept
  315. {
  316. String zone[2];
  317. #if JUCE_WINDOWS
  318. #if JUCE_MSVC || JUCE_CLANG
  319. _tzset();
  320. for (int i = 0; i < 2; ++i)
  321. {
  322. char name[128] = { 0 };
  323. size_t length;
  324. _get_tzname (&length, name, 127, i);
  325. zone[i] = name;
  326. }
  327. #else
  328. #warning "Can't find a replacement for tzset on mingw - ideas welcome!"
  329. #endif
  330. #else
  331. tzset();
  332. const char** const zonePtr = (const char**) tzname;
  333. zone[0] = zonePtr[0];
  334. zone[1] = zonePtr[1];
  335. #endif
  336. if (isDaylightSavingTime())
  337. {
  338. zone[0] = zone[1];
  339. if (zone[0].length() > 3
  340. && zone[0].containsIgnoreCase ("daylight")
  341. && zone[0].contains ("GMT"))
  342. zone[0] = "BST";
  343. }
  344. return zone[0].substring (0, 3);
  345. }
  346. int Time::getUTCOffsetSeconds() const noexcept
  347. {
  348. return TimeHelpers::getUTCOffsetSeconds (millisSinceEpoch);
  349. }
  350. String Time::getUTCOffsetString (bool includeSemiColon) const
  351. {
  352. if (int seconds = getUTCOffsetSeconds())
  353. {
  354. const int minutes = seconds / 60;
  355. return String::formatted (includeSemiColon ? "%+03d:%02d"
  356. : "%+03d%02d",
  357. minutes / 60,
  358. minutes % 60);
  359. }
  360. return "Z";
  361. }
  362. String Time::toISO8601 (bool includeDividerCharacters) const
  363. {
  364. return String::formatted (includeDividerCharacters ? "%04d-%02d-%02dT%02d:%02d:%06.03f"
  365. : "%04d%02d%02dT%02d%02d%06.03f",
  366. getYear(),
  367. getMonth() + 1,
  368. getDayOfMonth(),
  369. getHours(),
  370. getMinutes(),
  371. getSeconds() + getMilliseconds() / 1000.0)
  372. + getUTCOffsetString (includeDividerCharacters);
  373. }
  374. static int parseFixedSizeIntAndSkip (String::CharPointerType& t, int numChars, char charToSkip) noexcept
  375. {
  376. int n = 0;
  377. for (int i = numChars; --i >= 0;)
  378. {
  379. const int digit = (int) (*t - '0');
  380. if (! isPositiveAndBelow (digit, 10))
  381. return -1;
  382. ++t;
  383. n = n * 10 + digit;
  384. }
  385. if (charToSkip != 0 && *t == (juce_wchar) charToSkip)
  386. ++t;
  387. return n;
  388. }
  389. Time Time::fromISO8601 (StringRef iso) noexcept
  390. {
  391. String::CharPointerType t = iso.text;
  392. const int year = parseFixedSizeIntAndSkip (t, 4, '-');
  393. if (year < 0)
  394. return {};
  395. const int month = parseFixedSizeIntAndSkip (t, 2, '-');
  396. if (month < 0)
  397. return {};
  398. const int day = parseFixedSizeIntAndSkip (t, 2, 0);
  399. if (day < 0)
  400. return {};
  401. int hours = 0, minutes = 0, milliseconds = 0;
  402. if (*t == 'T')
  403. {
  404. ++t;
  405. hours = parseFixedSizeIntAndSkip (t, 2, ':');
  406. if (hours < 0)
  407. return {};
  408. minutes = parseFixedSizeIntAndSkip (t, 2, ':');
  409. if (minutes < 0)
  410. return {};
  411. milliseconds = (int) (1000.0 * CharacterFunctions::readDoubleValue (t));
  412. }
  413. const juce_wchar nextChar = t.getAndAdvance();
  414. if (nextChar == '-' || nextChar == '+')
  415. {
  416. const int offsetHours = parseFixedSizeIntAndSkip (t, 2, ':');
  417. if (offsetHours < 0)
  418. return {};
  419. const int offsetMinutes = parseFixedSizeIntAndSkip (t, 2, 0);
  420. if (offsetMinutes < 0)
  421. return {};
  422. const int offsetMs = (offsetHours * 60 + offsetMinutes) * 60 * 1000;
  423. milliseconds += nextChar == '-' ? offsetMs : -offsetMs; // NB: this seems backwards but is correct!
  424. }
  425. else if (nextChar != 0 && nextChar != 'Z')
  426. {
  427. return {};
  428. }
  429. return Time (year, month - 1, day, hours, minutes, 0, milliseconds, false);
  430. }
  431. String Time::getMonthName (const bool threeLetterVersion) const
  432. {
  433. return getMonthName (getMonth(), threeLetterVersion);
  434. }
  435. String Time::getWeekdayName (const bool threeLetterVersion) const
  436. {
  437. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  438. }
  439. static const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  440. static const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  441. String Time::getMonthName (int monthNumber, const bool threeLetterVersion)
  442. {
  443. monthNumber %= 12;
  444. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  445. : longMonthNames [monthNumber]);
  446. }
  447. String Time::getWeekdayName (int day, const bool threeLetterVersion)
  448. {
  449. static const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  450. static const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  451. day %= 7;
  452. return TRANS (threeLetterVersion ? shortDayNames [day]
  453. : longDayNames [day]);
  454. }
  455. //==============================================================================
  456. Time& Time::operator+= (RelativeTime delta) noexcept { millisSinceEpoch += delta.inMilliseconds(); return *this; }
  457. Time& Time::operator-= (RelativeTime delta) noexcept { millisSinceEpoch -= delta.inMilliseconds(); return *this; }
  458. Time operator+ (Time time, RelativeTime delta) noexcept { Time t (time); return t += delta; }
  459. Time operator- (Time time, RelativeTime delta) noexcept { Time t (time); return t -= delta; }
  460. Time operator+ (RelativeTime delta, Time time) noexcept { Time t (time); return t += delta; }
  461. const RelativeTime operator- (Time time1, Time time2) noexcept { return RelativeTime::milliseconds (time1.toMilliseconds() - time2.toMilliseconds()); }
  462. bool operator== (Time time1, Time time2) noexcept { return time1.toMilliseconds() == time2.toMilliseconds(); }
  463. bool operator!= (Time time1, Time time2) noexcept { return time1.toMilliseconds() != time2.toMilliseconds(); }
  464. bool operator< (Time time1, Time time2) noexcept { return time1.toMilliseconds() < time2.toMilliseconds(); }
  465. bool operator> (Time time1, Time time2) noexcept { return time1.toMilliseconds() > time2.toMilliseconds(); }
  466. bool operator<= (Time time1, Time time2) noexcept { return time1.toMilliseconds() <= time2.toMilliseconds(); }
  467. bool operator>= (Time time1, Time time2) noexcept { return time1.toMilliseconds() >= time2.toMilliseconds(); }
  468. static int getMonthNumberForCompileDate (const String& m) noexcept
  469. {
  470. for (int i = 0; i < 12; ++i)
  471. if (m.equalsIgnoreCase (shortMonthNames[i]))
  472. return i;
  473. // If you hit this because your compiler has an unusual __DATE__
  474. // format, let us know so we can add support for it!
  475. jassertfalse;
  476. return 0;
  477. }
  478. Time Time::getCompilationDate()
  479. {
  480. StringArray dateTokens, timeTokens;
  481. dateTokens.addTokens (__DATE__, true);
  482. dateTokens.removeEmptyStrings (true);
  483. timeTokens.addTokens (__TIME__, ":", StringRef());
  484. return Time (dateTokens[2].getIntValue(),
  485. getMonthNumberForCompileDate (dateTokens[0]),
  486. dateTokens[1].getIntValue(),
  487. timeTokens[0].getIntValue(),
  488. timeTokens[1].getIntValue());
  489. }
  490. //==============================================================================
  491. //==============================================================================
  492. #if JUCE_UNIT_TESTS
  493. class TimeTests : public UnitTest
  494. {
  495. public:
  496. TimeTests() : UnitTest ("Time") {}
  497. void runTest() override
  498. {
  499. beginTest ("Time");
  500. Time t = Time::getCurrentTime();
  501. expect (t > Time());
  502. Thread::sleep (15);
  503. expect (Time::getCurrentTime() > t);
  504. expect (t.getTimeZone().isNotEmpty());
  505. expect (t.getUTCOffsetString (true) == "Z" || t.getUTCOffsetString (true).length() == 6);
  506. expect (t.getUTCOffsetString (false) == "Z" || t.getUTCOffsetString (false).length() == 5);
  507. expect (Time::fromISO8601 (t.toISO8601 (true)) == t);
  508. expect (Time::fromISO8601 (t.toISO8601 (false)) == t);
  509. expect (Time::fromISO8601 ("2016-02-16") == Time (2016, 1, 16, 0, 0, 0, 0, false));
  510. expect (Time::fromISO8601 ("20160216Z") == Time (2016, 1, 16, 0, 0, 0, 0, false));
  511. expect (Time::fromISO8601 ("2016-02-16T15:03:57+00:00") == Time (2016, 1, 16, 15, 3, 57, 0, false));
  512. expect (Time::fromISO8601 ("20160216T150357+0000") == Time (2016, 1, 16, 15, 3, 57, 0, false));
  513. expect (Time::fromISO8601 ("2016-02-16T15:03:57.999+00:00") == Time (2016, 1, 16, 15, 3, 57, 999, false));
  514. expect (Time::fromISO8601 ("20160216T150357.999+0000") == Time (2016, 1, 16, 15, 3, 57, 999, false));
  515. expect (Time::fromISO8601 ("2016-02-16T15:03:57.999Z") == Time (2016, 1, 16, 15, 3, 57, 999, false));
  516. expect (Time::fromISO8601 ("20160216T150357.999Z") == Time (2016, 1, 16, 15, 3, 57, 999, false));
  517. expect (Time::fromISO8601 ("2016-02-16T15:03:57.999-02:30") == Time (2016, 1, 16, 17, 33, 57, 999, false));
  518. expect (Time::fromISO8601 ("20160216T150357.999-0230") == Time (2016, 1, 16, 17, 33, 57, 999, false));
  519. expect (Time (1970, 0, 1, 0, 0, 0, 0, false) == Time (0));
  520. expect (Time (2106, 1, 7, 6, 28, 15, 0, false) == Time (4294967295000));
  521. expect (Time (2007, 10, 7, 1, 7, 20, 0, false) == Time (1194397640000));
  522. expect (Time (2038, 0, 19, 3, 14, 7, 0, false) == Time (2147483647000));
  523. expect (Time (2016, 2, 7, 11, 20, 8, 0, false) == Time (1457349608000));
  524. expect (Time (1969, 11, 31, 23, 59, 59, 0, false) == Time (-1000));
  525. expect (Time (1901, 11, 13, 20, 45, 53, 0, false) == Time (-2147483647000));
  526. expect (Time (1982, 1, 1, 12, 0, 0, 0, true) + RelativeTime::days (365) == Time (1983, 1, 1, 12, 0, 0, 0, true));
  527. expect (Time (1970, 1, 1, 12, 0, 0, 0, true) + RelativeTime::days (365) == Time (1971, 1, 1, 12, 0, 0, 0, true));
  528. expect (Time (2038, 1, 1, 12, 0, 0, 0, true) + RelativeTime::days (365) == Time (2039, 1, 1, 12, 0, 0, 0, true));
  529. expect (Time (1982, 1, 1, 12, 0, 0, 0, false) + RelativeTime::days (365) == Time (1983, 1, 1, 12, 0, 0, 0, false));
  530. expect (Time (1970, 1, 1, 12, 0, 0, 0, false) + RelativeTime::days (365) == Time (1971, 1, 1, 12, 0, 0, 0, false));
  531. expect (Time (2038, 1, 1, 12, 0, 0, 0, false) + RelativeTime::days (365) == Time (2039, 1, 1, 12, 0, 0, 0, false));
  532. }
  533. };
  534. static TimeTests timeTests;
  535. #endif