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.

677 lines
22KB

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