JulianDate.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. import sprintf from '../ThirdParty/sprintf.js';
  2. import binarySearch from './binarySearch.js';
  3. import defaultValue from './defaultValue.js';
  4. import defined from './defined.js';
  5. import DeveloperError from './DeveloperError.js';
  6. import GregorianDate from './GregorianDate.js';
  7. import isLeapYear from './isLeapYear.js';
  8. import LeapSecond from './LeapSecond.js';
  9. import TimeConstants from './TimeConstants.js';
  10. import TimeStandard from './TimeStandard.js';
  11. var gregorianDateScratch = new GregorianDate();
  12. var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  13. var daysInLeapFeburary = 29;
  14. function compareLeapSecondDates(leapSecond, dateToFind) {
  15. return JulianDate.compare(leapSecond.julianDate, dateToFind.julianDate);
  16. }
  17. // we don't really need a leap second instance, anything with a julianDate property will do
  18. var binarySearchScratchLeapSecond = new LeapSecond();
  19. function convertUtcToTai(julianDate) {
  20. //Even though julianDate is in UTC, we'll treat it as TAI and
  21. //search the leap second table for it.
  22. binarySearchScratchLeapSecond.julianDate = julianDate;
  23. var leapSeconds = JulianDate.leapSeconds;
  24. var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, compareLeapSecondDates);
  25. if (index < 0) {
  26. index = ~index;
  27. }
  28. if (index >= leapSeconds.length) {
  29. index = leapSeconds.length - 1;
  30. }
  31. var offset = leapSeconds[index].offset;
  32. if (index > 0) {
  33. //Now we have the index of the closest leap second that comes on or after our UTC time.
  34. //However, if the difference between the UTC date being converted and the TAI
  35. //defined leap second is greater than the offset, we are off by one and need to use
  36. //the previous leap second.
  37. var difference = JulianDate.secondsDifference(leapSeconds[index].julianDate, julianDate);
  38. if (difference > offset) {
  39. index--;
  40. offset = leapSeconds[index].offset;
  41. }
  42. }
  43. JulianDate.addSeconds(julianDate, offset, julianDate);
  44. }
  45. function convertTaiToUtc(julianDate, result) {
  46. binarySearchScratchLeapSecond.julianDate = julianDate;
  47. var leapSeconds = JulianDate.leapSeconds;
  48. var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, compareLeapSecondDates);
  49. if (index < 0) {
  50. index = ~index;
  51. }
  52. //All times before our first leap second get the first offset.
  53. if (index === 0) {
  54. return JulianDate.addSeconds(julianDate, -leapSeconds[0].offset, result);
  55. }
  56. //All times after our leap second get the last offset.
  57. if (index >= leapSeconds.length) {
  58. return JulianDate.addSeconds(julianDate, -leapSeconds[index - 1].offset, result);
  59. }
  60. //Compute the difference between the found leap second and the time we are converting.
  61. var difference = JulianDate.secondsDifference(leapSeconds[index].julianDate, julianDate);
  62. if (difference === 0) {
  63. //The date is in our leap second table.
  64. return JulianDate.addSeconds(julianDate, -leapSeconds[index].offset, result);
  65. }
  66. if (difference <= 1.0) {
  67. //The requested date is during the moment of a leap second, then we cannot convert to UTC
  68. return undefined;
  69. }
  70. //The time is in between two leap seconds, index is the leap second after the date
  71. //we're converting, so we subtract one to get the correct LeapSecond instance.
  72. return JulianDate.addSeconds(julianDate, -leapSeconds[--index].offset, result);
  73. }
  74. function setComponents(wholeDays, secondsOfDay, julianDate) {
  75. var extraDays = (secondsOfDay / TimeConstants.SECONDS_PER_DAY) | 0;
  76. wholeDays += extraDays;
  77. secondsOfDay -= TimeConstants.SECONDS_PER_DAY * extraDays;
  78. if (secondsOfDay < 0) {
  79. wholeDays--;
  80. secondsOfDay += TimeConstants.SECONDS_PER_DAY;
  81. }
  82. julianDate.dayNumber = wholeDays;
  83. julianDate.secondsOfDay = secondsOfDay;
  84. return julianDate;
  85. }
  86. function computeJulianDateComponents(year, month, day, hour, minute, second, millisecond) {
  87. // Algorithm from page 604 of the Explanatory Supplement to the
  88. // Astronomical Almanac (Seidelmann 1992).
  89. var a = ((month - 14) / 12) | 0;
  90. var b = year + 4800 + a;
  91. var dayNumber = (((1461 * b) / 4) | 0) + (((367 * (month - 2 - 12 * a)) / 12) | 0) - (((3 * (((b + 100) / 100) | 0)) / 4) | 0) + day - 32075;
  92. // JulianDates are noon-based
  93. hour = hour - 12;
  94. if (hour < 0) {
  95. hour += 24;
  96. }
  97. var secondsOfDay = second + ((hour * TimeConstants.SECONDS_PER_HOUR) + (minute * TimeConstants.SECONDS_PER_MINUTE) + (millisecond * TimeConstants.SECONDS_PER_MILLISECOND));
  98. if (secondsOfDay >= 43200.0) {
  99. dayNumber -= 1;
  100. }
  101. return [dayNumber, secondsOfDay];
  102. }
  103. //Regular expressions used for ISO8601 date parsing.
  104. //YYYY
  105. var matchCalendarYear = /^(\d{4})$/;
  106. //YYYY-MM (YYYYMM is invalid)
  107. var matchCalendarMonth = /^(\d{4})-(\d{2})$/;
  108. //YYYY-DDD or YYYYDDD
  109. var matchOrdinalDate = /^(\d{4})-?(\d{3})$/;
  110. //YYYY-Www or YYYYWww or YYYY-Www-D or YYYYWwwD
  111. var matchWeekDate = /^(\d{4})-?W(\d{2})-?(\d{1})?$/;
  112. //YYYY-MM-DD or YYYYMMDD
  113. var matchCalendarDate = /^(\d{4})-?(\d{2})-?(\d{2})$/;
  114. // Match utc offset
  115. var utcOffset = /([Z+\-])?(\d{2})?:?(\d{2})?$/;
  116. // Match hours HH or HH.xxxxx
  117. var matchHours = /^(\d{2})(\.\d+)?/.source + utcOffset.source;
  118. // Match hours/minutes HH:MM HHMM.xxxxx
  119. var matchHoursMinutes = /^(\d{2}):?(\d{2})(\.\d+)?/.source + utcOffset.source;
  120. // Match hours/minutes HH:MM:SS HHMMSS.xxxxx
  121. var matchHoursMinutesSeconds = /^(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?/.source + utcOffset.source;
  122. var iso8601ErrorMessage = 'Invalid ISO 8601 date.';
  123. /**
  124. * Represents an astronomical Julian date, which is the number of days since noon on January 1, -4712 (4713 BC).
  125. * For increased precision, this class stores the whole number part of the date and the seconds
  126. * part of the date in separate components. In order to be safe for arithmetic and represent
  127. * leap seconds, the date is always stored in the International Atomic Time standard
  128. * {@link TimeStandard.TAI}.
  129. * @alias JulianDate
  130. * @constructor
  131. *
  132. * @param {Number} [julianDayNumber=0.0] The Julian Day Number representing the number of whole days. Fractional days will also be handled correctly.
  133. * @param {Number} [secondsOfDay=0.0] The number of seconds into the current Julian Day Number. Fractional seconds, negative seconds and seconds greater than a day will be handled correctly.
  134. * @param {TimeStandard} [timeStandard=TimeStandard.UTC] The time standard in which the first two parameters are defined.
  135. */
  136. function JulianDate(julianDayNumber, secondsOfDay, timeStandard) {
  137. /**
  138. * Gets or sets the number of whole days.
  139. * @type {Number}
  140. */
  141. this.dayNumber = undefined;
  142. /**
  143. * Gets or sets the number of seconds into the current day.
  144. * @type {Number}
  145. */
  146. this.secondsOfDay = undefined;
  147. julianDayNumber = defaultValue(julianDayNumber, 0.0);
  148. secondsOfDay = defaultValue(secondsOfDay, 0.0);
  149. timeStandard = defaultValue(timeStandard, TimeStandard.UTC);
  150. //If julianDayNumber is fractional, make it an integer and add the number of seconds the fraction represented.
  151. var wholeDays = julianDayNumber | 0;
  152. secondsOfDay = secondsOfDay + (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY;
  153. setComponents(wholeDays, secondsOfDay, this);
  154. if (timeStandard === TimeStandard.UTC) {
  155. convertUtcToTai(this);
  156. }
  157. }
  158. /**
  159. * Creates a new instance from a GregorianDate.
  160. *
  161. * @param {GregorianDate} date A GregorianDate.
  162. * @param {JulianDate} [result] An existing instance to use for the result.
  163. * @returns {JulianDate} The modified result parameter or a new instance if none was provided.
  164. *
  165. * @exception {DeveloperError} date must be a valid GregorianDate.
  166. */
  167. JulianDate.fromGregorianDate = function(date, result) {
  168. //>>includeStart('debug', pragmas.debug);
  169. if (!(date instanceof GregorianDate)) {
  170. throw new DeveloperError('date must be a valid GregorianDate.');
  171. }
  172. //>>includeEnd('debug');
  173. var components = computeJulianDateComponents(date.year, date.month, date.day, date.hour, date.minute, date.second, date.millisecond);
  174. if (!defined(result)) {
  175. return new JulianDate(components[0], components[1], TimeStandard.UTC);
  176. }
  177. setComponents(components[0], components[1], result);
  178. convertUtcToTai(result);
  179. return result;
  180. };
  181. /**
  182. * Creates a new instance from a JavaScript Date.
  183. *
  184. * @param {Date} date A JavaScript Date.
  185. * @param {JulianDate} [result] An existing instance to use for the result.
  186. * @returns {JulianDate} The modified result parameter or a new instance if none was provided.
  187. *
  188. * @exception {DeveloperError} date must be a valid JavaScript Date.
  189. */
  190. JulianDate.fromDate = function(date, result) {
  191. //>>includeStart('debug', pragmas.debug);
  192. if (!(date instanceof Date) || isNaN(date.getTime())) {
  193. throw new DeveloperError('date must be a valid JavaScript Date.');
  194. }
  195. //>>includeEnd('debug');
  196. var components = computeJulianDateComponents(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());
  197. if (!defined(result)) {
  198. return new JulianDate(components[0], components[1], TimeStandard.UTC);
  199. }
  200. setComponents(components[0], components[1], result);
  201. convertUtcToTai(result);
  202. return result;
  203. };
  204. /**
  205. * Creates a new instance from a from an {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} date.
  206. * This method is superior to <code>Date.parse</code> because it will handle all valid formats defined by the ISO 8601
  207. * specification, including leap seconds and sub-millisecond times, which discarded by most JavaScript implementations.
  208. *
  209. * @param {String} iso8601String An ISO 8601 date.
  210. * @param {JulianDate} [result] An existing instance to use for the result.
  211. * @returns {JulianDate} The modified result parameter or a new instance if none was provided.
  212. *
  213. * @exception {DeveloperError} Invalid ISO 8601 date.
  214. */
  215. JulianDate.fromIso8601 = function(iso8601String, result) {
  216. //>>includeStart('debug', pragmas.debug);
  217. if (typeof iso8601String !== 'string') {
  218. throw new DeveloperError(iso8601ErrorMessage);
  219. }
  220. //>>includeEnd('debug');
  221. //Comma and decimal point both indicate a fractional number according to ISO 8601,
  222. //start out by blanket replacing , with . which is the only valid such symbol in JS.
  223. iso8601String = iso8601String.replace(',', '.');
  224. //Split the string into its date and time components, denoted by a mandatory T
  225. var tokens = iso8601String.split('T');
  226. var year;
  227. var month = 1;
  228. var day = 1;
  229. var hour = 0;
  230. var minute = 0;
  231. var second = 0;
  232. var millisecond = 0;
  233. //Lacking a time is okay, but a missing date is illegal.
  234. var date = tokens[0];
  235. var time = tokens[1];
  236. var tmp;
  237. var inLeapYear;
  238. //>>includeStart('debug', pragmas.debug);
  239. if (!defined(date)) {
  240. throw new DeveloperError(iso8601ErrorMessage);
  241. }
  242. var dashCount;
  243. //>>includeEnd('debug');
  244. //First match the date against possible regular expressions.
  245. tokens = date.match(matchCalendarDate);
  246. if (tokens !== null) {
  247. //>>includeStart('debug', pragmas.debug);
  248. dashCount = date.split('-').length - 1;
  249. if (dashCount > 0 && dashCount !== 2) {
  250. throw new DeveloperError(iso8601ErrorMessage);
  251. }
  252. //>>includeEnd('debug');
  253. year = +tokens[1];
  254. month = +tokens[2];
  255. day = +tokens[3];
  256. } else {
  257. tokens = date.match(matchCalendarMonth);
  258. if (tokens !== null) {
  259. year = +tokens[1];
  260. month = +tokens[2];
  261. } else {
  262. tokens = date.match(matchCalendarYear);
  263. if (tokens !== null) {
  264. year = +tokens[1];
  265. } else {
  266. //Not a year/month/day so it must be an ordinal date.
  267. var dayOfYear;
  268. tokens = date.match(matchOrdinalDate);
  269. if (tokens !== null) {
  270. year = +tokens[1];
  271. dayOfYear = +tokens[2];
  272. inLeapYear = isLeapYear(year);
  273. //This validation is only applicable for this format.
  274. //>>includeStart('debug', pragmas.debug);
  275. if (dayOfYear < 1 || (inLeapYear && dayOfYear > 366) || (!inLeapYear && dayOfYear > 365)) {
  276. throw new DeveloperError(iso8601ErrorMessage);
  277. }
  278. //>>includeEnd('debug')
  279. } else {
  280. tokens = date.match(matchWeekDate);
  281. if (tokens !== null) {
  282. //ISO week date to ordinal date from
  283. //http://en.wikipedia.org/w/index.php?title=ISO_week_date&oldid=474176775
  284. year = +tokens[1];
  285. var weekNumber = +tokens[2];
  286. var dayOfWeek = +tokens[3] || 0;
  287. //>>includeStart('debug', pragmas.debug);
  288. dashCount = date.split('-').length - 1;
  289. if (dashCount > 0 &&
  290. ((!defined(tokens[3]) && dashCount !== 1) ||
  291. (defined(tokens[3]) && dashCount !== 2))) {
  292. throw new DeveloperError(iso8601ErrorMessage);
  293. }
  294. //>>includeEnd('debug')
  295. var january4 = new Date(Date.UTC(year, 0, 4));
  296. dayOfYear = (weekNumber * 7) + dayOfWeek - january4.getUTCDay() - 3;
  297. } else {
  298. //None of our regular expressions succeeded in parsing the date properly.
  299. //>>includeStart('debug', pragmas.debug);
  300. throw new DeveloperError(iso8601ErrorMessage);
  301. //>>includeEnd('debug')
  302. }
  303. }
  304. //Split an ordinal date into month/day.
  305. tmp = new Date(Date.UTC(year, 0, 1));
  306. tmp.setUTCDate(dayOfYear);
  307. month = tmp.getUTCMonth() + 1;
  308. day = tmp.getUTCDate();
  309. }
  310. }
  311. }
  312. //Now that we have all of the date components, validate them to make sure nothing is out of range.
  313. inLeapYear = isLeapYear(year);
  314. //>>includeStart('debug', pragmas.debug);
  315. if (month < 1 || month > 12 || day < 1 || ((month !== 2 || !inLeapYear) && day > daysInMonth[month - 1]) || (inLeapYear && month === 2 && day > daysInLeapFeburary)) {
  316. throw new DeveloperError(iso8601ErrorMessage);
  317. }
  318. //>>includeEnd('debug')
  319. //Now move onto the time string, which is much simpler.
  320. //If no time is specified, it is considered the beginning of the day, UTC to match Javascript's implementation.
  321. var offsetIndex;
  322. if (defined(time)) {
  323. tokens = time.match(matchHoursMinutesSeconds);
  324. if (tokens !== null) {
  325. //>>includeStart('debug', pragmas.debug);
  326. dashCount = time.split(':').length - 1;
  327. if (dashCount > 0 && dashCount !== 2 && dashCount !== 3) {
  328. throw new DeveloperError(iso8601ErrorMessage);
  329. }
  330. //>>includeEnd('debug')
  331. hour = +tokens[1];
  332. minute = +tokens[2];
  333. second = +tokens[3];
  334. millisecond = +(tokens[4] || 0) * 1000.0;
  335. offsetIndex = 5;
  336. } else {
  337. tokens = time.match(matchHoursMinutes);
  338. if (tokens !== null) {
  339. //>>includeStart('debug', pragmas.debug);
  340. dashCount = time.split(':').length - 1;
  341. if (dashCount > 2) {
  342. throw new DeveloperError(iso8601ErrorMessage);
  343. }
  344. //>>includeEnd('debug')
  345. hour = +tokens[1];
  346. minute = +tokens[2];
  347. second = +(tokens[3] || 0) * 60.0;
  348. offsetIndex = 4;
  349. } else {
  350. tokens = time.match(matchHours);
  351. if (tokens !== null) {
  352. hour = +tokens[1];
  353. minute = +(tokens[2] || 0) * 60.0;
  354. offsetIndex = 3;
  355. } else {
  356. //>>includeStart('debug', pragmas.debug);
  357. throw new DeveloperError(iso8601ErrorMessage);
  358. //>>includeEnd('debug')
  359. }
  360. }
  361. }
  362. //Validate that all values are in proper range. Minutes and hours have special cases at 60 and 24.
  363. //>>includeStart('debug', pragmas.debug);
  364. if (minute >= 60 || second >= 61 || hour > 24 || (hour === 24 && (minute > 0 || second > 0 || millisecond > 0))) {
  365. throw new DeveloperError(iso8601ErrorMessage);
  366. }
  367. //>>includeEnd('debug');
  368. //Check the UTC offset value, if no value exists, use local time
  369. //a Z indicates UTC, + or - are offsets.
  370. var offset = tokens[offsetIndex];
  371. var offsetHours = +(tokens[offsetIndex + 1]);
  372. var offsetMinutes = +(tokens[offsetIndex + 2] || 0);
  373. switch (offset) {
  374. case '+':
  375. hour = hour - offsetHours;
  376. minute = minute - offsetMinutes;
  377. break;
  378. case '-':
  379. hour = hour + offsetHours;
  380. minute = minute + offsetMinutes;
  381. break;
  382. case 'Z':
  383. break;
  384. default:
  385. minute = minute + new Date(Date.UTC(year, month - 1, day, hour, minute)).getTimezoneOffset();
  386. break;
  387. }
  388. }
  389. //ISO8601 denotes a leap second by any time having a seconds component of 60 seconds.
  390. //If that's the case, we need to temporarily subtract a second in order to build a UTC date.
  391. //Then we add it back in after converting to TAI.
  392. var isLeapSecond = second === 60;
  393. if (isLeapSecond) {
  394. second--;
  395. }
  396. //Even if we successfully parsed the string into its components, after applying UTC offset or
  397. //special cases like 24:00:00 denoting midnight, we need to normalize the data appropriately.
  398. //milliseconds can never be greater than 1000, and seconds can't be above 60, so we start with minutes
  399. while (minute >= 60) {
  400. minute -= 60;
  401. hour++;
  402. }
  403. while (hour >= 24) {
  404. hour -= 24;
  405. day++;
  406. }
  407. tmp = (inLeapYear && month === 2) ? daysInLeapFeburary : daysInMonth[month - 1];
  408. while (day > tmp) {
  409. day -= tmp;
  410. month++;
  411. if (month > 12) {
  412. month -= 12;
  413. year++;
  414. }
  415. tmp = (inLeapYear && month === 2) ? daysInLeapFeburary : daysInMonth[month - 1];
  416. }
  417. //If UTC offset is at the beginning/end of the day, minutes can be negative.
  418. while (minute < 0) {
  419. minute += 60;
  420. hour--;
  421. }
  422. while (hour < 0) {
  423. hour += 24;
  424. day--;
  425. }
  426. while (day < 1) {
  427. month--;
  428. if (month < 1) {
  429. month += 12;
  430. year--;
  431. }
  432. tmp = (inLeapYear && month === 2) ? daysInLeapFeburary : daysInMonth[month - 1];
  433. day += tmp;
  434. }
  435. //Now create the JulianDate components from the Gregorian date and actually create our instance.
  436. var components = computeJulianDateComponents(year, month, day, hour, minute, second, millisecond);
  437. if (!defined(result)) {
  438. result = new JulianDate(components[0], components[1], TimeStandard.UTC);
  439. } else {
  440. setComponents(components[0], components[1], result);
  441. convertUtcToTai(result);
  442. }
  443. //If we were on a leap second, add it back.
  444. if (isLeapSecond) {
  445. JulianDate.addSeconds(result, 1, result);
  446. }
  447. return result;
  448. };
  449. /**
  450. * Creates a new instance that represents the current system time.
  451. * This is equivalent to calling <code>JulianDate.fromDate(new Date());</code>.
  452. *
  453. * @param {JulianDate} [result] An existing instance to use for the result.
  454. * @returns {JulianDate} The modified result parameter or a new instance if none was provided.
  455. */
  456. JulianDate.now = function(result) {
  457. return JulianDate.fromDate(new Date(), result);
  458. };
  459. var toGregorianDateScratch = new JulianDate(0, 0, TimeStandard.TAI);
  460. /**
  461. * Creates a {@link GregorianDate} from the provided instance.
  462. *
  463. * @param {JulianDate} julianDate The date to be converted.
  464. * @param {GregorianDate} [result] An existing instance to use for the result.
  465. * @returns {GregorianDate} The modified result parameter or a new instance if none was provided.
  466. */
  467. JulianDate.toGregorianDate = function(julianDate, result) {
  468. //>>includeStart('debug', pragmas.debug);
  469. if (!defined(julianDate)) {
  470. throw new DeveloperError('julianDate is required.');
  471. }
  472. //>>includeEnd('debug');
  473. var isLeapSecond = false;
  474. var thisUtc = convertTaiToUtc(julianDate, toGregorianDateScratch);
  475. if (!defined(thisUtc)) {
  476. //Conversion to UTC will fail if we are during a leap second.
  477. //If that's the case, subtract a second and convert again.
  478. //JavaScript doesn't support leap seconds, so this results in second 59 being repeated twice.
  479. JulianDate.addSeconds(julianDate, -1, toGregorianDateScratch);
  480. thisUtc = convertTaiToUtc(toGregorianDateScratch, toGregorianDateScratch);
  481. isLeapSecond = true;
  482. }
  483. var julianDayNumber = thisUtc.dayNumber;
  484. var secondsOfDay = thisUtc.secondsOfDay;
  485. if (secondsOfDay >= 43200.0) {
  486. julianDayNumber += 1;
  487. }
  488. // Algorithm from page 604 of the Explanatory Supplement to the
  489. // Astronomical Almanac (Seidelmann 1992).
  490. var L = (julianDayNumber + 68569) | 0;
  491. var N = (4 * L / 146097) | 0;
  492. L = (L - (((146097 * N + 3) / 4) | 0)) | 0;
  493. var I = ((4000 * (L + 1)) / 1461001) | 0;
  494. L = (L - (((1461 * I) / 4) | 0) + 31) | 0;
  495. var J = ((80 * L) / 2447) | 0;
  496. var day = (L - (((2447 * J) / 80) | 0)) | 0;
  497. L = (J / 11) | 0;
  498. var month = (J + 2 - 12 * L) | 0;
  499. var year = (100 * (N - 49) + I + L) | 0;
  500. var hour = (secondsOfDay / TimeConstants.SECONDS_PER_HOUR) | 0;
  501. var remainingSeconds = secondsOfDay - (hour * TimeConstants.SECONDS_PER_HOUR);
  502. var minute = (remainingSeconds / TimeConstants.SECONDS_PER_MINUTE) | 0;
  503. remainingSeconds = remainingSeconds - (minute * TimeConstants.SECONDS_PER_MINUTE);
  504. var second = remainingSeconds | 0;
  505. var millisecond = ((remainingSeconds - second) / TimeConstants.SECONDS_PER_MILLISECOND);
  506. // JulianDates are noon-based
  507. hour += 12;
  508. if (hour > 23) {
  509. hour -= 24;
  510. }
  511. //If we were on a leap second, add it back.
  512. if (isLeapSecond) {
  513. second += 1;
  514. }
  515. if (!defined(result)) {
  516. return new GregorianDate(year, month, day, hour, minute, second, millisecond, isLeapSecond);
  517. }
  518. result.year = year;
  519. result.month = month;
  520. result.day = day;
  521. result.hour = hour;
  522. result.minute = minute;
  523. result.second = second;
  524. result.millisecond = millisecond;
  525. result.isLeapSecond = isLeapSecond;
  526. return result;
  527. };
  528. /**
  529. * Creates a JavaScript Date from the provided instance.
  530. * Since JavaScript dates are only accurate to the nearest millisecond and
  531. * cannot represent a leap second, consider using {@link JulianDate.toGregorianDate} instead.
  532. * If the provided JulianDate is during a leap second, the previous second is used.
  533. *
  534. * @param {JulianDate} julianDate The date to be converted.
  535. * @returns {Date} A new instance representing the provided date.
  536. */
  537. JulianDate.toDate = function(julianDate) {
  538. //>>includeStart('debug', pragmas.debug);
  539. if (!defined(julianDate)) {
  540. throw new DeveloperError('julianDate is required.');
  541. }
  542. //>>includeEnd('debug');
  543. var gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch);
  544. var second = gDate.second;
  545. if (gDate.isLeapSecond) {
  546. second -= 1;
  547. }
  548. return new Date(Date.UTC(gDate.year, gDate.month - 1, gDate.day, gDate.hour, gDate.minute, second, gDate.millisecond));
  549. };
  550. /**
  551. * Creates an ISO8601 representation of the provided date.
  552. *
  553. * @param {JulianDate} julianDate The date to be converted.
  554. * @param {Number} [precision] The number of fractional digits used to represent the seconds component. By default, the most precise representation is used.
  555. * @returns {String} The ISO8601 representation of the provided date.
  556. */
  557. JulianDate.toIso8601 = function(julianDate, precision) {
  558. //>>includeStart('debug', pragmas.debug);
  559. if (!defined(julianDate)) {
  560. throw new DeveloperError('julianDate is required.');
  561. }
  562. //>>includeEnd('debug');
  563. var gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch);
  564. var year = gDate.year;
  565. var month = gDate.month;
  566. var day = gDate.day;
  567. var hour = gDate.hour;
  568. var minute = gDate.minute;
  569. var second = gDate.second;
  570. var millisecond = gDate.millisecond;
  571. // special case - Iso8601.MAXIMUM_VALUE produces a string which we can't parse unless we adjust.
  572. // 10000-01-01T00:00:00 is the same instant as 9999-12-31T24:00:00
  573. if (year === 10000 && month === 1 && day === 1 && hour === 0 && minute === 0 && second === 0 && millisecond === 0) {
  574. year = 9999;
  575. month = 12;
  576. day = 31;
  577. hour = 24;
  578. }
  579. var millisecondStr;
  580. if (!defined(precision) && millisecond !== 0) {
  581. //Forces milliseconds into a number with at least 3 digits to whatever the default toString() precision is.
  582. millisecondStr = (millisecond * 0.01).toString().replace('.', '');
  583. return sprintf('%04d-%02d-%02dT%02d:%02d:%02d.%sZ', year, month, day, hour, minute, second, millisecondStr);
  584. }
  585. //Precision is either 0 or milliseconds is 0 with undefined precision, in either case, leave off milliseconds entirely
  586. if (!defined(precision) || precision === 0) {
  587. return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', year, month, day, hour, minute, second);
  588. }
  589. //Forces milliseconds into a number with at least 3 digits to whatever the specified precision is.
  590. millisecondStr = (millisecond * 0.01).toFixed(precision).replace('.', '').slice(0, precision);
  591. return sprintf('%04d-%02d-%02dT%02d:%02d:%02d.%sZ', year, month, day, hour, minute, second, millisecondStr);
  592. };
  593. /**
  594. * Duplicates a JulianDate instance.
  595. *
  596. * @param {JulianDate} julianDate The date to duplicate.
  597. * @param {JulianDate} [result] An existing instance to use for the result.
  598. * @returns {JulianDate} The modified result parameter or a new instance if none was provided. Returns undefined if julianDate is undefined.
  599. */
  600. JulianDate.clone = function(julianDate, result) {
  601. if (!defined(julianDate)) {
  602. return undefined;
  603. }
  604. if (!defined(result)) {
  605. return new JulianDate(julianDate.dayNumber, julianDate.secondsOfDay, TimeStandard.TAI);
  606. }
  607. result.dayNumber = julianDate.dayNumber;
  608. result.secondsOfDay = julianDate.secondsOfDay;
  609. return result;
  610. };
  611. /**
  612. * Compares two instances.
  613. *
  614. * @param {JulianDate} left The first instance.
  615. * @param {JulianDate} right The second instance.
  616. * @returns {Number} A negative value if left is less than right, a positive value if left is greater than right, or zero if left and right are equal.
  617. */
  618. JulianDate.compare = function(left, right) {
  619. //>>includeStart('debug', pragmas.debug);
  620. if (!defined(left)) {
  621. throw new DeveloperError('left is required.');
  622. }
  623. if (!defined(right)) {
  624. throw new DeveloperError('right is required.');
  625. }
  626. //>>includeEnd('debug');
  627. var julianDayNumberDifference = left.dayNumber - right.dayNumber;
  628. if (julianDayNumberDifference !== 0) {
  629. return julianDayNumberDifference;
  630. }
  631. return left.secondsOfDay - right.secondsOfDay;
  632. };
  633. /**
  634. * Compares two instances and returns <code>true</code> if they are equal, <code>false</code> otherwise.
  635. *
  636. * @param {JulianDate} [left] The first instance.
  637. * @param {JulianDate} [right] The second instance.
  638. * @returns {Boolean} <code>true</code> if the dates are equal; otherwise, <code>false</code>.
  639. */
  640. JulianDate.equals = function(left, right) {
  641. return (left === right) ||
  642. (defined(left) &&
  643. defined(right) &&
  644. left.dayNumber === right.dayNumber &&
  645. left.secondsOfDay === right.secondsOfDay);
  646. };
  647. /**
  648. * Compares two instances and returns <code>true</code> if they are within <code>epsilon</code> seconds of
  649. * each other. That is, in order for the dates to be considered equal (and for
  650. * this function to return <code>true</code>), the absolute value of the difference between them, in
  651. * seconds, must be less than <code>epsilon</code>.
  652. *
  653. * @param {JulianDate} [left] The first instance.
  654. * @param {JulianDate} [right] The second instance.
  655. * @param {Number} epsilon The maximum number of seconds that should separate the two instances.
  656. * @returns {Boolean} <code>true</code> if the two dates are within <code>epsilon</code> seconds of each other; otherwise <code>false</code>.
  657. */
  658. JulianDate.equalsEpsilon = function(left, right, epsilon) {
  659. //>>includeStart('debug', pragmas.debug);
  660. if (!defined(epsilon)) {
  661. throw new DeveloperError('epsilon is required.');
  662. }
  663. //>>includeEnd('debug');
  664. return (left === right) ||
  665. (defined(left) &&
  666. defined(right) &&
  667. Math.abs(JulianDate.secondsDifference(left, right)) <= epsilon);
  668. };
  669. /**
  670. * Computes the total number of whole and fractional days represented by the provided instance.
  671. *
  672. * @param {JulianDate} julianDate The date.
  673. * @returns {Number} The Julian date as single floating point number.
  674. */
  675. JulianDate.totalDays = function(julianDate) {
  676. //>>includeStart('debug', pragmas.debug);
  677. if (!defined(julianDate)) {
  678. throw new DeveloperError('julianDate is required.');
  679. }
  680. //>>includeEnd('debug');
  681. return julianDate.dayNumber + (julianDate.secondsOfDay / TimeConstants.SECONDS_PER_DAY);
  682. };
  683. /**
  684. * Computes the difference in seconds between the provided instance.
  685. *
  686. * @param {JulianDate} left The first instance.
  687. * @param {JulianDate} right The second instance.
  688. * @returns {Number} The difference, in seconds, when subtracting <code>right</code> from <code>left</code>.
  689. */
  690. JulianDate.secondsDifference = function(left, right) {
  691. //>>includeStart('debug', pragmas.debug);
  692. if (!defined(left)) {
  693. throw new DeveloperError('left is required.');
  694. }
  695. if (!defined(right)) {
  696. throw new DeveloperError('right is required.');
  697. }
  698. //>>includeEnd('debug');
  699. var dayDifference = (left.dayNumber - right.dayNumber) * TimeConstants.SECONDS_PER_DAY;
  700. return (dayDifference + (left.secondsOfDay - right.secondsOfDay));
  701. };
  702. /**
  703. * Computes the difference in days between the provided instance.
  704. *
  705. * @param {JulianDate} left The first instance.
  706. * @param {JulianDate} right The second instance.
  707. * @returns {Number} The difference, in days, when subtracting <code>right</code> from <code>left</code>.
  708. */
  709. JulianDate.daysDifference = function(left, right) {
  710. //>>includeStart('debug', pragmas.debug);
  711. if (!defined(left)) {
  712. throw new DeveloperError('left is required.');
  713. }
  714. if (!defined(right)) {
  715. throw new DeveloperError('right is required.');
  716. }
  717. //>>includeEnd('debug');
  718. var dayDifference = (left.dayNumber - right.dayNumber);
  719. var secondDifference = (left.secondsOfDay - right.secondsOfDay) / TimeConstants.SECONDS_PER_DAY;
  720. return dayDifference + secondDifference;
  721. };
  722. /**
  723. * Computes the number of seconds the provided instance is ahead of UTC.
  724. *
  725. * @param {JulianDate} julianDate The date.
  726. * @returns {Number} The number of seconds the provided instance is ahead of UTC
  727. */
  728. JulianDate.computeTaiMinusUtc = function(julianDate) {
  729. binarySearchScratchLeapSecond.julianDate = julianDate;
  730. var leapSeconds = JulianDate.leapSeconds;
  731. var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, compareLeapSecondDates);
  732. if (index < 0) {
  733. index = ~index;
  734. --index;
  735. if (index < 0) {
  736. index = 0;
  737. }
  738. }
  739. return leapSeconds[index].offset;
  740. };
  741. /**
  742. * Adds the provided number of seconds to the provided date instance.
  743. *
  744. * @param {JulianDate} julianDate The date.
  745. * @param {Number} seconds The number of seconds to add or subtract.
  746. * @param {JulianDate} result An existing instance to use for the result.
  747. * @returns {JulianDate} The modified result parameter.
  748. */
  749. JulianDate.addSeconds = function(julianDate, seconds, result) {
  750. //>>includeStart('debug', pragmas.debug);
  751. if (!defined(julianDate)) {
  752. throw new DeveloperError('julianDate is required.');
  753. }
  754. if (!defined(seconds)) {
  755. throw new DeveloperError('seconds is required.');
  756. }
  757. if (!defined(result)) {
  758. throw new DeveloperError('result is required.');
  759. }
  760. //>>includeEnd('debug');
  761. return setComponents(julianDate.dayNumber, julianDate.secondsOfDay + seconds, result);
  762. };
  763. /**
  764. * Adds the provided number of minutes to the provided date instance.
  765. *
  766. * @param {JulianDate} julianDate The date.
  767. * @param {Number} minutes The number of minutes to add or subtract.
  768. * @param {JulianDate} result An existing instance to use for the result.
  769. * @returns {JulianDate} The modified result parameter.
  770. */
  771. JulianDate.addMinutes = function(julianDate, minutes, result) {
  772. //>>includeStart('debug', pragmas.debug);
  773. if (!defined(julianDate)) {
  774. throw new DeveloperError('julianDate is required.');
  775. }
  776. if (!defined(minutes)) {
  777. throw new DeveloperError('minutes is required.');
  778. }
  779. if (!defined(result)) {
  780. throw new DeveloperError('result is required.');
  781. }
  782. //>>includeEnd('debug');
  783. var newSecondsOfDay = julianDate.secondsOfDay + (minutes * TimeConstants.SECONDS_PER_MINUTE);
  784. return setComponents(julianDate.dayNumber, newSecondsOfDay, result);
  785. };
  786. /**
  787. * Adds the provided number of hours to the provided date instance.
  788. *
  789. * @param {JulianDate} julianDate The date.
  790. * @param {Number} hours The number of hours to add or subtract.
  791. * @param {JulianDate} result An existing instance to use for the result.
  792. * @returns {JulianDate} The modified result parameter.
  793. */
  794. JulianDate.addHours = function(julianDate, hours, result) {
  795. //>>includeStart('debug', pragmas.debug);
  796. if (!defined(julianDate)) {
  797. throw new DeveloperError('julianDate is required.');
  798. }
  799. if (!defined(hours)) {
  800. throw new DeveloperError('hours is required.');
  801. }
  802. if (!defined(result)) {
  803. throw new DeveloperError('result is required.');
  804. }
  805. //>>includeEnd('debug');
  806. var newSecondsOfDay = julianDate.secondsOfDay + (hours * TimeConstants.SECONDS_PER_HOUR);
  807. return setComponents(julianDate.dayNumber, newSecondsOfDay, result);
  808. };
  809. /**
  810. * Adds the provided number of days to the provided date instance.
  811. *
  812. * @param {JulianDate} julianDate The date.
  813. * @param {Number} days The number of days to add or subtract.
  814. * @param {JulianDate} result An existing instance to use for the result.
  815. * @returns {JulianDate} The modified result parameter.
  816. */
  817. JulianDate.addDays = function(julianDate, days, result) {
  818. //>>includeStart('debug', pragmas.debug);
  819. if (!defined(julianDate)) {
  820. throw new DeveloperError('julianDate is required.');
  821. }
  822. if (!defined(days)) {
  823. throw new DeveloperError('days is required.');
  824. }
  825. if (!defined(result)) {
  826. throw new DeveloperError('result is required.');
  827. }
  828. //>>includeEnd('debug');
  829. var newJulianDayNumber = julianDate.dayNumber + days;
  830. return setComponents(newJulianDayNumber, julianDate.secondsOfDay, result);
  831. };
  832. /**
  833. * Compares the provided instances and returns <code>true</code> if <code>left</code> is earlier than <code>right</code>, <code>false</code> otherwise.
  834. *
  835. * @param {JulianDate} left The first instance.
  836. * @param {JulianDate} right The second instance.
  837. * @returns {Boolean} <code>true</code> if <code>left</code> is earlier than <code>right</code>, <code>false</code> otherwise.
  838. */
  839. JulianDate.lessThan = function(left, right) {
  840. return JulianDate.compare(left, right) < 0;
  841. };
  842. /**
  843. * Compares the provided instances and returns <code>true</code> if <code>left</code> is earlier than or equal to <code>right</code>, <code>false</code> otherwise.
  844. *
  845. * @param {JulianDate} left The first instance.
  846. * @param {JulianDate} right The second instance.
  847. * @returns {Boolean} <code>true</code> if <code>left</code> is earlier than or equal to <code>right</code>, <code>false</code> otherwise.
  848. */
  849. JulianDate.lessThanOrEquals = function(left, right) {
  850. return JulianDate.compare(left, right) <= 0;
  851. };
  852. /**
  853. * Compares the provided instances and returns <code>true</code> if <code>left</code> is later than <code>right</code>, <code>false</code> otherwise.
  854. *
  855. * @param {JulianDate} left The first instance.
  856. * @param {JulianDate} right The second instance.
  857. * @returns {Boolean} <code>true</code> if <code>left</code> is later than <code>right</code>, <code>false</code> otherwise.
  858. */
  859. JulianDate.greaterThan = function(left, right) {
  860. return JulianDate.compare(left, right) > 0;
  861. };
  862. /**
  863. * Compares the provided instances and returns <code>true</code> if <code>left</code> is later than or equal to <code>right</code>, <code>false</code> otherwise.
  864. *
  865. * @param {JulianDate} left The first instance.
  866. * @param {JulianDate} right The second instance.
  867. * @returns {Boolean} <code>true</code> if <code>left</code> is later than or equal to <code>right</code>, <code>false</code> otherwise.
  868. */
  869. JulianDate.greaterThanOrEquals = function(left, right) {
  870. return JulianDate.compare(left, right) >= 0;
  871. };
  872. /**
  873. * Duplicates this instance.
  874. *
  875. * @param {JulianDate} [result] An existing instance to use for the result.
  876. * @returns {JulianDate} The modified result parameter or a new instance if none was provided.
  877. */
  878. JulianDate.prototype.clone = function(result) {
  879. return JulianDate.clone(this, result);
  880. };
  881. /**
  882. * Compares this and the provided instance and returns <code>true</code> if they are equal, <code>false</code> otherwise.
  883. *
  884. * @param {JulianDate} [right] The second instance.
  885. * @returns {Boolean} <code>true</code> if the dates are equal; otherwise, <code>false</code>.
  886. */
  887. JulianDate.prototype.equals = function(right) {
  888. return JulianDate.equals(this, right);
  889. };
  890. /**
  891. * Compares this and the provided instance and returns <code>true</code> if they are within <code>epsilon</code> seconds of
  892. * each other. That is, in order for the dates to be considered equal (and for
  893. * this function to return <code>true</code>), the absolute value of the difference between them, in
  894. * seconds, must be less than <code>epsilon</code>.
  895. *
  896. * @param {JulianDate} [right] The second instance.
  897. * @param {Number} epsilon The maximum number of seconds that should separate the two instances.
  898. * @returns {Boolean} <code>true</code> if the two dates are within <code>epsilon</code> seconds of each other; otherwise <code>false</code>.
  899. */
  900. JulianDate.prototype.equalsEpsilon = function(right, epsilon) {
  901. return JulianDate.equalsEpsilon(this, right, epsilon);
  902. };
  903. /**
  904. * Creates a string representing this date in ISO8601 format.
  905. *
  906. * @returns {String} A string representing this date in ISO8601 format.
  907. */
  908. JulianDate.prototype.toString = function() {
  909. return JulianDate.toIso8601(this);
  910. };
  911. /**
  912. * Gets or sets the list of leap seconds used throughout Cesium.
  913. * @memberof JulianDate
  914. * @type {LeapSecond[]}
  915. */
  916. JulianDate.leapSeconds = [
  917. new LeapSecond(new JulianDate(2441317, 43210.0, TimeStandard.TAI), 10), // January 1, 1972 00:00:00 UTC
  918. new LeapSecond(new JulianDate(2441499, 43211.0, TimeStandard.TAI), 11), // July 1, 1972 00:00:00 UTC
  919. new LeapSecond(new JulianDate(2441683, 43212.0, TimeStandard.TAI), 12), // January 1, 1973 00:00:00 UTC
  920. new LeapSecond(new JulianDate(2442048, 43213.0, TimeStandard.TAI), 13), // January 1, 1974 00:00:00 UTC
  921. new LeapSecond(new JulianDate(2442413, 43214.0, TimeStandard.TAI), 14), // January 1, 1975 00:00:00 UTC
  922. new LeapSecond(new JulianDate(2442778, 43215.0, TimeStandard.TAI), 15), // January 1, 1976 00:00:00 UTC
  923. new LeapSecond(new JulianDate(2443144, 43216.0, TimeStandard.TAI), 16), // January 1, 1977 00:00:00 UTC
  924. new LeapSecond(new JulianDate(2443509, 43217.0, TimeStandard.TAI), 17), // January 1, 1978 00:00:00 UTC
  925. new LeapSecond(new JulianDate(2443874, 43218.0, TimeStandard.TAI), 18), // January 1, 1979 00:00:00 UTC
  926. new LeapSecond(new JulianDate(2444239, 43219.0, TimeStandard.TAI), 19), // January 1, 1980 00:00:00 UTC
  927. new LeapSecond(new JulianDate(2444786, 43220.0, TimeStandard.TAI), 20), // July 1, 1981 00:00:00 UTC
  928. new LeapSecond(new JulianDate(2445151, 43221.0, TimeStandard.TAI), 21), // July 1, 1982 00:00:00 UTC
  929. new LeapSecond(new JulianDate(2445516, 43222.0, TimeStandard.TAI), 22), // July 1, 1983 00:00:00 UTC
  930. new LeapSecond(new JulianDate(2446247, 43223.0, TimeStandard.TAI), 23), // July 1, 1985 00:00:00 UTC
  931. new LeapSecond(new JulianDate(2447161, 43224.0, TimeStandard.TAI), 24), // January 1, 1988 00:00:00 UTC
  932. new LeapSecond(new JulianDate(2447892, 43225.0, TimeStandard.TAI), 25), // January 1, 1990 00:00:00 UTC
  933. new LeapSecond(new JulianDate(2448257, 43226.0, TimeStandard.TAI), 26), // January 1, 1991 00:00:00 UTC
  934. new LeapSecond(new JulianDate(2448804, 43227.0, TimeStandard.TAI), 27), // July 1, 1992 00:00:00 UTC
  935. new LeapSecond(new JulianDate(2449169, 43228.0, TimeStandard.TAI), 28), // July 1, 1993 00:00:00 UTC
  936. new LeapSecond(new JulianDate(2449534, 43229.0, TimeStandard.TAI), 29), // July 1, 1994 00:00:00 UTC
  937. new LeapSecond(new JulianDate(2450083, 43230.0, TimeStandard.TAI), 30), // January 1, 1996 00:00:00 UTC
  938. new LeapSecond(new JulianDate(2450630, 43231.0, TimeStandard.TAI), 31), // July 1, 1997 00:00:00 UTC
  939. new LeapSecond(new JulianDate(2451179, 43232.0, TimeStandard.TAI), 32), // January 1, 1999 00:00:00 UTC
  940. new LeapSecond(new JulianDate(2453736, 43233.0, TimeStandard.TAI), 33), // January 1, 2006 00:00:00 UTC
  941. new LeapSecond(new JulianDate(2454832, 43234.0, TimeStandard.TAI), 34), // January 1, 2009 00:00:00 UTC
  942. new LeapSecond(new JulianDate(2456109, 43235.0, TimeStandard.TAI), 35), // July 1, 2012 00:00:00 UTC
  943. new LeapSecond(new JulianDate(2457204, 43236.0, TimeStandard.TAI), 36), // July 1, 2015 00:00:00 UTC
  944. new LeapSecond(new JulianDate(2457754, 43237.0, TimeStandard.TAI), 37) // January 1, 2017 00:00:00 UTC
  945. ];
  946. export default JulianDate;