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.

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