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.

685 lines
23KB

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