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.

687 lines
23KB

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