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.

678 lines
23KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. namespace TimeHelpers
  24. {
  25. static std::tm millisToLocal (int64 millis) noexcept
  26. {
  27. #if JUCE_WINDOWS && JUCE_MINGW
  28. time_t now = (time_t) (millis / 1000);
  29. return *localtime (&now);
  30. #elif JUCE_WINDOWS
  31. std::tm result;
  32. millis /= 1000;
  33. if (_localtime64_s (&result, &millis) != 0)
  34. zerostruct (result);
  35. return result;
  36. #else
  37. std::tm result;
  38. time_t now = (time_t) (millis / 1000);
  39. if (localtime_r (&now, &result) == nullptr)
  40. zerostruct (result);
  41. return result;
  42. #endif
  43. }
  44. static std::tm millisToUTC (int64 millis) noexcept
  45. {
  46. #if JUCE_WINDOWS && JUCE_MINGW
  47. time_t now = (time_t) (millis / 1000);
  48. return *gmtime (&now);
  49. #elif JUCE_WINDOWS
  50. std::tm result;
  51. millis /= 1000;
  52. if (_gmtime64_s (&result, &millis) != 0)
  53. zerostruct (result);
  54. return result;
  55. #else
  56. std::tm result;
  57. time_t now = (time_t) (millis / 1000);
  58. if (gmtime_r (&now, &result) == nullptr)
  59. zerostruct (result);
  60. return result;
  61. #endif
  62. }
  63. static int getUTCOffsetSeconds (const int64 millis) noexcept
  64. {
  65. std::tm utc = millisToUTC (millis);
  66. utc.tm_isdst = -1; // Treat this UTC time as local to find the offset
  67. return (int) ((millis / 1000) - (int64) mktime (&utc));
  68. }
  69. static int extendedModulo (const int64 value, const int modulo) noexcept
  70. {
  71. return (int) (value >= 0 ? (value % modulo)
  72. : (value - ((value / modulo) + 1) * modulo));
  73. }
  74. static inline String formatString (const String& format, const std::tm* const tm)
  75. {
  76. #if JUCE_ANDROID
  77. typedef CharPointer_UTF8 StringType;
  78. #elif JUCE_WINDOWS
  79. typedef CharPointer_UTF16 StringType;
  80. #else
  81. typedef CharPointer_UTF32 StringType;
  82. #endif
  83. #ifdef JUCE_MSVC
  84. if (tm->tm_year < -1900 || tm->tm_year > 8099)
  85. return String(); // Visual Studio's library can only handle 0 -> 9999 AD
  86. #endif
  87. for (size_t bufferSize = 256; ; bufferSize += 256)
  88. {
  89. HeapBlock<StringType::CharType> buffer (bufferSize);
  90. const size_t numChars =
  91. #if JUCE_ANDROID
  92. strftime (buffer, bufferSize - 1, format.toUTF8(), tm);
  93. #elif JUCE_WINDOWS
  94. wcsftime (buffer, bufferSize - 1, format.toWideCharPointer(), tm);
  95. #else
  96. wcsftime (buffer, bufferSize - 1, format.toUTF32(), tm);
  97. #endif
  98. if (numChars > 0 || format.isEmpty())
  99. return String (StringType (buffer),
  100. StringType (buffer) + (int) numChars);
  101. }
  102. }
  103. //==============================================================================
  104. static inline bool isLeapYear (int year) noexcept
  105. {
  106. return (year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0));
  107. }
  108. static inline int daysFromJan1 (int year, int month) noexcept
  109. {
  110. const short dayOfYear[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
  111. 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
  112. return dayOfYear [(isLeapYear (year) ? 12 : 0) + month];
  113. }
  114. static inline int64 daysFromYear0 (int year) noexcept
  115. {
  116. --year;
  117. return 365 * year + (year / 400) - (year / 100) + (year / 4);
  118. }
  119. static inline int64 daysFrom1970 (int year) noexcept
  120. {
  121. return daysFromYear0 (year) - daysFromYear0 (1970);
  122. }
  123. static inline int64 daysFrom1970 (int year, int month) noexcept
  124. {
  125. if (month > 11)
  126. {
  127. year += month / 12;
  128. month %= 12;
  129. }
  130. else if (month < 0)
  131. {
  132. const int numYears = (11 - month) / 12;
  133. year -= numYears;
  134. month += 12 * numYears;
  135. }
  136. return daysFrom1970 (year) + daysFromJan1 (year, month);
  137. }
  138. // There's no posix function that does a UTC version of mktime,
  139. // so annoyingly we need to implement this manually..
  140. static inline int64 mktime_utc (const std::tm& t) noexcept
  141. {
  142. return 24 * 3600 * (daysFrom1970 (t.tm_year + 1900, t.tm_mon) + (t.tm_mday - 1))
  143. + 3600 * t.tm_hour
  144. + 60 * t.tm_min
  145. + t.tm_sec;
  146. }
  147. static uint32 lastMSCounterValue = 0;
  148. }
  149. //==============================================================================
  150. Time::Time() noexcept : millisSinceEpoch (0)
  151. {
  152. }
  153. Time::Time (const Time& other) noexcept : millisSinceEpoch (other.millisSinceEpoch)
  154. {
  155. }
  156. Time::Time (const int64 ms) noexcept : millisSinceEpoch (ms)
  157. {
  158. }
  159. Time::Time (const int year,
  160. const int month,
  161. const int day,
  162. const int hours,
  163. const int minutes,
  164. const int seconds,
  165. const int milliseconds,
  166. const bool useLocalTime) noexcept
  167. {
  168. std::tm t;
  169. t.tm_year = year - 1900;
  170. t.tm_mon = month;
  171. t.tm_mday = day;
  172. t.tm_hour = hours;
  173. t.tm_min = minutes;
  174. t.tm_sec = seconds;
  175. t.tm_isdst = -1;
  176. millisSinceEpoch = 1000 * (useLocalTime ? (int64) mktime (&t)
  177. : TimeHelpers::mktime_utc (t))
  178. + milliseconds;
  179. }
  180. Time::~Time() noexcept
  181. {
  182. }
  183. Time& Time::operator= (const Time& other) noexcept
  184. {
  185. millisSinceEpoch = other.millisSinceEpoch;
  186. return *this;
  187. }
  188. //==============================================================================
  189. int64 Time::currentTimeMillis() noexcept
  190. {
  191. #if JUCE_WINDOWS && ! JUCE_MINGW
  192. struct _timeb t;
  193. _ftime_s (&t);
  194. return ((int64) t.time) * 1000 + t.millitm;
  195. #else
  196. struct timeval tv;
  197. gettimeofday (&tv, nullptr);
  198. return ((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
  199. #endif
  200. }
  201. Time JUCE_CALLTYPE Time::getCurrentTime() noexcept
  202. {
  203. return Time (currentTimeMillis());
  204. }
  205. //==============================================================================
  206. uint32 juce_millisecondsSinceStartup() noexcept;
  207. uint32 Time::getMillisecondCounter() noexcept
  208. {
  209. const uint32 now = juce_millisecondsSinceStartup();
  210. if (now < TimeHelpers::lastMSCounterValue)
  211. {
  212. // in multi-threaded apps this might be called concurrently, so
  213. // make sure that our last counter value only increases and doesn't
  214. // go backwards..
  215. if (now < TimeHelpers::lastMSCounterValue - 1000)
  216. TimeHelpers::lastMSCounterValue = now;
  217. }
  218. else
  219. {
  220. TimeHelpers::lastMSCounterValue = now;
  221. }
  222. return now;
  223. }
  224. uint32 Time::getApproximateMillisecondCounter() noexcept
  225. {
  226. if (TimeHelpers::lastMSCounterValue == 0)
  227. getMillisecondCounter();
  228. return TimeHelpers::lastMSCounterValue;
  229. }
  230. void Time::waitForMillisecondCounter (const uint32 targetTime) noexcept
  231. {
  232. for (;;)
  233. {
  234. const uint32 now = getMillisecondCounter();
  235. if (now >= targetTime)
  236. break;
  237. const int toWait = (int) (targetTime - now);
  238. if (toWait > 2)
  239. {
  240. Thread::sleep (jmin (20, toWait >> 1));
  241. }
  242. else
  243. {
  244. // xxx should consider using mutex_pause on the mac as it apparently
  245. // makes it seem less like a spinlock and avoids lowering the thread pri.
  246. for (int i = 10; --i >= 0;)
  247. Thread::yield();
  248. }
  249. }
  250. }
  251. //==============================================================================
  252. double Time::highResolutionTicksToSeconds (const int64 ticks) noexcept
  253. {
  254. return ticks / (double) getHighResolutionTicksPerSecond();
  255. }
  256. int64 Time::secondsToHighResolutionTicks (const double seconds) noexcept
  257. {
  258. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  259. }
  260. //==============================================================================
  261. String Time::toString (const bool includeDate,
  262. const bool includeTime,
  263. const bool includeSeconds,
  264. const bool use24HourClock) const noexcept
  265. {
  266. String result;
  267. if (includeDate)
  268. {
  269. result << getDayOfMonth() << ' '
  270. << getMonthName (true) << ' '
  271. << getYear();
  272. if (includeTime)
  273. result << ' ';
  274. }
  275. if (includeTime)
  276. {
  277. const int mins = getMinutes();
  278. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  279. << (mins < 10 ? ":0" : ":") << mins;
  280. if (includeSeconds)
  281. {
  282. const int secs = getSeconds();
  283. result << (secs < 10 ? ":0" : ":") << secs;
  284. }
  285. if (! use24HourClock)
  286. result << (isAfternoon() ? "pm" : "am");
  287. }
  288. return result.trimEnd();
  289. }
  290. String Time::formatted (const String& format) const
  291. {
  292. std::tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  293. return TimeHelpers::formatString (format, &t);
  294. }
  295. //==============================================================================
  296. int Time::getYear() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900; }
  297. int Time::getMonth() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon; }
  298. int Time::getDayOfYear() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_yday; }
  299. int Time::getDayOfMonth() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday; }
  300. int Time::getDayOfWeek() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday; }
  301. int Time::getHours() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour; }
  302. int Time::getMinutes() const noexcept { return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min; }
  303. int Time::getSeconds() const noexcept { return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60); }
  304. int Time::getMilliseconds() const noexcept { return TimeHelpers::extendedModulo (millisSinceEpoch, 1000); }
  305. int Time::getHoursInAmPmFormat() const noexcept
  306. {
  307. const int hours = getHours();
  308. if (hours == 0) return 12;
  309. if (hours <= 12) return hours;
  310. return hours - 12;
  311. }
  312. bool Time::isAfternoon() const noexcept
  313. {
  314. return getHours() >= 12;
  315. }
  316. bool Time::isDaylightSavingTime() const noexcept
  317. {
  318. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  319. }
  320. String Time::getTimeZone() const noexcept
  321. {
  322. String zone[2];
  323. #if JUCE_WINDOWS
  324. #if JUCE_MSVC || JUCE_CLANG
  325. _tzset();
  326. for (int i = 0; i < 2; ++i)
  327. {
  328. char name[128] = { 0 };
  329. size_t length;
  330. _get_tzname (&length, name, 127, i);
  331. zone[i] = name;
  332. }
  333. #else
  334. #warning "Can't find a replacement for tzset on mingw - ideas welcome!"
  335. #endif
  336. #else
  337. tzset();
  338. const char** const zonePtr = (const char**) tzname;
  339. zone[0] = zonePtr[0];
  340. zone[1] = zonePtr[1];
  341. #endif
  342. if (isDaylightSavingTime())
  343. {
  344. zone[0] = zone[1];
  345. if (zone[0].length() > 3
  346. && zone[0].containsIgnoreCase ("daylight")
  347. && zone[0].contains ("GMT"))
  348. zone[0] = "BST";
  349. }
  350. return zone[0].substring (0, 3);
  351. }
  352. int Time::getUTCOffsetSeconds() const noexcept
  353. {
  354. return TimeHelpers::getUTCOffsetSeconds (millisSinceEpoch);
  355. }
  356. String Time::getUTCOffsetString (bool includeSemiColon) const
  357. {
  358. if (int seconds = getUTCOffsetSeconds())
  359. {
  360. const int minutes = seconds / 60;
  361. return String::formatted (includeSemiColon ? "%+03d:%02d"
  362. : "%+03d%02d",
  363. minutes / 60,
  364. minutes % 60);
  365. }
  366. return "Z";
  367. }
  368. String Time::toISO8601 (bool includeDividerCharacters) const
  369. {
  370. return String::formatted (includeDividerCharacters ? "%04d-%02d-%02dT%02d:%02d:%06.03f"
  371. : "%04d%02d%02dT%02d%02d%06.03f",
  372. getYear(),
  373. getMonth() + 1,
  374. getDayOfMonth(),
  375. getHours(),
  376. getMinutes(),
  377. getSeconds() + getMilliseconds() / 1000.0)
  378. + getUTCOffsetString (includeDividerCharacters);
  379. }
  380. static int parseFixedSizeIntAndSkip (String::CharPointerType& t, int numChars, char charToSkip) noexcept
  381. {
  382. int n = 0;
  383. for (int i = numChars; --i >= 0;)
  384. {
  385. const int digit = (int) (*t - '0');
  386. if (! isPositiveAndBelow (digit, 10))
  387. return -1;
  388. ++t;
  389. n = n * 10 + digit;
  390. }
  391. if (charToSkip != 0 && *t == (juce_wchar) charToSkip)
  392. ++t;
  393. return n;
  394. }
  395. Time Time::fromISO8601 (StringRef iso) noexcept
  396. {
  397. String::CharPointerType t = iso.text;
  398. const int year = parseFixedSizeIntAndSkip (t, 4, '-');
  399. if (year < 0)
  400. return Time();
  401. const int month = parseFixedSizeIntAndSkip (t, 2, '-');
  402. if (month < 0)
  403. return Time();
  404. const int day = parseFixedSizeIntAndSkip (t, 2, 0);
  405. if (day < 0)
  406. return Time();
  407. int hours = 0, minutes = 0, milliseconds = 0;
  408. if (*t == 'T')
  409. {
  410. ++t;
  411. hours = parseFixedSizeIntAndSkip (t, 2, ':');
  412. if (hours < 0)
  413. return Time();
  414. minutes = parseFixedSizeIntAndSkip (t, 2, ':');
  415. if (minutes < 0)
  416. return Time();
  417. milliseconds = (int) (1000.0 * CharacterFunctions::readDoubleValue (t));
  418. }
  419. const juce_wchar nextChar = t.getAndAdvance();
  420. if (nextChar == '-' || nextChar == '+')
  421. {
  422. const int offsetHours = parseFixedSizeIntAndSkip (t, 2, ':');
  423. if (offsetHours < 0)
  424. return Time();
  425. const int offsetMinutes = parseFixedSizeIntAndSkip (t, 2, 0);
  426. if (offsetMinutes < 0)
  427. return Time();
  428. const int 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 Time();
  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") {}
  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