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.

688 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 Atomic<uint32> lastMSCounterValue { (uint32) 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.get())
  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.get() - (uint32) 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. auto t = TimeHelpers::lastMSCounterValue.get();
  218. return t == 0 ? getMillisecondCounter() : t;
  219. }
  220. void Time::waitForMillisecondCounter (uint32 targetTime) noexcept
  221. {
  222. for (;;)
  223. {
  224. auto now = getMillisecondCounter();
  225. if (now >= targetTime)
  226. break;
  227. auto toWait = (int) (targetTime - now);
  228. if (toWait > 2)
  229. {
  230. Thread::sleep (jmin (20, toWait >> 1));
  231. }
  232. else
  233. {
  234. // xxx should consider using mutex_pause on the mac as it apparently
  235. // makes it seem less like a spinlock and avoids lowering the thread pri.
  236. for (int i = 10; --i >= 0;)
  237. Thread::yield();
  238. }
  239. }
  240. }
  241. //==============================================================================
  242. double Time::highResolutionTicksToSeconds (const int64 ticks) noexcept
  243. {
  244. return ticks / (double) getHighResolutionTicksPerSecond();
  245. }
  246. int64 Time::secondsToHighResolutionTicks (const double seconds) noexcept
  247. {
  248. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  249. }
  250. //==============================================================================
  251. String Time::toString (const bool includeDate,
  252. const bool includeTime,
  253. const bool includeSeconds,
  254. const bool use24HourClock) const noexcept
  255. {
  256. String result;
  257. if (includeDate)
  258. {
  259. result << getDayOfMonth() << ' '
  260. << getMonthName (true) << ' '
  261. << getYear();
  262. if (includeTime)
  263. result << ' ';
  264. }
  265. if (includeTime)
  266. {
  267. auto mins = getMinutes();
  268. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  269. << (mins < 10 ? ":0" : ":") << mins;
  270. if (includeSeconds)
  271. {
  272. auto secs = getSeconds();
  273. result << (secs < 10 ? ":0" : ":") << secs;
  274. }
  275. if (! use24HourClock)
  276. result << (isAfternoon() ? "pm" : "am");
  277. }
  278. return result.trimEnd();
  279. }
  280. String Time::formatted (const String& format) const
  281. {
  282. std::tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  283. return TimeHelpers::formatString (format, &t);
  284. }
  285. //==============================================================================
  286. int Time::getYear() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900; }
  287. int Time::getMonth() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon; }
  288. int Time::getDayOfYear() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_yday; }
  289. int Time::getDayOfMonth() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday; }
  290. int Time::getDayOfWeek() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday; }
  291. int Time::getHours() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour; }
  292. int Time::getMinutes() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min; }
  293. int Time::getSeconds() const noexcept { return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60); }
  294. int Time::getMilliseconds() const noexcept { return TimeHelpers::extendedModulo (millisSinceEpoch, 1000); }
  295. int Time::getHoursInAmPmFormat() const noexcept
  296. {
  297. auto hours = getHours();
  298. if (hours == 0) return 12;
  299. if (hours <= 12) return hours;
  300. return hours - 12;
  301. }
  302. bool Time::isAfternoon() const noexcept
  303. {
  304. return getHours() >= 12;
  305. }
  306. bool Time::isDaylightSavingTime() const noexcept
  307. {
  308. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  309. }
  310. String Time::getTimeZone() const noexcept
  311. {
  312. String zone[2];
  313. #if JUCE_WINDOWS
  314. #if JUCE_MSVC || JUCE_CLANG
  315. _tzset();
  316. for (int i = 0; i < 2; ++i)
  317. {
  318. char name[128] = { 0 };
  319. size_t length;
  320. _get_tzname (&length, name, 127, i);
  321. zone[i] = name;
  322. }
  323. #else
  324. #warning "Can't find a replacement for tzset on mingw - ideas welcome!"
  325. #endif
  326. #else
  327. tzset();
  328. auto zonePtr = (const char**) tzname;
  329. zone[0] = zonePtr[0];
  330. zone[1] = zonePtr[1];
  331. #endif
  332. if (isDaylightSavingTime())
  333. {
  334. zone[0] = zone[1];
  335. if (zone[0].length() > 3
  336. && zone[0].containsIgnoreCase ("daylight")
  337. && zone[0].contains ("GMT"))
  338. zone[0] = "BST";
  339. }
  340. return zone[0].substring (0, 3);
  341. }
  342. int Time::getUTCOffsetSeconds() const noexcept
  343. {
  344. return TimeHelpers::getUTCOffsetSeconds (millisSinceEpoch);
  345. }
  346. String Time::getUTCOffsetString (bool includeSemiColon) const
  347. {
  348. if (int seconds = getUTCOffsetSeconds())
  349. {
  350. const int minutes = seconds / 60;
  351. return String::formatted (includeSemiColon ? "%+03d:%02d"
  352. : "%+03d%02d",
  353. minutes / 60,
  354. minutes % 60);
  355. }
  356. return "Z";
  357. }
  358. String Time::toISO8601 (bool includeDividerCharacters) const
  359. {
  360. return String::formatted (includeDividerCharacters ? "%04d-%02d-%02dT%02d:%02d:%06.03f"
  361. : "%04d%02d%02dT%02d%02d%06.03f",
  362. getYear(),
  363. getMonth() + 1,
  364. getDayOfMonth(),
  365. getHours(),
  366. getMinutes(),
  367. getSeconds() + getMilliseconds() / 1000.0)
  368. + getUTCOffsetString (includeDividerCharacters);
  369. }
  370. static int parseFixedSizeIntAndSkip (String::CharPointerType& t, int numChars, char charToSkip) noexcept
  371. {
  372. int n = 0;
  373. for (int i = numChars; --i >= 0;)
  374. {
  375. const int digit = (int) (*t - '0');
  376. if (! isPositiveAndBelow (digit, 10))
  377. return -1;
  378. ++t;
  379. n = n * 10 + digit;
  380. }
  381. if (charToSkip != 0 && *t == (juce_wchar) charToSkip)
  382. ++t;
  383. return n;
  384. }
  385. Time Time::fromISO8601 (StringRef iso) noexcept
  386. {
  387. auto t = iso.text;
  388. auto year = parseFixedSizeIntAndSkip (t, 4, '-');
  389. if (year < 0)
  390. return {};
  391. auto month = parseFixedSizeIntAndSkip (t, 2, '-');
  392. if (month < 0)
  393. return {};
  394. auto day = parseFixedSizeIntAndSkip (t, 2, 0);
  395. if (day < 0)
  396. return {};
  397. int hours = 0, minutes = 0, milliseconds = 0;
  398. if (*t == 'T')
  399. {
  400. ++t;
  401. hours = parseFixedSizeIntAndSkip (t, 2, ':');
  402. if (hours < 0)
  403. return {};
  404. minutes = parseFixedSizeIntAndSkip (t, 2, ':');
  405. if (minutes < 0)
  406. return {};
  407. auto seconds = parseFixedSizeIntAndSkip (t, 2, 0);
  408. if (seconds < 0)
  409. return {};
  410. if (*t == '.')
  411. {
  412. ++t;
  413. milliseconds = parseFixedSizeIntAndSkip (t, 3, 0);
  414. if (milliseconds < 0)
  415. return {};
  416. }
  417. milliseconds += 1000 * seconds;
  418. }
  419. auto nextChar = t.getAndAdvance();
  420. if (nextChar == '-' || nextChar == '+')
  421. {
  422. auto offsetHours = parseFixedSizeIntAndSkip (t, 2, ':');
  423. if (offsetHours < 0)
  424. return {};
  425. auto offsetMinutes = parseFixedSizeIntAndSkip (t, 2, 0);
  426. if (offsetMinutes < 0)
  427. return {};
  428. auto offsetMs = (offsetHours * 60 + offsetMinutes) * 60 * 1000;
  429. milliseconds += nextChar == '-' ? offsetMs : -offsetMs; // NB: this seems backwards but is correct!
  430. }
  431. else if (nextChar != 0 && nextChar != 'Z')
  432. {
  433. return {};
  434. }
  435. return Time (year, month - 1, day, hours, minutes, 0, milliseconds, false);
  436. }
  437. String Time::getMonthName (const bool threeLetterVersion) const
  438. {
  439. return getMonthName (getMonth(), threeLetterVersion);
  440. }
  441. String Time::getWeekdayName (const bool threeLetterVersion) const
  442. {
  443. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  444. }
  445. static const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  446. static const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  447. String Time::getMonthName (int monthNumber, const bool threeLetterVersion)
  448. {
  449. monthNumber %= 12;
  450. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  451. : longMonthNames [monthNumber]);
  452. }
  453. String Time::getWeekdayName (int day, const bool threeLetterVersion)
  454. {
  455. static const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  456. static const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  457. day %= 7;
  458. return TRANS (threeLetterVersion ? shortDayNames [day]
  459. : longDayNames [day]);
  460. }
  461. //==============================================================================
  462. Time& Time::operator+= (RelativeTime delta) noexcept { millisSinceEpoch += delta.inMilliseconds(); return *this; }
  463. Time& Time::operator-= (RelativeTime delta) noexcept { millisSinceEpoch -= delta.inMilliseconds(); return *this; }
  464. Time operator+ (Time time, RelativeTime delta) noexcept { Time t (time); return t += delta; }
  465. Time operator- (Time time, RelativeTime delta) noexcept { Time t (time); return t -= delta; }
  466. Time operator+ (RelativeTime delta, Time time) noexcept { Time t (time); return t += delta; }
  467. const RelativeTime operator- (Time time1, Time time2) noexcept { return RelativeTime::milliseconds (time1.toMilliseconds() - time2.toMilliseconds()); }
  468. bool operator== (Time time1, Time time2) noexcept { return 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. static int getMonthNumberForCompileDate (const String& m) noexcept
  475. {
  476. for (int i = 0; i < 12; ++i)
  477. if (m.equalsIgnoreCase (shortMonthNames[i]))
  478. return i;
  479. // If you hit this because your compiler has an unusual __DATE__
  480. // format, let us know so we can add support for it!
  481. jassertfalse;
  482. return 0;
  483. }
  484. Time Time::getCompilationDate()
  485. {
  486. StringArray dateTokens, timeTokens;
  487. dateTokens.addTokens (__DATE__, true);
  488. dateTokens.removeEmptyStrings (true);
  489. timeTokens.addTokens (__TIME__, ":", StringRef());
  490. return Time (dateTokens[2].getIntValue(),
  491. getMonthNumberForCompileDate (dateTokens[0]),
  492. dateTokens[1].getIntValue(),
  493. timeTokens[0].getIntValue(),
  494. timeTokens[1].getIntValue());
  495. }
  496. //==============================================================================
  497. //==============================================================================
  498. #if JUCE_UNIT_TESTS
  499. class TimeTests : public UnitTest
  500. {
  501. public:
  502. TimeTests() : UnitTest ("Time", "Time") {}
  503. void runTest() override
  504. {
  505. beginTest ("Time");
  506. Time t = Time::getCurrentTime();
  507. expect (t > Time());
  508. Thread::sleep (15);
  509. expect (Time::getCurrentTime() > t);
  510. expect (t.getTimeZone().isNotEmpty());
  511. expect (t.getUTCOffsetString (true) == "Z" || t.getUTCOffsetString (true).length() == 6);
  512. expect (t.getUTCOffsetString (false) == "Z" || t.getUTCOffsetString (false).length() == 5);
  513. expect (Time::fromISO8601 (t.toISO8601 (true)) == t);
  514. expect (Time::fromISO8601 (t.toISO8601 (false)) == t);
  515. expect (Time::fromISO8601 ("2016-02-16") == Time (2016, 1, 16, 0, 0, 0, 0, false));
  516. expect (Time::fromISO8601 ("20160216Z") == Time (2016, 1, 16, 0, 0, 0, 0, false));
  517. expect (Time::fromISO8601 ("2016-02-16T15:03:57+00:00") == Time (2016, 1, 16, 15, 3, 57, 0, false));
  518. expect (Time::fromISO8601 ("20160216T150357+0000") == Time (2016, 1, 16, 15, 3, 57, 0, false));
  519. expect (Time::fromISO8601 ("2016-02-16T15:03:57.999+00:00") == Time (2016, 1, 16, 15, 3, 57, 999, false));
  520. expect (Time::fromISO8601 ("20160216T150357.999+0000") == Time (2016, 1, 16, 15, 3, 57, 999, false));
  521. expect (Time::fromISO8601 ("2016-02-16T15:03:57.999Z") == Time (2016, 1, 16, 15, 3, 57, 999, false));
  522. expect (Time::fromISO8601 ("20160216T150357.999Z") == Time (2016, 1, 16, 15, 3, 57, 999, false));
  523. expect (Time::fromISO8601 ("2016-02-16T15:03:57.999-02:30") == Time (2016, 1, 16, 17, 33, 57, 999, false));
  524. expect (Time::fromISO8601 ("20160216T150357.999-0230") == Time (2016, 1, 16, 17, 33, 57, 999, false));
  525. expect (Time (1970, 0, 1, 0, 0, 0, 0, false) == Time (0));
  526. expect (Time (2106, 1, 7, 6, 28, 15, 0, false) == Time (4294967295000));
  527. expect (Time (2007, 10, 7, 1, 7, 20, 0, false) == Time (1194397640000));
  528. expect (Time (2038, 0, 19, 3, 14, 7, 0, false) == Time (2147483647000));
  529. expect (Time (2016, 2, 7, 11, 20, 8, 0, false) == Time (1457349608000));
  530. expect (Time (1969, 11, 31, 23, 59, 59, 0, false) == Time (-1000));
  531. expect (Time (1901, 11, 13, 20, 45, 53, 0, false) == Time (-2147483647000));
  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
  542. } // namespace juce