From cb6005ca86a3b273dac3047122bfe319b7cc9b18 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Mon, 9 Jun 2014 17:57:04 -0400 Subject: [PATCH 01/11] Start refactoring JulianDate Turn all prototype functions (except for clone/equals/eqaulsEpsilon/compareTo) into static functions. --- Apps/TimelineDemo/TimelineDemo.js | 16 +- Source/Core/Clock.js | 26 +- Source/Core/EarthOrientationParameters.js | 6 +- Source/Core/GregorianDate.js | 56 ++++ Source/Core/Iau2000Orientation.js | 4 +- Source/Core/Iau2006XysData.js | 6 +- Source/Core/JulianDate.js | 307 ++++-------------- Source/Core/Simon1994PlanetaryPositions.js | 10 +- Source/Core/TimeInterval.js | 8 +- Source/Core/TimeIntervalCollection.js | 22 +- Source/Core/Transforms.js | 24 +- Source/DynamicScene/CzmlDataSource.js | 2 +- .../DynamicScene/DynamicObjectCollection.js | 6 +- Source/DynamicScene/DynamicObjectView.js | 4 +- Source/DynamicScene/DynamicPathVisualizer.js | 36 +- Source/DynamicScene/SampledProperty.js | 6 +- Source/Scene/ModelAnimationCollection.js | 8 +- .../Widgets/Animation/AnimationViewModel.js | 12 +- Source/Widgets/Timeline/Timeline.js | 64 ++-- .../Timeline/TimelineHighlightRange.js | 10 +- Source/Widgets/Timeline/TimelineTrack.js | 18 +- Specs/Core/ClockSpec.js | 32 +- Specs/Core/EarthOrientationParametersSpec.js | 10 +- Specs/Core/JulianDateSpec.js | 289 ++++++----------- Specs/Core/TimeIntervalSpec.js | 4 +- Specs/Core/TransformsSpec.js | 24 +- Specs/DynamicScene/CzmlDataSourceSpec.js | 54 +-- Specs/DynamicScene/DynamicObjectSpec.js | 4 +- .../DynamicScene/DynamicPathVisualizerSpec.js | 28 +- .../SampledPositionPropertySpec.js | 2 +- Specs/DynamicScene/SampledPropertySpec.js | 14 +- Specs/Scene/ModelSpec.js | 26 +- .../Animation/AnimationViewModelSpec.js | 20 +- 33 files changed, 490 insertions(+), 668 deletions(-) create mode 100644 Source/Core/GregorianDate.js diff --git a/Apps/TimelineDemo/TimelineDemo.js b/Apps/TimelineDemo/TimelineDemo.js index 853de0102c6c..2a99c32c954a 100644 --- a/Apps/TimelineDemo/TimelineDemo.js +++ b/Apps/TimelineDemo/TimelineDemo.js @@ -93,10 +93,10 @@ define([ timeline.addEventListener('settime', handleSetTime, false); timeline.addEventListener('setzoom', handleSetZoom, false); - timeline.addTrack(new TimeInterval(startJulian, startJulian.addSeconds(60 * 60)), 8, Color.RED, new Color(0.55, 0.55, 0.55, 0.25)); - timeline.addTrack(new TimeInterval(endJulian.addSeconds(-60 * 60), endJulian), 8, Color.LIME); - var middle = startJulian.getSecondsDifference(endJulian) / 4; - timeline.addTrack(new TimeInterval(startJulian.addSeconds(middle), startJulian.addSeconds(middle * 3)), 8, Color.DEEPSKYBLUE, new Color(0.55, 0.55, 0.55, 0.25)); + timeline.addTrack(new TimeInterval(startJulian, JulianDate.addSeconds(startJulian, 60 * 60)), 8, Color.RED, new Color(0.55, 0.55, 0.55, 0.25)); + timeline.addTrack(new TimeInterval(JulianDate.addSeconds(endJulian, -60 * 60), endJulian), 8, Color.LIME); + var middle = JulianDate.getSecondsDifference(startJulian, endJulian) / 4; + timeline.addTrack(new TimeInterval(JulianDate.addSeconds(startJulian, middle), JulianDate.addSeconds(startJulian, middle * 3)), 8, Color.DEEPSKYBLUE, new Color(0.55, 0.55, 0.55, 0.25)); var clockViewModel = new ClockViewModel(clock); animationViewModel = new AnimationViewModel(clockViewModel); @@ -123,7 +123,7 @@ define([ } if (startJulian && endJulian) { - if (startJulian.getSecondsDifference(endJulian) < 0.1) { + if (JulianDate.getSecondsDifference(startJulian, endJulian) < 0.1) { endBeforeStart.style.display = 'block'; containerElement.style.visibility = 'hidden'; } else { @@ -215,8 +215,8 @@ define([ dijit.byId('endTimeSel').set('value', 'T24:00:00'); var today = new JulianDate(); - var tomorrow = today.addDays(1); - dijit.byId('startCal').set('value', today.toDate()); - dijit.byId('endCal').set('value', tomorrow.toDate()); + var tomorrow = JulianDate.addDays(today, 1); + dijit.byId('startCal').set('value', JulianDate.toDate(today)); + dijit.byId('endCal').set('value', JulianDate.toDate(tomorrow)); }); }); diff --git a/Source/Core/Clock.js b/Source/Core/Clock.js index 9cd661b225ff..dd0fa63199c9 100644 --- a/Source/Core/Clock.js +++ b/Source/Core/Clock.js @@ -66,26 +66,26 @@ define([ if (startTimeUndefined && stopTimeUndefined && currentTimeUndefined) { currentTime = new JulianDate(); startTime = JulianDate.clone(currentTime); - stopTime = currentTime.addDays(1.0); + stopTime = JulianDate.addDays(currentTime, 1.0); } else if (startTimeUndefined && stopTimeUndefined) { startTime = JulianDate.clone(currentTime); - stopTime = currentTime.addDays(1.0); + stopTime = JulianDate.addDays(currentTime, 1.0); } else if (startTimeUndefined && currentTimeUndefined) { - startTime = stopTime.addDays(-1.0); + startTime = JulianDate.addDays(stopTime, -1.0); currentTime = JulianDate.clone(startTime); } else if (currentTimeUndefined && stopTimeUndefined) { currentTime = JulianDate.clone(startTime); - stopTime = startTime.addDays(1.0); + stopTime = JulianDate.addDays(startTime, 1.0); } else if (currentTimeUndefined) { currentTime = JulianDate.clone(startTime); } else if (stopTimeUndefined) { - stopTime = currentTime.addDays(1.0); + stopTime = JulianDate.addDays(currentTime, 1.0); } else if (startTimeUndefined) { startTime = JulianDate.clone(currentTime); } //>>includeStart('debug', pragmas.debug); - if (startTime.greaterThan(stopTime)) { + if (JulianDate.greaterThan(startTime, stopTime)) { throw new DeveloperError('startTime must come before stopTime.'); } //>>includeEnd('debug'); @@ -175,24 +175,24 @@ define([ currentTime = new JulianDate(); } else { if (this.clockStep === ClockStep.TICK_DEPENDENT) { - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); } else { var milliseconds = currentSystemTime - this._lastSystemTime; - currentTime = currentTime.addSeconds(multiplier * (milliseconds / 1000.0)); + currentTime = JulianDate.addSeconds(currentTime, multiplier * (milliseconds / 1000.0)); } if (this.clockRange === ClockRange.CLAMPED) { - if (currentTime.lessThan(startTime)) { + if (JulianDate.lessThan(currentTime, startTime)) { currentTime = startTime; - } else if (currentTime.greaterThan(stopTime)) { + } else if (JulianDate.greaterThan(currentTime, stopTime)) { currentTime = stopTime; } } else if (this.clockRange === ClockRange.LOOP_STOP) { - if (currentTime.lessThan(startTime)) { + if (JulianDate.lessThan(currentTime, startTime)) { currentTime = JulianDate.clone(startTime); } - while (currentTime.greaterThan(stopTime)) { - currentTime = startTime.addSeconds(stopTime.getSecondsDifference(currentTime)); + while (JulianDate.greaterThan(currentTime, stopTime)) { + currentTime = JulianDate.addSeconds(startTime, JulianDate.getSecondsDifference(stopTime, currentTime)); } } } diff --git a/Source/Core/EarthOrientationParameters.js b/Source/Core/EarthOrientationParameters.js index a6c5745fce9a..bc7df3a8ef2f 100644 --- a/Source/Core/EarthOrientationParameters.js +++ b/Source/Core/EarthOrientationParameters.js @@ -187,9 +187,9 @@ define([ if (defined(lastIndex)) { var previousIndexDate = dates[lastIndex]; var nextIndexDate = dates[lastIndex + 1]; - var isAfterPrevious = previousIndexDate.lessThanOrEquals(date); + var isAfterPrevious = JulianDate.lessThanOrEquals(previousIndexDate, date); var isAfterLastSample = !defined(nextIndexDate); - var isBeforeNext = isAfterLastSample || nextIndexDate.greaterThanOrEquals(date); + var isBeforeNext = isAfterLastSample || JulianDate.greaterThanOrEquals(nextIndexDate, date); if (isAfterPrevious && isBeforeNext) { before = lastIndex; @@ -338,7 +338,7 @@ define([ return result; } - var factor = beforeDate.getSecondsDifference(date) / beforeDate.getSecondsDifference(afterDate); + var factor = JulianDate.getSecondsDifference(beforeDate, date) / JulianDate.getSecondsDifference(beforeDate, afterDate); var startBefore = before * columnCount; var startAfter = after * columnCount; diff --git a/Source/Core/GregorianDate.js b/Source/Core/GregorianDate.js new file mode 100644 index 000000000000..3475dc0bc302 --- /dev/null +++ b/Source/Core/GregorianDate.js @@ -0,0 +1,56 @@ +/*global define*/ +define(function() { + "use strict"; + + /** + * The object returned by {@link JulianDate#toGregorianDate}. + * + * @alias GregorianDate + * @see JulianDate#toGregorianDate + * @constructor + */ + var GregorianDate = function(year, month, day, hour, minute, second, millisecond, isLeapSecond) { + /** + * The year, a whole number. + * @type {Number} + */ + this.year = year; + /** + * The month, a whole number with range [1, 12]. + * @type {Number} + */ + this.month = month; + /** + * The day, a whole number with range 1. + * @type {Number} + */ + this.day = day; + /** + * The hour, a whole number with range [0, 23]. + * @type {Number} + */ + this.hour = hour; + /** + * The minute, a whole number with range [0, 59]. + * @type {Number} + */ + this.minute = minute; + /** + * The second, a whole number with range [0, 60], with 60 representing a leap second. + * @type {Number} + */ + this.second = second; + /** + * The millisecond, a floating point number with range [0.0, 1000.0). + * @type {Number} + */ + this.millisecond = millisecond; + /** + * True if this date is during a leap second. + * @type {Boolean} + */ + this.isLeapSecond = isLeapSecond; + }; + + return GregorianDate; +}); \ No newline at end of file diff --git a/Source/Core/Iau2000Orientation.js b/Source/Core/Iau2000Orientation.js index 3b3ddb6290da..109bed56540b 100644 --- a/Source/Core/Iau2000Orientation.js +++ b/Source/Core/Iau2000Orientation.js @@ -52,8 +52,8 @@ define([ date = new JulianDate(); } - var dateTT = date.addSeconds(TdtMinusTai); - var d = dateTT.getTotalDays() - J2000d; + var dateTT = JulianDate.addSeconds(date, TdtMinusTai); + var d = JulianDate.getTotalDays(dateTT) - J2000d; var T = d / TimeConstants.DAYS_PER_JULIAN_CENTURY; var E1 = (125.045 + c1 * d) * CesiumMath.RADIANS_PER_DEGREE; diff --git a/Source/Core/Iau2006XysData.js b/Source/Core/Iau2006XysData.js index ad988a16e4b5..72f97e3a83af 100644 --- a/Source/Core/Iau2006XysData.js +++ b/Source/Core/Iau2006XysData.js @@ -79,9 +79,9 @@ define([ function getDaysSinceEpoch(xys, dayTT, secondTT) { var dateTT = julianDateScratch; - dateTT._julianDayNumber = dayTT; - dateTT._secondsOfDay = secondTT; - return xys._sampleZeroDateTT.getDaysDifference(dateTT); + dateTT.dayNumber = dayTT; + dateTT.secondsOfDay = secondTT; + return JulianDate.getDaysDifference(xys._sampleZeroDateTT, dateTT); } /** diff --git a/Source/Core/JulianDate.js b/Source/Core/JulianDate.js index c3ac6e669efe..6c8c604f6741 100644 --- a/Source/Core/JulianDate.js +++ b/Source/Core/JulianDate.js @@ -5,6 +5,7 @@ define([ './defaultValue', './defined', './DeveloperError', + './GregorianDate', './isLeapYear', './LeapSecond', './TimeConstants', @@ -15,62 +16,13 @@ define([ defaultValue, defined, DeveloperError, + GregorianDate, isLeapYear, LeapSecond, TimeConstants, TimeStandard) { "use strict"; - /** - * The object returned by {@link JulianDate#toGregorianDate}. - * - * @alias GregorianDate - * @see JulianDate#toGregorianDate - * @constructor - */ - var GregorianDate = function(year, month, day, hour, minute, second, millisecond, isLeapSecond) { - /** - * The year, a whole number. - * @type {Number} - */ - this.year = year; - /** - * The month, a whole number with range [1, 12]. - * @type {Number} - */ - this.month = month; - /** - * The day, a whole number with range 1. - * @type {Number} - */ - this.day = day; - /** - * The hour, a whole number with range [0, 23]. - * @type {Number} - */ - this.hour = hour; - /** - * The minute, a whole number with range [0, 59]. - * @type {Number} - */ - this.minute = minute; - /** - * The second, a whole number with range [0, 60], with 60 representing a leap second. - * @type {Number} - */ - this.second = second; - /** - * The millisecond, a floating point number with range [0.0, 1000.0). - * @type {Number} - */ - this.millisecond = millisecond; - /** - * True if this date is during a leap second. - * @type {Boolean} - */ - this.isLeapSecond = isLeapSecond; - }; - var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; var daysInLeapFeburary = 29; @@ -78,6 +30,7 @@ define([ var binarySearchScratchLeapSecond = { julianDate : undefined }; + function convertUtcToTai(julianDate) { //Even though julianDate is in UTC, we'll treat it as TAI and //search the leap second table for it. @@ -99,14 +52,14 @@ define([ //However, if the difference between the UTC date being converted and the TAI //defined leap second is greater than the offset, we are off by one and need to use //the previous leap second. - var difference = julianDate.getSecondsDifference(leapSeconds[index].julianDate); + var difference = JulianDate.getSecondsDifference(julianDate, leapSeconds[index].julianDate); if (difference > offset) { index--; offset = leapSeconds[index].offset; } } - julianDate.addSeconds(offset, julianDate); + JulianDate.addSeconds(julianDate, offset, julianDate); } function convertTaiToUtc(julianDate, result) { @@ -119,20 +72,20 @@ define([ //All times before our first leap second get the first offset. if (index === 0) { - return julianDate.addSeconds(-leapSeconds[0].offset, result); + return JulianDate.addSeconds(julianDate, -leapSeconds[0].offset, result); } //All times after our leap second get the last offset. if (index >= leapSeconds.length) { - return julianDate.addSeconds(-leapSeconds[index - 1].offset, result); + return JulianDate.addSeconds(julianDate, -leapSeconds[index - 1].offset, result); } //Compute the difference between the found leap second and the time we are converting. - var difference = julianDate.getSecondsDifference(leapSeconds[index].julianDate); + var difference = JulianDate.getSecondsDifference(julianDate, leapSeconds[index].julianDate); if (difference === 0) { //The date is in our leap second table. - return julianDate.addSeconds(-leapSeconds[index].offset, result); + return JulianDate.addSeconds(julianDate, -leapSeconds[index].offset, result); } if (difference <= 1.0) { @@ -142,7 +95,7 @@ define([ //The time is in between two leap seconds, index is the leap second after the date //we're converting, so we subtract one to get the correct LeapSecond instance. - return julianDate.addSeconds(-leapSeconds[--index].offset, result); + return JulianDate.addSeconds(julianDate, -leapSeconds[--index].offset, result); } function setComponents(wholeDays, secondsOfDay, julianDate) { @@ -159,8 +112,8 @@ define([ return new JulianDate(wholeDays, secondsOfDay, TimeStandard.TAI); } - julianDate._julianDayNumber = wholeDays; - julianDate._secondsOfDay = secondsOfDay; + julianDate.dayNumber = wholeDays; + julianDate.secondsOfDay = secondsOfDay; return julianDate; } @@ -251,8 +204,8 @@ define([ * var julianDate = new Cesium.JulianDate(julianDayNumber, secondsOfDay, Cesium.TimeStandard.UTC); */ var JulianDate = function(julianDayNumber, julianSecondsOfDay, timeStandard) { - this._julianDayNumber = undefined; - this._secondsOfDay = undefined; + this.dayNumber = undefined; + this.secondsOfDay = undefined; var wholeDays; var secondsOfDay; @@ -304,10 +257,10 @@ define([ return undefined; } if (!defined(result)) { - return new JulianDate(date._julianDayNumber, date._secondsOfDay, TimeStandard.TAI); + return new JulianDate(date.dayNumber, date.secondsOfDay, TimeStandard.TAI); } - result._julianDayNumber = date._julianDayNumber; - result._secondsOfDay = date._secondsOfDay; + result.dayNumber = date.dayNumber; + result.secondsOfDay = date.secondsOfDay; return result; }; @@ -607,7 +560,7 @@ define([ //If we were on a leap second, add it back. if (isLeapSecond) { - result.addSeconds(1, result); + JulianDate.addSeconds(result, 1, result); } return result; @@ -650,11 +603,11 @@ define([ * or zero if a and b are equal. */ JulianDate.compare = function(a, b) { - var julianDayNumberDifference = a._julianDayNumber - b._julianDayNumber; + var julianDayNumberDifference = a.dayNumber - b.dayNumber; if (julianDayNumberDifference !== 0) { return julianDayNumberDifference; } - return a._secondsOfDay - b._secondsOfDay; + return a.secondsOfDay - b.secondsOfDay; }; /** @@ -668,8 +621,8 @@ define([ return (left === right) || (defined(left) && defined(right) && - left._julianDayNumber === right._julianDayNumber && - left._secondsOfDay === right._secondsOfDay); + left.dayNumber === right.dayNumber && + left.secondsOfDay === right.secondsOfDay); }; /** @@ -692,7 +645,7 @@ define([ } //>>includeEnd('debug'); - return Math.abs(left.getSecondsDifference(right)) <= epsilon; + return Math.abs(JulianDate.getSecondsDifference(left, right)) <= epsilon; }; /** @@ -709,47 +662,9 @@ define([ * Returns the total number of whole and fractional days represented by this astronomical Julian date. * * @returns {Number} The Julian date as single floating point number. - * - * @see JulianDate#getJulianDayNumber - * @see JulianDate#getJulianTimeFraction - */ - JulianDate.prototype.getTotalDays = function() { - return this._julianDayNumber + (this._secondsOfDay / TimeConstants.SECONDS_PER_DAY); - }; - - /** - * Returns the whole number component of the Julian date. - * - * @returns {Number} A whole number representing the Julian day number. - * - * @see JulianDate#getTotalDays - * @see JulianDate#getJulianTimeFraction - */ - JulianDate.prototype.getJulianDayNumber = function() { - return this._julianDayNumber; - }; - - /** - * Returns the floating point component of the Julian date representing the time of day. - * - * @returns {Number} The floating point component of the Julian date representing the time of day. - * - * @see JulianDate#getTotalDays - * @see JulianDate#getJulianDayNumber - */ - JulianDate.prototype.getJulianTimeFraction = function() { - return this._secondsOfDay / TimeConstants.SECONDS_PER_DAY; - }; - - /** - * Return the number of seconds elapsed into the current Julian day (starting at noon). - * - * @returns {Number} The number of seconds elapsed into the current day. - * - * @see JulianDate#getJulianDayNumber */ - JulianDate.prototype.getSecondsOfDay = function() { - return this._secondsOfDay; + JulianDate.getTotalDays = function(value) { + return value.dayNumber + (value.secondsOfDay / TimeConstants.SECONDS_PER_DAY); }; var toGregorianDateScratch = new JulianDate(0, 0, TimeStandard.TAI); @@ -759,20 +674,20 @@ define([ * * @returns {GregorianDate} A gregorian date. */ - JulianDate.prototype.toGregorianDate = function() { + JulianDate.toGregorianDate = function(value) { var isLeapSecond = false; - var thisUtc = convertTaiToUtc(this, toGregorianDateScratch); + var thisUtc = convertTaiToUtc(value, toGregorianDateScratch); if (!defined(thisUtc)) { //Conversion to UTC will fail if we are during a leap second. //If that's the case, subtract a second and convert again. //JavaScript doesn't support leap seconds, so this results in second 59 being repeated twice. - this.addSeconds(-1, toGregorianDateScratch); + JulianDate.addSeconds(value, -1, toGregorianDateScratch); thisUtc = convertTaiToUtc(toGregorianDateScratch, toGregorianDateScratch); isLeapSecond = true; } - var julianDayNumber = thisUtc._julianDayNumber; - var secondsOfDay = thisUtc._secondsOfDay; + var julianDayNumber = thisUtc.dayNumber; + var secondsOfDay = thisUtc.secondsOfDay; if (secondsOfDay >= 43200.0) { julianDayNumber += 1; @@ -818,8 +733,8 @@ define([ * * @returns {Date} A new JavaScript Date equivalent to this JulianDate. */ - JulianDate.prototype.toDate = function() { - var gDate = this.toGregorianDate(); + JulianDate.toDate = function(value) { + var gDate = JulianDate.toGregorianDate(value); var second = gDate.second; if (gDate.isLeapSecond) { second -= 1; @@ -833,8 +748,8 @@ define([ * @param {Number} [precision] The number of fractional digits used to represent the seconds component. By default, the most precise representation is used. * @returns {String} An ISO8601 string represenation of this JulianDate. */ - JulianDate.prototype.toIso8601 = function(precision) { - var gDate = this.toGregorianDate(); + JulianDate.toIso8601 = function(value, precision) { + var gDate = JulianDate.toGregorianDate(value); var millisecondStr; if (!defined(precision) && gDate.millisecond !== 0) { @@ -860,7 +775,6 @@ define([ * @param {JulianDate} other The other JulianDate, which is the end of the interval. * @returns {Number} The number of seconds that have elpased from this JulianDate to the other JulianDate. * - * @see JulianDate#getMinutesDifference * @see JulianDate#getDaysDifference * * @example @@ -868,30 +782,9 @@ define([ * var end = Cesium.JulianDate.fromDate(new Date('July 5, 2011 12:01:00')); * var difference = start.getSecondsDifference(end); // 86460.0 seconds */ - JulianDate.prototype.getSecondsDifference = function(other) { - var julianDate1 = this; - var julianDate2 = other; - var dayDifference = (julianDate2._julianDayNumber - julianDate1._julianDayNumber) * TimeConstants.SECONDS_PER_DAY; - return (dayDifference + (julianDate2._secondsOfDay - julianDate1._secondsOfDay)); - }; - - /** - * Computes the number of minutes that have elapsed from this JulianDate to the other - * JulianDate. - * - * @param {JulianDate} other The other JulianDate, which is the end of the interval. - * @returns {Number} The number of seconds that have elpased from this JulianDate to the other JulianDate. - * - * @see JulianDate#getSecondsDifference - * @see JulianDate#getDaysDifference - * - * @example - * var start = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); - * var end = Cesium.JulianDate.fromDate(new Date('July 5, 2011 12:01:00')); - * var difference = start.getMinutesDifference(end); // 1441.0 minutes - */ - JulianDate.prototype.getMinutesDifference = function(other) { - return this.getSecondsDifference(other) / TimeConstants.SECONDS_PER_MINUTE; + JulianDate.getSecondsDifference = function(left, right) { + var dayDifference = (right.dayNumber - left.dayNumber) * TimeConstants.SECONDS_PER_DAY; + return (dayDifference + (right.secondsOfDay - left.secondsOfDay)); }; /** @@ -901,19 +794,14 @@ define([ * @param {JulianDate} other The other JulianDate, which is the end of the interval. * @returns {Number} The number of days that have elpased from this JulianDate to the other JulianDate. * - * @see JulianDate#getSecondsDifference - * @see JulianDate#getMinutesDifference - * * @example * var start = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); * var end = Cesium.JulianDate.fromDate(new Date('July 5, 2011 14:24:00')); - * var difference = start.getDaysDifference(end); // 1.1 days + * var difference = JulianDate.getDaysDifference(start, end); // 1.1 days */ - JulianDate.prototype.getDaysDifference = function(other) { - var julianDate1 = this; - var julianDate2 = other; - var dayDifference = (julianDate2._julianDayNumber - julianDate1._julianDayNumber); - var secondDifference = (julianDate2._secondsOfDay - julianDate1._secondsOfDay) / TimeConstants.SECONDS_PER_DAY; + JulianDate.getDaysDifference = function(left, right) { + var dayDifference = (right.dayNumber - left.dayNumber); + var secondDifference = (right.secondsOfDay - left.secondsOfDay) / TimeConstants.SECONDS_PER_DAY; return dayDifference + secondDifference; }; @@ -924,14 +812,9 @@ define([ * * @see LeapSecond * @see TimeStandard - * - * @example - * var date = new Date('August 1, 2012 12:00:00 UTC'); - * var julianDate = Cesium.JulianDate.fromDate(date); - * var difference = julianDate.getTaiMinusUtc(); //35 */ - JulianDate.prototype.getTaiMinusUtc = function() { - binarySearchScratchLeapSecond.julianDate = this; + JulianDate.getTaiMinusUtc = function(value) { + binarySearchScratchLeapSecond.julianDate = value; var leapSeconds = LeapSecond._leapSeconds; var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, LeapSecond.compareLeapSecondDate); if (index < 0) { @@ -952,25 +835,21 @@ define([ * @param {JulianDate} [result] The JulianDate to store the result into. * @returns {JulianDate} The modified result parameter or a new JulianDate instance if it was not provided. * - * @see JulianDate#addMinutes - * @see JulianDate#addHours - * @see JulianDate#addDays - * * @example * var date = new Date(); * date.setUTCFullYear(2011, 6, 4); // July 4, 2011 @ 12:00:00 UTC * date.setUTCHours(12, 0, 00, 0); * var start = Cesium.JulianDate.fromDate(date); - * var end = start.addSeconds(95); // July 4, 2011 @ 12:01:35 UTC + * var end = JulianDate.addSeconds(start, 95); // July 4, 2011 @ 12:01:35 UTC */ - JulianDate.prototype.addSeconds = function(seconds, result) { + JulianDate.addSeconds = function(julianDate, seconds, result) { //>>includeStart('debug', pragmas.debug); - if (seconds === null || isNaN(seconds)) { - throw new DeveloperError('seconds is required and must be a number.'); + if (!defined(seconds)) { + throw new DeveloperError('seconds is required.'); } //>>includeEnd('debug'); - return setComponents(this._julianDayNumber, this._secondsOfDay + seconds, result); + return setComponents(julianDate.dayNumber, julianDate.secondsOfDay + seconds, result); }; /** @@ -980,10 +859,6 @@ define([ * @param {Number} duration An integer number of minutes to add or subtract. * @returns {JulianDate} A new JulianDate object * - * @see JulianDate#addSeconds - * @see JulianDate#addHours - * @see JulianDate#addDays - * * @example * var date = new Date(); * date.setUTCFullYear(2011, 6, 4); // July 4, 2011 @ 12:00 UTC @@ -991,15 +866,15 @@ define([ * var start = Cesium.JulianDate.fromDate(date); * var end = start.addMinutes(65); // July 4, 2011 @ 13:05 UTC */ - JulianDate.prototype.addMinutes = function(duration) { + JulianDate.addMinutes = function(julianDate, duration) { //>>includeStart('debug', pragmas.debug); - if (duration === null || isNaN(duration)) { + if (!defined(duration)) { throw new DeveloperError('duration is required and must be a number.'); } //>>includeEnd('debug'); - var newSecondsOfDay = this._secondsOfDay + (duration * TimeConstants.SECONDS_PER_MINUTE); - return new JulianDate(this._julianDayNumber, newSecondsOfDay, TimeStandard.TAI); + var newSecondsOfDay = julianDate.secondsOfDay + (duration * TimeConstants.SECONDS_PER_MINUTE); + return new JulianDate(julianDate.dayNumber, newSecondsOfDay, TimeStandard.TAI); }; /** @@ -1008,27 +883,16 @@ define([ * * @param {Number} duration An integer number of hours to add or subtract. * @returns {JulianDate} A new JulianDate object - * - * @see JulianDate#addSeconds - * @see JulianDate#addMinutes - * @see JulianDate#addDays - * - * @example - * var date = new Date(); - * date.setUTCFullYear(2011, 6, 4); // July 4, 2011 @ 12:00 UTC - * date.setUTCHours(12, 0, 0, 0); - * var start = Cesium.JulianDate.fromDate(date); - * var end = start.addHours(6); // July 4, 2011 @ 18:00 UTC */ - JulianDate.prototype.addHours = function(duration) { + JulianDate.addHours = function(julianDate, value) { //>>includeStart('debug', pragmas.debug); - if (duration === null || isNaN(duration)) { - throw new DeveloperError('duration is required and must be a number.'); + if (!defined(value)) { + throw new DeveloperError('duration is required.'); } //>>includeEnd('debug'); - var newSecondsOfDay = this._secondsOfDay + (duration * TimeConstants.SECONDS_PER_HOUR); - return new JulianDate(this._julianDayNumber, newSecondsOfDay, TimeStandard.TAI); + var newSecondsOfDay = julianDate.secondsOfDay + (value * TimeConstants.SECONDS_PER_HOUR); + return new JulianDate(julianDate.dayNumber, newSecondsOfDay, TimeStandard.TAI); }; /** @@ -1037,27 +901,16 @@ define([ * * @param {Number} duration An integer number of days to add or subtract. * @returns {JulianDate} A new JulianDate object - * - * @see JulianDate#addSeconds - * @see JulianDate#addMinutes - * @see JulianDate#addHours - * - * @example - * var date = new Date(); - * date.setUTCFullYear(2011, 6, 4); // July 4, 2011 @ 12:00 UTC - * date.setUTCHours(12, 0, 0, 0); - * var start = Cesium.JulianDate.fromDate(date); - * var end = start.addDays(5); // July 9, 2011 @ 12:00 UTC */ - JulianDate.prototype.addDays = function(duration) { + JulianDate.addDays = function(julianDate, duration) { //>>includeStart('debug', pragmas.debug); - if (duration === null || isNaN(duration)) { + if (!defined(duration)) { throw new DeveloperError('duration is required and must be a number.'); } //>>includeEnd('debug'); - var newJulianDayNumber = this._julianDayNumber + duration; - return new JulianDate(newJulianDayNumber, this._secondsOfDay, TimeStandard.TAI); + var newJulianDayNumber = julianDate.dayNumber + duration; + return new JulianDate(newJulianDayNumber, julianDate.secondsOfDay, TimeStandard.TAI); }; /** @@ -1065,18 +918,9 @@ define([ * * @param {JulianDate} other The JulianDate to be compared. * @returns {Boolean} true if this JulianDate is chronologically earlier than other; otherwise, false. - * - * @see JulianDate#lessThanOrEquals - * @see JulianDate#greaterThan - * @see JulianDate#greaterThanOrEquals - * - * @example - * var start = Cesium.JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); - * var end = Cesium.JulianDate.fromDate(new Date('July 6, 2011 12:01:00')); - * start.lessThan(end); // true */ - JulianDate.prototype.lessThan = function(other) { - return JulianDate.compare(this, other) < 0; + JulianDate.lessThan = function(left, right) { + return JulianDate.compare(left, right) < 0; }; /** @@ -1092,10 +936,10 @@ define([ * @example * var start = Cesium.JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); * var end = Cesium.JulianDate.fromDate(new Date('July 6, 2011 12:00:00')); - * start.lessThanOrEquals(end); // true + * JulianDate.lessThanOrEquals(start, end); // true */ - JulianDate.prototype.lessThanOrEquals = function(other) { - return JulianDate.compare(this, other) <= 0; + JulianDate.lessThanOrEquals = function(left, right) { + return JulianDate.compare(left, right) <= 0; }; /** @@ -1111,10 +955,10 @@ define([ * @example * var start = Cesium.JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); * var end = Cesium.JulianDate.fromDate(new Date('July 6, 2011 12:01:00')); - * end.greaterThan(start); // true + * JulianDate.greaterThan(end, start); // true */ - JulianDate.prototype.greaterThan = function(other) { - return JulianDate.compare(this, other) > 0; + JulianDate.greaterThan = function(left, right) { + return JulianDate.compare(left, right) > 0; }; /** @@ -1122,18 +966,9 @@ define([ * * @param {JulianDate} other The JulianDate to be compared. * @returns {Boolean} true if this JulianDate is chronologically later than or equal to other; otherwise, false. - * - * @see JulianDate#lessThan - * @see JulianDate#lessThanOrEquals - * @see JulianDate#greaterThan - * - * @example - * var start = Cesium.JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); - * var end = Cesium.JulianDate.fromDate(new Date('July 6, 2011 12:00:00')); - * end.greaterThanOrEquals(start); // true */ - JulianDate.prototype.greaterThanOrEquals = function(other) { - return JulianDate.compare(this, other) >= 0; + JulianDate.greaterThanOrEquals = function(left, right) { + return JulianDate.compare(left, right) >= 0; }; /** diff --git a/Source/Core/Simon1994PlanetaryPositions.js b/Source/Core/Simon1994PlanetaryPositions.js index 830ca38e96c0..9191d2db2992 100644 --- a/Source/Core/Simon1994PlanetaryPositions.js +++ b/Source/Core/Simon1994PlanetaryPositions.js @@ -55,11 +55,11 @@ define([ var J2000d = 2451545; function taiToTdb(date, result) { //Converts TAI to TT - result = date.addSeconds(TdtMinusTai, result); + result = JulianDate.addSeconds(date, TdtMinusTai, result); //Converts TT to TDB - var days = result.getTotalDays() - J2000d; - result = result.addSeconds(computeTdbMinusTtSpice(days), result); + var days = JulianDate.getTotalDays(result) - J2000d; + result = JulianDate.addSeconds(result, computeTdbMinusTtSpice(days), result); return result; } @@ -317,7 +317,7 @@ define([ // t is thousands of years from J2000 TDB taiToTdb(date, scratchDate); - var x = (scratchDate.getJulianDayNumber() - epoch.getJulianDayNumber()) + ((scratchDate.getSecondsOfDay() - epoch.getSecondsOfDay())/TimeConstants.SECONDS_PER_DAY); + var x = (scratchDate.dayNumber - epoch.dayNumber) + ((scratchDate.secondsOfDay - epoch.secondsOfDay)/TimeConstants.SECONDS_PER_DAY); var t = x / (TimeConstants.DAYS_PER_JULIAN_CENTURY * 10.0); var u = 0.35953620 * t; @@ -355,7 +355,7 @@ define([ */ function computeSimonMoon(date, result) { taiToTdb(date, scratchDate); - var x = (scratchDate.getJulianDayNumber() - epoch.getJulianDayNumber()) + ((scratchDate.getSecondsOfDay() - epoch.getSecondsOfDay())/TimeConstants.SECONDS_PER_DAY); + var x = (scratchDate.dayNumber - epoch.dayNumber) + ((scratchDate.secondsOfDay - epoch.secondsOfDay)/TimeConstants.SECONDS_PER_DAY); var t = x / (TimeConstants.DAYS_PER_JULIAN_CENTURY); var t2 = t * t; var t3 = t2 * t; diff --git a/Source/Core/TimeInterval.js b/Source/Core/TimeInterval.js index 662e54505a5b..5899409f780a 100644 --- a/Source/Core/TimeInterval.js +++ b/Source/Core/TimeInterval.js @@ -209,7 +209,7 @@ define([ var isStartIncluded; var isStopIncluded; - if (otherStart.greaterThanOrEquals(thisStart) && thisStop.greaterThanOrEquals(otherStart)) { + if (JulianDate.greaterThanOrEquals(otherStart, thisStart) && JulianDate.greaterThanOrEquals(thisStop, otherStart)) { isStartIncluded = (!JulianDate.equals(otherStart, thisStart) && otherIsStartIncluded) || (thisIsStartIncluded && otherIsStartIncluded); @@ -217,7 +217,7 @@ define([ outputData = defined(mergeCallback) ? mergeCallback(this.data, other.data) : this.data; - if (thisStop.greaterThanOrEquals(otherStop)) { + if (JulianDate.greaterThanOrEquals(thisStop, otherStop)) { isStopIncluded = isStopIncluded || (!JulianDate.equals(otherStop, thisStop) && otherIsStopIncluded); return new TimeInterval(otherStart, otherStop, isStartIncluded, isStopIncluded, outputData); } @@ -226,14 +226,14 @@ define([ return new TimeInterval(otherStart, thisStop, isStartIncluded, isStopIncluded, outputData); } - if (otherStart.lessThanOrEquals(thisStart) && thisStart.lessThanOrEquals(otherStop)) { + if (JulianDate.lessThanOrEquals(otherStart, thisStart) && JulianDate.lessThanOrEquals(thisStart, otherStop)) { isStartIncluded = (JulianDate.equals(otherStart, thisStart) === false && thisIsStartIncluded) || (thisIsStartIncluded && otherIsStartIncluded); isStopIncluded = thisIsStopIncluded && otherIsStopIncluded; outputData = defined(mergeCallback) ? mergeCallback(this.data, other.data) : this.data; - if (thisStop.greaterThanOrEquals(otherStop)) { + if (JulianDate.greaterThanOrEquals(thisStop, otherStop)) { isStopIncluded = isStopIncluded || (JulianDate.equals(otherStop, thisStop) === false && otherIsStopIncluded); return new TimeInterval(thisStart, otherStop, isStartIncluded, isStopIncluded, outputData); } diff --git a/Source/Core/TimeIntervalCollection.js b/Source/Core/TimeIntervalCollection.js index faf4062b22b3..48c4b22e5211 100644 --- a/Source/Core/TimeIntervalCollection.js +++ b/Source/Core/TimeIntervalCollection.js @@ -269,7 +269,7 @@ define([ // Handle the common case quickly: we're adding a new interval which is after all existing intervals. if (thisIntervals.length === 0 || - interval.start.greaterThan(thisIntervals[thisIntervals.length - 1].stop)) { + JulianDate.greaterThan(interval.start, thisIntervals[thisIntervals.length - 1].stop)) { thisIntervals.push(interval); this._intervalsChanged.raiseEvent(this); return; @@ -306,7 +306,7 @@ define([ // There is an overlap if (defined(equalsCallback) ? equalsCallback(thisIntervals[index - 1].data, interval.data) : (thisIntervals[index - 1].data === interval.data)) { // Overlapping intervals have the same data, so combine them - if (interval.stop.greaterThan(thisIntervals[index - 1].stop)) { + if (JulianDate.greaterThan(interval.stop, thisIntervals[index - 1].stop)) { interval = new TimeInterval(thisIntervals[index - 1].start, interval.stop, thisIntervals[index - 1].isStartIncluded, @@ -358,9 +358,9 @@ define([ if (defined(equalsCallback) ? equalsCallback(thisIntervals[index].data, interval.data) : thisIntervals[index].data === interval.data) { // Overlapping intervals have the same data, so combine them interval = new TimeInterval(interval.start, - thisIntervals[index].stop.greaterThan(interval.stop) ? thisIntervals[index].stop : interval.stop, + JulianDate.greaterThan(thisIntervals[index].stop, interval.stop) ? thisIntervals[index].stop : interval.stop, interval.isStartIncluded, - thisIntervals[index].stop.greaterThan(interval.stop) ? thisIntervals[index].isStopIncluded : interval.isStopIncluded, + JulianDate.greaterThan(thisIntervals[index].stop, interval.stop) ? thisIntervals[index].isStopIncluded : interval.isStopIncluded, interval.data); thisIntervals.splice(index, 1); } else { @@ -426,12 +426,12 @@ define([ if (index > 0) { var indexMinus1 = thisIntervals[index - 1]; var indexMinus1Stop = indexMinus1.stop; - if (indexMinus1Stop.greaterThan(intervalStart) || + if (JulianDate.greaterThan(indexMinus1Stop, intervalStart) || (indexMinus1Stop.equals(intervalStart) && indexMinus1.isStopIncluded && intervalIsStartIncluded)) { result = true; - if (indexMinus1Stop.greaterThan(intervalStop) || + if (JulianDate.greaterThan(indexMinus1Stop, intervalStop) || (indexMinus1.isStopIncluded && !intervalIsStopIncluded && indexMinus1Stop.equals(intervalStop))) { // Break the existing interval into two pieces thisIntervals.splice(index, 0, new TimeInterval(intervalStop, indexMinus1Stop, !intervalIsStopIncluded, indexMinus1.isStopIncluded, indexMinus1.data)); @@ -456,7 +456,7 @@ define([ // Remove any intervals that are completely overlapped by the input interval. while (index < thisIntervals.length && - intervalStop.greaterThan(indexInterval.stop)) { + JulianDate.greaterThan(intervalStop, indexInterval.stop)) { result = true; thisIntervals.splice(index, 1); } @@ -484,7 +484,7 @@ define([ // Truncate any partially-overlapped intervals. if (index < thisIntervals.length && - (intervalStop.greaterThan(indexInterval.start) || + (JulianDate.greaterThan(intervalStop, indexInterval.start) || (intervalStop.equals(indexInterval.start) && intervalIsStopIncluded && indexInterval.isStartIncluded))) { @@ -557,9 +557,9 @@ define([ while (left < thisIntervals.length && right < otherIntervals.length) { var leftInterval = thisIntervals[left]; var rightInterval = otherIntervals[right]; - if (leftInterval.stop.lessThan(rightInterval.start)) { + if (JulianDate.lessThan(leftInterval.stop, rightInterval.start)) { ++left; - } else if (rightInterval.stop.lessThan(leftInterval.start)) { + } else if (JulianDate.lessThan(rightInterval.stop, leftInterval.start)) { ++right; } else { // The following will return an intersection whose data is 'merged' if the callback is defined @@ -575,7 +575,7 @@ define([ } } - if (leftInterval.stop.lessThan(rightInterval.stop) || + if (JulianDate.lessThan(leftInterval.stop, rightInterval.stop) || (leftInterval.stop.equals(rightInterval.stop) && !leftInterval.isStopIncluded && rightInterval.isStopIncluded)) { diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index 979736c8402a..3ab74f63d930 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -12,6 +12,7 @@ define([ './Ellipsoid', './Iau2006XysData', './Iau2006XysSample', + './JulianDate', './Math', './Matrix3', './Matrix4', @@ -29,6 +30,7 @@ define([ Ellipsoid, Iau2006XysData, Iau2006XysSample, + JulianDate, CesiumMath, Matrix3, Matrix4, @@ -279,9 +281,9 @@ define([ // We do not want to use the function like convertTaiToUtc in JulianDate because // we explicitly do not want to fail when inside the leap second. - var dateInUtc = date.addSeconds(-date.getTaiMinusUtc()); - var utcDayNumber = dateInUtc.getJulianDayNumber(); - var utcSecondsIntoDay = dateInUtc.getSecondsOfDay(); + var dateInUtc = JulianDate.addSeconds(date, -JulianDate.getTaiMinusUtc(date)); + var utcDayNumber = dateInUtc.dayNumber; + var utcSecondsIntoDay = dateInUtc.secondsOfDay; var t; var diffDays = utcDayNumber - 2451545; @@ -361,10 +363,10 @@ define([ * }); */ Transforms.preloadIcrfFixed = function(timeInterval) { - var startDayTT = timeInterval.start.getJulianDayNumber(); - var startSecondTT = timeInterval.start.getSecondsOfDay() + ttMinusTai; - var stopDayTT = timeInterval.stop.getJulianDayNumber(); - var stopSecondTT = timeInterval.stop.getSecondsOfDay() + ttMinusTai; + var startDayTT = timeInterval.start.dayNumber; + var startSecondTT = timeInterval.start.secondsOfDay + ttMinusTai; + var stopDayTT = timeInterval.stop.dayNumber; + var stopSecondTT = timeInterval.stop.secondsOfDay + ttMinusTai; var xysPromise = Transforms.iau2006XysData.preload(startDayTT, startSecondTT, stopDayTT, stopSecondTT); var eopPromise = Transforms.earthOrientationParameters.getPromiseToLoad(); @@ -454,10 +456,10 @@ define([ // There is no external conversion to Terrestrial Time (TT). // So use International Atomic Time (TAI) and convert using offsets. // Here we are assuming that dayTT and secondTT are positive - var dayTT = date.getJulianDayNumber(); + var dayTT = date.dayNumber; // It's possible here that secondTT could roll over 86400 // This does not seem to affect the precision (unit tests check for this) - var secondTT = date.getSecondsOfDay() + ttMinusTai; + var secondTT = date.secondsOfDay + ttMinusTai; var xys = Transforms.iau2006XysData.computeXysRadians(dayTT, secondTT, xysScratch); if (!defined(xys)) { @@ -487,8 +489,8 @@ define([ // Similar to TT conversions above // It's possible here that secondTT could roll over 86400 // This does not seem to affect the precision (unit tests check for this) - var dateUt1day = date.getJulianDayNumber(); - var dateUt1sec = date.getSecondsOfDay() - date.getTaiMinusUtc() + eop.ut1MinusUtc; + var dateUt1day = date.dayNumber; + var dateUt1sec = date.secondsOfDay - JulianDate.getTaiMinusUtc(date) + eop.ut1MinusUtc; // Compute Earth rotation angle // The IERS standard for era is diff --git a/Source/DynamicScene/CzmlDataSource.js b/Source/DynamicScene/CzmlDataSource.js index 73c83391c6fb..6d0cbbde64ef 100644 --- a/Source/DynamicScene/CzmlDataSource.js +++ b/Source/DynamicScene/CzmlDataSource.js @@ -1520,7 +1520,7 @@ define([ if (!availability.start.equals(Iso8601.MINIMUM_VALUE)) { var startTime = availability.start; var stopTime = availability.stop; - var totalSeconds = startTime.getSecondsDifference(stopTime); + var totalSeconds = JulianDate.getSecondsDifference(startTime, stopTime); var multiplier = Math.round(totalSeconds / 120.0); czmlClock = new DynamicClock(); diff --git a/Source/DynamicScene/DynamicObjectCollection.js b/Source/DynamicScene/DynamicObjectCollection.js index 26228be9ea9b..5bd0a381ff9c 100644 --- a/Source/DynamicScene/DynamicObjectCollection.js +++ b/Source/DynamicScene/DynamicObjectCollection.js @@ -7,6 +7,7 @@ define([ '../Core/DeveloperError', '../Core/Event', '../Core/Iso8601', + '../Core/JulianDate', '../Core/RuntimeError', '../Core/TimeInterval', './DynamicObject' @@ -18,6 +19,7 @@ define([ DeveloperError, Event, Iso8601, + JulianDate, RuntimeError, TimeInterval, DynamicObject) { @@ -135,10 +137,10 @@ define([ if (defined(availability)) { var start = availability.start; var stop = availability.stop; - if (start.lessThan(startTime) && !start.equals(Iso8601.MINIMUM_VALUE)) { + if (JulianDate.lessThan(start, startTime) && !start.equals(Iso8601.MINIMUM_VALUE)) { startTime = start; } - if (stop.greaterThan(stopTime) && !stop.equals(Iso8601.MAXIMUM_VALUE)) { + if (JulianDate.greaterThan(stop, stopTime) && !stop.equals(Iso8601.MAXIMUM_VALUE)) { stopTime = stop; } } diff --git a/Source/DynamicScene/DynamicObjectView.js b/Source/DynamicScene/DynamicObjectView.js index a7be01edf1ea..4b3107ab5979 100644 --- a/Source/DynamicScene/DynamicObjectView.js +++ b/Source/DynamicScene/DynamicObjectView.js @@ -5,6 +5,7 @@ define([ '../Core/defined', '../Core/DeveloperError', '../Core/Ellipsoid', + '../Core/JulianDate', '../Core/Math', '../Core/Matrix3', '../Core/Transforms', @@ -15,6 +16,7 @@ define([ defined, DeveloperError, Ellipsoid, + JulianDate, CesiumMath, Matrix3, Transforms, @@ -43,7 +45,7 @@ define([ // The time delta was determined based on how fast satellites move compared to vehicles near the surface. // Slower moving vehicles will most likely default to east-north-up, while faster ones will be VVLH. - var deltaTime = time.addSeconds(0.001); + var deltaTime = JulianDate.addSeconds(time, 0.001); var deltaCartesian = positionProperty.getValue(deltaTime, updateTransformCartesian3Scratch1); if (defined(deltaCartesian)) { var toInertial = Transforms.computeFixedToIcrfMatrix(time, updateTransformMatrix3Scratch1); diff --git a/Source/DynamicScene/DynamicPathVisualizer.js b/Source/DynamicScene/DynamicPathVisualizer.js index 00790974d3e6..5878c9a12b7c 100644 --- a/Source/DynamicScene/DynamicPathVisualizer.js +++ b/Source/DynamicScene/DynamicPathVisualizer.js @@ -5,6 +5,7 @@ define([ '../Core/defined', '../Core/destroyObject', '../Core/DeveloperError', + '../Core/JulianDate', '../Core/Matrix3', '../Core/Matrix4', '../Core/ReferenceFrame', @@ -24,6 +25,7 @@ define([ defined, destroyObject, DeveloperError, + JulianDate, Matrix3, Matrix4, ReferenceFrame, @@ -50,7 +52,7 @@ define([ result[r++] = tmp; } - var steppedOnNow = !defined(updateTime) || updateTime.lessThanOrEquals(start) || updateTime.greaterThanOrEquals(stop); + var steppedOnNow = !defined(updateTime) || JulianDate.lessThanOrEquals(updateTime, start) || JulianDate.greaterThanOrEquals(updateTime, stop); //Iterate over all interval times and add the ones that fall in our //time range. Note that times can contain data outside of @@ -65,14 +67,14 @@ define([ var sampleStepSize; while (t < len) { - if (!steppedOnNow && current.greaterThanOrEquals(updateTime)) { + if (!steppedOnNow && JulianDate.greaterThanOrEquals(current, updateTime)) { tmp = property.getValueInReferenceFrame(updateTime, referenceFrame, result[r]); if (defined(tmp)) { result[r++] = tmp; } steppedOnNow = true; } - if (current.greaterThan(start) && current.lessThan(loopStop) && !current.equals(updateTime)) { + if (JulianDate.greaterThan(current, start) && JulianDate.lessThan(current, loopStop) && !current.equals(updateTime)) { tmp = property.getValueInReferenceFrame(current, referenceFrame, result[r]); if (defined(tmp)) { result[r++] = tmp; @@ -82,7 +84,7 @@ define([ if (t < (len - 1)) { if (maximumStep > 0 && !sampling) { var next = times[t + 1]; - var secondsUntilNext = current.getSecondsDifference(next); + var secondsUntilNext = JulianDate.getSecondsDifference(current, next); sampling = secondsUntilNext > maximumStep; if (sampling) { @@ -94,7 +96,7 @@ define([ } if (sampling && sampleStepsTaken < sampleStepsToTake) { - current = current.addSeconds(sampleStepSize); + current = JulianDate.addSeconds(current, sampleStepSize); sampleStepsTaken++; continue; } @@ -119,9 +121,9 @@ define([ var index = startingIndex; var time = start; var stepSize = Math.max(maximumStep, 60); - var steppedOnNow = !defined(updateTime) || updateTime.lessThanOrEquals(start) || updateTime.greaterThanOrEquals(stop); - while (time.lessThan(stop)) { - if (!steppedOnNow && time.greaterThanOrEquals(updateTime)) { + var steppedOnNow = !defined(updateTime) || JulianDate.lessThanOrEquals(updateTime, start) || JulianDate.greaterThanOrEquals(updateTime, stop); + while (JulianDate.lessThan(time, stop)) { + if (!steppedOnNow && JulianDate.greaterThanOrEquals(time, updateTime)) { steppedOnNow = true; tmp = property.getValueInReferenceFrame(updateTime, referenceFrame, result[index]); if (defined(tmp)) { @@ -135,7 +137,7 @@ define([ index++; } i++; - time = start.addSeconds(stepSize * i); + time = JulianDate.addSeconds(start, stepSize * i); } //Always sample stop. tmp = property.getValueInReferenceFrame(stop, referenceFrame, result[index]); @@ -159,7 +161,7 @@ define([ if (interval.isStopIncluded) { time = interval.stop; } else { - time = interval.start.addSeconds(interval.start.getSecondsDifference(interval.stop) / 2); + time = JulianDate.addSeconds(interval.start, JulianDate.getSecondsDifference(interval.start, interval.stop) / 2); } } var tmp = property.getValueInReferenceFrame(time, referenceFrame, result[index]); @@ -192,12 +194,12 @@ define([ var intervalStop = interval.stop; var sampleStart = start; - if (intervalStart.greaterThan(sampleStart)) { + if (JulianDate.greaterThan(intervalStart, sampleStart)) { sampleStart = intervalStart; } var sampleStop = stop; - if (intervalStop.lessThan(sampleStop)) { + if (JulianDate.lessThan(intervalStop, sampleStop)) { sampleStop = intervalStop; } @@ -309,25 +311,25 @@ define([ //we won't have to draw anything anyway. if (show) { if (hasTrailTime) { - sampleStart = time.addSeconds(-trailTime); + sampleStart = JulianDate.addSeconds(time, -trailTime); } if (hasLeadTime) { - sampleStop = time.addSeconds(leadTime); + sampleStop = JulianDate.addSeconds(time, leadTime); } if (hasAvailability) { var start = availability.start; var stop = availability.stop; - if (!hasTrailTime || start.greaterThan(sampleStart)) { + if (!hasTrailTime || JulianDate.greaterThan(start, sampleStart)) { sampleStart = start; } - if (!hasLeadTime || stop.lessThan(sampleStop)) { + if (!hasLeadTime || JulianDate.lessThan(stop, sampleStop)) { sampleStop = stop; } } - show = sampleStart.lessThan(sampleStop); + show = JulianDate.lessThan(sampleStart, sampleStop); } } diff --git a/Source/DynamicScene/SampledProperty.js b/Source/DynamicScene/SampledProperty.js index 89b38557ab56..ec9f7bdfa060 100644 --- a/Source/DynamicScene/SampledProperty.js +++ b/Source/DynamicScene/SampledProperty.js @@ -59,7 +59,7 @@ define([ if (typeof date === 'string') { return JulianDate.fromIso8601(date); } - return epoch.addSeconds(date); + return JulianDate.addSeconds(epoch, date); } var timesSpliceArgs = []; @@ -324,7 +324,7 @@ define([ // Build the tables for ( var i = 0; i < length; ++i) { - xTable[i] = times[lastIndex].getSecondsDifference(times[firstIndex + i]); + xTable[i] = JulianDate.getSecondsDifference(times[lastIndex], times[firstIndex + i]); } if (!defined(innerType.convertPackedArrayForInterpolation)) { @@ -343,7 +343,7 @@ define([ } // Interpolate! - var x = times[lastIndex].getSecondsDifference(time); + var x = JulianDate.getSecondsDifference(times[lastIndex], time); var interpolationResult = interpolationAlgorithm.interpolateOrderZero(x, xTable, yTable, packedInterpolationLength, this._interpolationResult); if (!defined(innerType.unpackInterpolationResult)) { diff --git a/Source/Scene/ModelAnimationCollection.js b/Source/Scene/ModelAnimationCollection.js index a58c21ee0698..16bb2edfb04c 100644 --- a/Source/Scene/ModelAnimationCollection.js +++ b/Source/Scene/ModelAnimationCollection.js @@ -119,7 +119,7 @@ define([ * name : 'another animation name', * startTime : startTime, * startOffset : 0.0, // Play at startTime (default) - * stopTime : startTime.addSeconds(4.0), + * stopTime : JulianDate.addSeconds(startTime, 4.0), * removeOnStop : false, // Do not remove when animation stops (default) * speedup : 2.0, // Play at double speed * reverse : true, // Play in reverse @@ -350,7 +350,7 @@ define([ var runtimeAnimation = scheduledAnimation._runtimeAnimation; if (!defined(scheduledAnimation._startTime)) { - scheduledAnimation._startTime = defaultValue(scheduledAnimation.startTime, sceneTime).addSeconds(scheduledAnimation.startOffset); + scheduledAnimation._startTime = JulianDate.addSeconds(defaultValue(scheduledAnimation.startTime, sceneTime), scheduledAnimation.startOffset); } if (!defined(scheduledAnimation._duration)) { @@ -362,7 +362,7 @@ define([ var stopTime = scheduledAnimation.stopTime; // [0.0, 1.0] normalized local animation time - var delta = (duration !== 0.0) ? (startTime.getSecondsDifference(sceneTime) / duration) : 0.0; + var delta = (duration !== 0.0) ? (JulianDate.getSecondsDifference(startTime, sceneTime) / duration) : 0.0; var pastStartTime = (delta >= 0.0); // Play animation if @@ -373,7 +373,7 @@ define([ ((delta <= 1.0) || ((scheduledAnimation.loop === ModelAnimationLoop.REPEAT) || (scheduledAnimation.loop === ModelAnimationLoop.MIRRORED_REPEAT))) && - (!defined(stopTime) || sceneTime.lessThanOrEquals(stopTime)); + (!defined(stopTime) || JulianDate.lessThanOrEquals(sceneTime, stopTime)); if (play) { // STOPPED -> ANIMATING state transition? diff --git a/Source/Widgets/Animation/AnimationViewModel.js b/Source/Widgets/Animation/AnimationViewModel.js index e9d2e57fd5cf..2aaf72455e2e 100644 --- a/Source/Widgets/Animation/AnimationViewModel.js +++ b/Source/Widgets/Animation/AnimationViewModel.js @@ -6,6 +6,7 @@ define([ '../../Core/defined', '../../Core/defineProperties', '../../Core/DeveloperError', + '../../Core/JulianDate', '../../ThirdParty/knockout', '../../ThirdParty/sprintf', '../createCommand', @@ -17,6 +18,7 @@ define([ defined, defineProperties, DeveloperError, + JulianDate, knockout, sprintf, createCommand, @@ -241,10 +243,10 @@ define([ var result = false; if (clockRange === ClockRange.LOOP_STOP) { - result = currentTime.greaterThan(startTime) || (currentTime.equals(startTime) && multiplier > 0); + result = JulianDate.greaterThan(currentTime, startTime) || (currentTime.equals(startTime) && multiplier > 0); } else { var stopTime = clockViewModel.stopTime; - result = (currentTime.greaterThan(startTime) && currentTime.lessThan(stopTime)) || // + result = (JulianDate.greaterThan(currentTime, startTime) && JulianDate.lessThan(currentTime, stopTime)) || // (currentTime.equals(startTime) && multiplier > 0) || // (currentTime.equals(stopTime) && multiplier < 0); } @@ -264,7 +266,7 @@ define([ } var systemTime = clockViewModel.systemTime; - return systemTime.greaterThanOrEquals(clockViewModel.startTime) && systemTime.lessThanOrEquals(clockViewModel.stopTime); + return JulianDate.greaterThanOrEquals(systemTime, clockViewModel.startTime) && JulianDate.lessThanOrEquals(systemTime, clockViewModel.stopTime); }); this._isAnimating = undefined; @@ -370,7 +372,7 @@ define([ * @returns {String} The string representation of the calendar date portion of the provided date. */ AnimationViewModel.defaultDateFormatter = function(date, viewModel) { - var gregorianDate = date.toGregorianDate(); + var gregorianDate = JulianDate.toGregorianDate(date); return monthNames[gregorianDate.month - 1] + ' ' + gregorianDate.day + ' ' + gregorianDate.year; }; @@ -390,7 +392,7 @@ define([ * @returns {String} The string representation of the time portion of the provided date. */ AnimationViewModel.defaultTimeFormatter = function(date, viewModel) { - var gregorianDate = date.toGregorianDate(); + var gregorianDate = JulianDate.toGregorianDate(date); var millisecond = Math.round(gregorianDate.millisecond); if (Math.abs(viewModel._clockViewModel.multiplier) < 1) { return sprintf("%02d:%02d:%02d.%03d", gregorianDate.hour, gregorianDate.minute, gregorianDate.second, millisecond); diff --git a/Source/Widgets/Timeline/Timeline.js b/Source/Widgets/Timeline/Timeline.js index f60ef0bbbc5d..3b204b04e05a 100644 --- a/Source/Widgets/Timeline/Timeline.js +++ b/Source/Widgets/Timeline/Timeline.js @@ -203,7 +203,7 @@ define([ }; Timeline.prototype.zoomTo = function(startJulianDate, endJulianDate) { - this._timeBarSecondsSpan = startJulianDate.getSecondsDifference(endJulianDate); + this._timeBarSecondsSpan = JulianDate.getSecondsDifference(startJulianDate, endJulianDate); //>>includeStart('debug', pragmas.debug); if (this._timeBarSecondsSpan <= 0) { @@ -218,9 +218,9 @@ define([ if (this._clock && (this._clock.clockRange !== ClockRange.UNBOUNDED)) { var clockStart = this._clock.startTime; var clockEnd = this._clock.stopTime; - var clockSpan = clockStart.getSecondsDifference(clockEnd); - var startOffset = this._startJulian.getSecondsDifference(clockStart); - var endOffset = this._endJulian.getSecondsDifference(clockEnd); + var clockSpan = JulianDate.getSecondsDifference(clockStart, clockEnd); + var startOffset = JulianDate.getSecondsDifference(this._startJulian, clockStart); + var endOffset = JulianDate.getSecondsDifference(this._endJulian, clockEnd); if (this._timeBarSecondsSpan >= clockSpan) { // if new duration longer than clock range duration, clamp to full range. @@ -229,14 +229,14 @@ define([ this._endJulian = this._clock.stopTime; } else if (startOffset > 0) { // if timeline start is before clock start, shift right - this._endJulian = this._endJulian.addSeconds(startOffset); + this._endJulian = JulianDate.addSeconds(this._endJulian, startOffset); this._startJulian = clockStart; - this._timeBarSecondsSpan = this._startJulian.getSecondsDifference(this._endJulian); + this._timeBarSecondsSpan = JulianDate.getSecondsDifference(this._startJulian, this._endJulian); } else if (endOffset < 0) { // if timeline end is after clock end, shift left - this._startJulian = this._startJulian.addSeconds(endOffset); + this._startJulian = JulianDate.addSeconds(this._startJulian, endOffset); this._endJulian = clockEnd; - this._timeBarSecondsSpan = this._startJulian.getSecondsDifference(this._endJulian); + this._timeBarSecondsSpan = JulianDate.getSecondsDifference(this._startJulian, this._endJulian); } } @@ -253,14 +253,14 @@ define([ }; Timeline.prototype.zoomFrom = function(amount) { - var centerSec = this._startJulian.getSecondsDifference(this._scrubJulian); + var centerSec = JulianDate.getSecondsDifference(this._startJulian, this._scrubJulian); if ((amount > 1) || (centerSec < 0) || (centerSec > this._timeBarSecondsSpan)) { centerSec = this._timeBarSecondsSpan * 0.5; } else { centerSec += (centerSec - this._timeBarSecondsSpan * 0.5); } var centerSecFlip = this._timeBarSecondsSpan - centerSec; - this.zoomTo(this._startJulian.addSeconds(centerSec - (centerSec * amount)), this._endJulian.addSeconds((centerSecFlip * amount) - centerSecFlip)); + this.zoomTo(JulianDate.addSeconds(this._startJulian, centerSec - (centerSec * amount)), JulianDate.addSeconds(this._endJulian, (centerSecFlip * amount) - centerSecFlip)); }; function twoDigits(num) { @@ -268,7 +268,7 @@ define([ } Timeline.prototype.makeLabel = function(julianDate) { - var gregorian = julianDate.toGregorianDate(); + var gregorian = JulianDate.toGregorianDate(julianDate); var millisecond = gregorian.millisecond, millisecondString = ' UTC'; if ((millisecond > 0) && (this._timeBarSecondsSpan < 3600)) { millisecondString = Math.floor(millisecond).toString(); @@ -287,7 +287,7 @@ define([ Timeline.prototype._makeTics = function() { var timeBar = this._timeBarEle; - var seconds = this._startJulian.getSecondsDifference(this._scrubJulian); + var seconds = JulianDate.getSecondsDifference(this._startJulian, this._scrubJulian); var xPos = Math.round(seconds * this._topDiv.clientWidth / this._timeBarSecondsSpan); var scrubX = xPos - 8, tic; var widget = this; @@ -307,11 +307,11 @@ define([ if (duration < minimumDuration) { duration = minimumDuration; this._timeBarSecondsSpan = minimumDuration; - this._endJulian = this._startJulian.addSeconds(minimumDuration); + this._endJulian = JulianDate.addSeconds(this._startJulian, minimumDuration); } else if (duration > maximumDuration) { duration = maximumDuration; this._timeBarSecondsSpan = maximumDuration; - this._endJulian = this._startJulian.addSeconds(maximumDuration); + this._endJulian = JulianDate.addSeconds(this._startJulian, maximumDuration); } var timeBarWidth = this._timeBarEle.clientWidth; @@ -326,16 +326,16 @@ define([ // epochJulian: a nearby time to be considered "zero seconds", should be a round-ish number by human standards. var epochJulian; if (duration > 315360000) { // 3650+ days visible, epoch is start of the first visible century. - epochJulian = JulianDate.fromIso8601(startJulian.toDate().toISOString().substring(0, 2) + '00-01-01T00:00:00Z'); + epochJulian = JulianDate.fromIso8601(JulianDate.toDate(startJulian).toISOString().substring(0, 2) + '00-01-01T00:00:00Z'); } else if (duration > 31536000) { // 365+ days visible, epoch is start of the first visible decade. - epochJulian = JulianDate.fromIso8601(startJulian.toDate().toISOString().substring(0, 3) + '0-01-01T00:00:00Z'); + epochJulian = JulianDate.fromIso8601(JulianDate.toDate(startJulian).toISOString().substring(0, 3) + '0-01-01T00:00:00Z'); } else if (duration > 86400) { // 1+ day(s) visible, epoch is start of the year. - epochJulian = JulianDate.fromIso8601(startJulian.toDate().toISOString().substring(0, 4) + '-01-01T00:00:00Z'); + epochJulian = JulianDate.fromIso8601(JulianDate.toDate(startJulian).toISOString().substring(0, 4) + '-01-01T00:00:00Z'); } else { // Less than a day on timeline, epoch is midnight of the visible day. - epochJulian = JulianDate.fromIso8601(startJulian.toDate().toISOString().substring(0, 10) + 'T00:00:00Z'); + epochJulian = JulianDate.fromIso8601(JulianDate.toDate(startJulian).toISOString().substring(0, 10) + 'T00:00:00Z'); } // startTime: Seconds offset of the left side of the timeline from epochJulian. - var startTime = epochJulian.addSeconds(epsilonTime).getSecondsDifference(this._startJulian); + var startTime = JulianDate.getSecondsDifference(JulianDate.addSeconds(epochJulian, epsilonTime), this._startJulian); // endTime: Seconds offset of the right side of the timeline from epochJulian. var endTime = startTime + duration; this._epochJulian = epochJulian; @@ -358,7 +358,7 @@ define([ } // Width in pixels of a typical label, plus padding - this._rulerEle.innerHTML = this.makeLabel(this._endJulian.addSeconds(-minimumDuration)); + this._rulerEle.innerHTML = this.makeLabel(JulianDate.addSeconds(this._endJulian, -minimumDuration)); var sampleWidth = this._rulerEle.offsetWidth + 20; if (sampleWidth < 30) { // Workaround an apparent IE bug with measuring the width after going full-screen from inside an iframe. @@ -452,14 +452,14 @@ define([ this._mainTicSpan = mainTic; endTime += mainTic; tic = getStartTic(mainTic); - var leapSecond = epochJulian.getTaiMinusUtc(); + var leapSecond = JulianDate.getTaiMinusUtc(epochJulian); while (tic <= endTime) { - var ticTime = startJulian.addSeconds(tic - startTime); + var ticTime = JulianDate.addSeconds(startJulian, tic - startTime); if (mainTic > 2.1) { - var ticLeap = ticTime.getTaiMinusUtc(); + var ticLeap = JulianDate.getTaiMinusUtc(ticTime); if (Math.abs(ticLeap - leapSecond) > 0.1) { tic += (ticLeap - leapSecond); - ticTime = startJulian.addSeconds(tic - startTime); + ticTime = JulianDate.addSeconds(startJulian, tic - startTime); } } var ticLeft = Math.round(timeBarWidth * getAlpha(tic)); @@ -502,7 +502,7 @@ define([ this._scrubJulian = this._clock.currentTime; var scrubElement = this._scrubElement; if (defined(this._scrubElement)) { - var seconds = this._startJulian.getSecondsDifference(this._scrubJulian); + var seconds = JulianDate.getSecondsDifference(this._startJulian, this._scrubJulian); var xPos = Math.round(seconds * this._topDiv.clientWidth / this._timeBarSecondsSpan); if (this._lastXPos !== xPos) { @@ -514,13 +514,13 @@ define([ } if (defined(this._timelineDragLocation)) { this._setTimeBarTime(this._timelineDragLocation, this._timelineDragLocation * this._timeBarSecondsSpan / this._topDiv.clientWidth); - this.zoomTo(this._startJulian.addSeconds(this._timelineDrag), this._endJulian.addSeconds(this._timelineDrag)); + this.zoomTo(JulianDate.addSeconds(this._startJulian, this._timelineDrag), JulianDate.addSeconds(this._endJulian, this._timelineDrag)); } }; Timeline.prototype._setTimeBarTime = function(xPos, seconds) { xPos = Math.round(xPos); - this._scrubJulian = this._startJulian.addSeconds(seconds); + this._scrubJulian = JulianDate.addSeconds(this._startJulian, seconds); if (this._scrubElement) { var scrubX = xPos - 8; this._scrubElement.style.left = scrubX.toString() + 'px'; @@ -592,7 +592,7 @@ define([ timeline._mouseX = e.clientX; if (dx !== 0) { var dsec = dx * timeline._timeBarSecondsSpan / timeline._topDiv.clientWidth; - timeline.zoomTo(timeline._startJulian.addSeconds(dsec), timeline._endJulian.addSeconds(dsec)); + timeline.zoomTo(JulianDate.addSeconds(timeline._startJulian, dsec), JulianDate.addSeconds(timeline._endJulian, dsec)); } } else if (timeline._mouseMode === timelineMouseMode.zoom) { dx = timeline._mouseX - e.clientX; @@ -619,7 +619,7 @@ define([ e.preventDefault(); timeline._mouseMode = timelineMouseMode.touchOnly; if (len === 1) { - seconds = timeline._startJulian.getSecondsDifference(timeline._scrubJulian); + seconds = JulianDate.getSecondsDifference(timeline._startJulian, timeline._scrubJulian); xPos = Math.round(seconds * timeline._topDiv.clientWidth / timeline._timeBarSecondsSpan + leftX); if (Math.abs(e.touches[0].clientX - xPos) < 50) { timeline._touchMode = timelineTouchMode.scrub; @@ -690,14 +690,14 @@ define([ if ((newSpan > 0) && (timeline._touchState.spanX > 0)) { // Zoom and slide zoom = (timeline._touchState.spanX / newSpan); - newStartTime = timeline._startJulian.addSeconds(((timeline._touchState.centerX * timeline._timeBarSecondsSpan) - (newCenter * timeline._timeBarSecondsSpan * zoom)) / timeline._topDiv.clientWidth); + newStartTime = JulianDate.addSeconds(timeline._startJulian, ((timeline._touchState.centerX * timeline._timeBarSecondsSpan) - (newCenter * timeline._timeBarSecondsSpan * zoom)) / timeline._topDiv.clientWidth); } else { // Slide to newCenter dx = timeline._touchState.centerX - newCenter; - newStartTime = timeline._startJulian.addSeconds(dx * timeline._timeBarSecondsSpan / timeline._topDiv.clientWidth); + newStartTime = JulianDate.addSeconds(timeline._startJulian, dx * timeline._timeBarSecondsSpan / timeline._topDiv.clientWidth); } - timeline.zoomTo(newStartTime, newStartTime.addSeconds(timeline._timeBarSecondsSpan * zoom)); + timeline.zoomTo(newStartTime, JulianDate.addSeconds(newStartTime, timeline._timeBarSecondsSpan * zoom)); timeline._touchState.centerX = newCenter; timeline._touchState.spanX = newSpan; } diff --git a/Source/Widgets/Timeline/TimelineHighlightRange.js b/Source/Widgets/Timeline/TimelineHighlightRange.js index 9a93da42b46b..dd9c4c8abbe0 100644 --- a/Source/Widgets/Timeline/TimelineHighlightRange.js +++ b/Source/Widgets/Timeline/TimelineHighlightRange.js @@ -1,8 +1,10 @@ /*global define*/ define([ - '../../Core/defaultValue' + '../../Core/defaultValue', + '../../Core/JulianDate' ], function( - defaultValue) { + defaultValue, + JulianDate) { "use strict"; function TimelineHighlightRange(color, heightInPx, base) { @@ -35,9 +37,9 @@ define([ TimelineHighlightRange.prototype.render = function(renderState) { var range = ''; if (this._start && this._stop && this._color) { - var highlightStart = renderState.epochJulian.getSecondsDifference(this._start); + var highlightStart = JulianDate.getSecondsDifference(renderState.epochJulian, this._start); var highlightLeft = Math.round(renderState.timeBarWidth * renderState.getAlpha(highlightStart)); - var highlightStop = renderState.epochJulian.getSecondsDifference(this._stop); + var highlightStop = JulianDate.getSecondsDifference(renderState.epochJulian, this._stop); var highlightWidth = Math.round(renderState.timeBarWidth * renderState.getAlpha(highlightStop)) - highlightLeft; if (highlightLeft < 0) { highlightWidth += highlightLeft; diff --git a/Source/Widgets/Timeline/TimelineTrack.js b/Source/Widgets/Timeline/TimelineTrack.js index 1606e52f24c7..3b1acb11650d 100644 --- a/Source/Widgets/Timeline/TimelineTrack.js +++ b/Source/Widgets/Timeline/TimelineTrack.js @@ -1,10 +1,12 @@ /*global define*/ define([ '../../Core/Color', - '../../Core/defined' + '../../Core/defined', + '../../Core/JulianDate' ], function( Color, - defined) { + defined, + JulianDate) { "use strict"; function TimelineTrack(interval, pixelHeight, color, backgroundColor) { @@ -19,21 +21,21 @@ define([ var stopInterval = this.interval.stop; var spanStart = renderState.startJulian; - var spanStop = renderState.startJulian.addSeconds(renderState.duration); + var spanStop = JulianDate.addSeconds(renderState.startJulian, renderState.duration); - if (startInterval.lessThan(spanStart) && stopInterval.greaterThan(spanStop)) { + if (JulianDate.lessThan(startInterval, spanStart) && JulianDate.greaterThan(stopInterval, spanStop)) { //The track takes up the entire visible span. context.fillStyle = this.color.toCssColorString(); context.fillRect(0, renderState.y, renderState.timeBarWidth, this.height); - } else if (startInterval.lessThanOrEquals(spanStop) && stopInterval.greaterThanOrEquals(spanStart)) { + } else if (JulianDate.lessThanOrEquals(startInterval, spanStop) && JulianDate.greaterThanOrEquals(stopInterval, spanStart)) { //The track only takes up some of the visible span, compute that span. var x; var start, stop; for (x = 0; x < renderState.timeBarWidth; ++x) { - var currentTime = renderState.startJulian.addSeconds((x / renderState.timeBarWidth) * renderState.duration); - if (!defined(start) && currentTime.greaterThanOrEquals(startInterval)) { + var currentTime = JulianDate.addSeconds(renderState.startJulian, (x / renderState.timeBarWidth) * renderState.duration); + if (!defined(start) && JulianDate.greaterThanOrEquals(currentTime, startInterval)) { start = x; - } else if (!defined(stop) && currentTime.greaterThanOrEquals(stopInterval)) { + } else if (!defined(stop) && JulianDate.greaterThanOrEquals(currentTime, stopInterval)) { stop = x; } } diff --git a/Specs/Core/ClockSpec.js b/Specs/Core/ClockSpec.js index 1876dc10f1ac..97712a9dd000 100644 --- a/Specs/Core/ClockSpec.js +++ b/Specs/Core/ClockSpec.js @@ -14,7 +14,7 @@ defineSuite([ it('constructor sets default parameters', function() { var clock = new Clock(); - expect(clock.stopTime).toEqual(clock.startTime.addDays(1)); + expect(clock.stopTime).toEqual(JulianDate.addDays(clock.startTime, 1)); expect(clock.startTime).toEqual(clock.currentTime); expect(clock.clockStep).toEqual(ClockStep.SYSTEM_CLOCK_MULTIPLIER); expect(clock.clockRange).toEqual(ClockRange.UNBOUNDED); @@ -190,11 +190,11 @@ defineSuite([ }); expect(clock.currentTime).toEqual(currentTime); - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); }); @@ -216,11 +216,11 @@ defineSuite([ }); expect(clock.currentTime).toEqual(currentTime); - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); }); @@ -242,11 +242,11 @@ defineSuite([ }); expect(clock.currentTime).toEqual(currentTime); - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); }); @@ -268,11 +268,11 @@ defineSuite([ }); expect(clock.currentTime).toEqual(currentTime); - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); }); @@ -294,11 +294,11 @@ defineSuite([ }); expect(clock.currentTime).toEqual(currentTime); - currentTime = start.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(start, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); - currentTime = currentTime.addSeconds(multiplier); + currentTime = JulianDate.addSeconds(currentTime, multiplier); expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); }); @@ -357,7 +357,7 @@ defineSuite([ waitsFor(function() { var time2 = clock.tick(); - return time2.greaterThan(time1); + return JulianDate.greaterThan(time2, time1); }); }); @@ -401,7 +401,7 @@ defineSuite([ var time1 = clock.tick(); waitsFor(function() { var time2 = clock.tick(); - return time2.greaterThan(time1); + return JulianDate.greaterThan(time2, time1); }); }); @@ -419,7 +419,7 @@ defineSuite([ time1 = clock.tick(); waitsFor(function() { time2 = clock.tick(); - return time2.greaterThan(time1); + return JulianDate.greaterThan(time2, time1); }); clock.clockStep = ClockStep.SYSTEM_CLOCK; @@ -431,7 +431,7 @@ defineSuite([ time1 = clock.tick(); waitsFor(function() { time2 = clock.tick(); - return time2.greaterThan(time1); + return JulianDate.greaterThan(time2, time1); }); clock.clockStep = ClockStep.TICK_DEPENDENT; @@ -440,7 +440,7 @@ defineSuite([ expect(currentTime).toEqual(clock.tick()); expect(clock.currentTime).toEqual(currentTime); clock.shouldAnimate = true; - expect((clock.tick()).greaterThan(currentTime)).toEqual(true); + expect(JulianDate.greaterThan(clock.tick(), currentTime)).toEqual(true); }); }); diff --git a/Specs/Core/EarthOrientationParametersSpec.js b/Specs/Core/EarthOrientationParametersSpec.js index 084615ee15ec..5c0985dd1db9 100644 --- a/Specs/Core/EarthOrientationParametersSpec.js +++ b/Specs/Core/EarthOrientationParametersSpec.js @@ -125,7 +125,7 @@ defineSuite([ var nColumns = eopDescription.data.columnNames.length; var x0 = eopDescription.data.samples[1 * nColumns + 2]; var x1 = eopDescription.data.samples[2 * nColumns + 2]; - var dt = JulianDate.fromIso8601(eopDescription.data.samples[nColumns]).getSecondsDifference(date) / 86400.0; + var dt = JulianDate.getSecondsDifference(JulianDate.fromIso8601(eopDescription.data.samples[nColumns]), date) / 86400.0; var expected = linearInterp(dt, x0, x1); expect(result.xPoleWander).toEqualEpsilon(expected, 1e-22); x0 = eopDescription.data.samples[1 * nColumns + 3]; @@ -171,15 +171,15 @@ defineSuite([ var eop = new EarthOrientationParameters(eopDescription); var dateAtLeapSecond = JulianDate.fromIso8601("2009-01-01T00:00:00Z"); - var dateSlightlyBefore = dateAtLeapSecond.addSeconds(-1.0); - var dateSlightlyAfter = dateAtLeapSecond.addSeconds(1.0); + var dateSlightlyBefore = JulianDate.addSeconds(dateAtLeapSecond, -1.0); + var dateSlightlyAfter = JulianDate.addSeconds(dateAtLeapSecond, 1.0); var nColumns = eopDescription.data.columnNames.length; var x0 = eopDescription.data.samples[1*nColumns + 6]; var x1 = eopDescription.data.samples[2*nColumns + 6]; var x2 = eopDescription.data.samples[3*nColumns + 6]; var t0 = JulianDate.fromIso8601(eopDescription.data.samples[nColumns]); var t1 = JulianDate.fromIso8601(eopDescription.data.samples[2*nColumns]); - var dt = t0.getSecondsDifference(dateSlightlyBefore) / (86400.0 + 1); + var dt = JulianDate.getSecondsDifference(t0, dateSlightlyBefore) / (86400.0 + 1); // Adjust for leap second when interpolating var expectedBefore = linearInterp(dt, x0, (x1 - 1)); var resultBefore = eop.compute(dateSlightlyBefore); @@ -187,7 +187,7 @@ defineSuite([ var expectedAt = eopDescription.data.samples[2*nColumns + 6]; var resultAt = eop.compute(dateAtLeapSecond); expect(resultAt.ut1MinusUtc).toEqualEpsilon(expectedAt, 1.0e-15); - dt = t1.getSecondsDifference(dateSlightlyAfter) / (86400.0); + dt = JulianDate.getSecondsDifference(t1, dateSlightlyAfter) / (86400.0); var expectedAfter = linearInterp(dt, x1, x2); var resultAfter = eop.compute(dateSlightlyAfter); expect(resultAfter.ut1MinusUtc).toEqualEpsilon(expectedAfter, 1.0e-15); diff --git a/Specs/Core/JulianDateSpec.js b/Specs/Core/JulianDateSpec.js index d668c9e8b7b3..785a976ba690 100644 --- a/Specs/Core/JulianDateSpec.js +++ b/Specs/Core/JulianDateSpec.js @@ -30,8 +30,8 @@ defineSuite([ var seconds = 12.5; var timeStandard = TimeStandard.TAI; var julianDate = new JulianDate(dayNumber, seconds, timeStandard); - expect(julianDate.getJulianDayNumber()).toEqual(dayNumber); - expect(julianDate.getSecondsOfDay()).toEqual(seconds); + expect(julianDate.dayNumber).toEqual(dayNumber); + expect(julianDate.secondsOfDay).toEqual(seconds); }); it('clone works without result parameter', function() { @@ -53,22 +53,22 @@ defineSuite([ it('Construct a date from UTC components just before a leap second', function() { var expected = new JulianDate(2443874, 43216, TimeStandard.TAI); var julianDate = new JulianDate(2443874, 43199.0, TimeStandard.UTC); - expect(julianDate.getJulianDayNumber()).toEqual(expected.getJulianDayNumber()); - expect(julianDate.getSecondsOfDay()).toEqual(expected.getSecondsOfDay()); + expect(julianDate.dayNumber).toEqual(expected.dayNumber); + expect(julianDate.secondsOfDay).toEqual(expected.secondsOfDay); }); it('Construct a date from UTC components equivalent to a LeapSecond table entry', function() { var expected = new JulianDate(2443874, 43218, TimeStandard.TAI); var julianDate = new JulianDate(2443874, 43200.0, TimeStandard.UTC); - expect(julianDate.getJulianDayNumber()).toEqual(expected.getJulianDayNumber()); - expect(julianDate.getSecondsOfDay()).toEqual(expected.getSecondsOfDay()); + expect(julianDate.dayNumber).toEqual(expected.dayNumber); + expect(julianDate.secondsOfDay).toEqual(expected.secondsOfDay); }); it('Construct a date from UTC components just after a leap second', function() { var expected = new JulianDate(2443874, 43219, TimeStandard.TAI); var julianDate = new JulianDate(2443874, 43201.0, TimeStandard.UTC); - expect(julianDate.getJulianDayNumber()).toEqual(expected.getJulianDayNumber()); - expect(julianDate.getSecondsOfDay()).toEqual(expected.getSecondsOfDay()); + expect(julianDate.dayNumber).toEqual(expected.dayNumber); + expect(julianDate.secondsOfDay).toEqual(expected.secondsOfDay); }); it('Construct a date from basic components with more seconds than a day', function() { @@ -76,8 +76,8 @@ defineSuite([ var seconds = 86401; var timeStandard = TimeStandard.TAI; var julianDate = new JulianDate(dayNumber, seconds, timeStandard); - expect(julianDate.getJulianDayNumber()).toEqual(13); - expect(julianDate.getSecondsOfDay()).toEqual(1); + expect(julianDate.dayNumber).toEqual(13); + expect(julianDate.secondsOfDay).toEqual(1); }); it('Construct a date from basic components with negative seconds in a day', function() { @@ -85,8 +85,8 @@ defineSuite([ var seconds = -1; var timeStandard = TimeStandard.TAI; var julianDate = new JulianDate(dayNumber, seconds, timeStandard); - expect(julianDate.getJulianDayNumber()).toEqual(11); - expect(julianDate.getSecondsOfDay()).toEqual(86399); + expect(julianDate.dayNumber).toEqual(11); + expect(julianDate.secondsOfDay).toEqual(86399); }); it('Construct a date from basic components with partial day and seconds in a day', function() { @@ -94,8 +94,8 @@ defineSuite([ var seconds = -1; var timeStandard = TimeStandard.TAI; var julianDate = new JulianDate(dayNumber, seconds, timeStandard); - expect(julianDate.getJulianDayNumber()).toEqual(12); - expect(julianDate.getSecondsOfDay()).toEqual(43199); + expect(julianDate.dayNumber).toEqual(12); + expect(julianDate.secondsOfDay).toEqual(43199); }); it('Construct a date with default time standard', function() { @@ -179,25 +179,25 @@ defineSuite([ it('Construct a date from a JavaScript Date (1)', function() { var date = new Date('January 1, 1991 06:00:00 UTC'); var julianDate = JulianDate.fromDate(date, TimeStandard.TAI); - expect(julianDate.getTotalDays()).toEqualEpsilon(2448257.75, CesiumMath.EPSILON5); + expect(JulianDate.getTotalDays(julianDate)).toEqualEpsilon(2448257.75, CesiumMath.EPSILON5); }); it('Construct a date from a JavaScript Date (2)', function() { var date = new Date('July 4, 2011 12:00:00 UTC'); var julianDate = JulianDate.fromDate(date, TimeStandard.TAI); - expect(julianDate.getTotalDays()).toEqualEpsilon(2455747.0, CesiumMath.EPSILON5); + expect(JulianDate.getTotalDays(julianDate)).toEqualEpsilon(2455747.0, CesiumMath.EPSILON5); }); it('Construct a date from a JavaScript Date (3)', function() { var date = new Date('December 31, 2021 18:00:00 UTC'); var julianDate = JulianDate.fromDate(date, TimeStandard.TAI); - expect(julianDate.getTotalDays()).toEqualEpsilon(2459580.25, CesiumMath.EPSILON5); + expect(JulianDate.getTotalDays(julianDate)).toEqualEpsilon(2459580.25, CesiumMath.EPSILON5); }); it('Construct a date from a JavaScript Date (4)', function() { var jsDate = new Date('September 1, 2011 12:00:00 UTC'); var julianDate = JulianDate.fromDate(jsDate, TimeStandard.TAI); - expect(julianDate.getTotalDays()).toEqualEpsilon(2455806.0, CesiumMath.EPSILON5); + expect(JulianDate.getTotalDays(julianDate)).toEqualEpsilon(2455806.0, CesiumMath.EPSILON5); }); it('Construct a date from a JavaScript Date in different TimeStandard', function() { @@ -798,16 +798,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('getJulianTimeFraction works', function() { - var seconds = 12345.678; - var fraction = seconds / 86400.0; - var julianDate = new JulianDate(0, seconds, TimeStandard.TAI); - expect(julianDate.getJulianTimeFraction()).toEqualEpsilon(fraction, CesiumMath.EPSILON20); - }); - it('toDate works when constructed from total days', function() { var julianDate = JulianDate.fromTotalDays(2455770.9986087964, TimeStandard.UTC); - var javascriptDate = julianDate.toDate(); + var javascriptDate = JulianDate.toDate(julianDate); expect(javascriptDate.getUTCFullYear()).toEqual(2011); expect(javascriptDate.getUTCMonth()).toEqual(6); expect(javascriptDate.getUTCDate()).toEqual(28); @@ -819,7 +812,7 @@ defineSuite([ it('toDate works when using TAI', function() { var julianDateTai = JulianDate.fromTotalDays(2455927.157772, TimeStandard.UTC); - var javascriptDate = julianDateTai.toDate(); + var javascriptDate = JulianDate.toDate(julianDateTai); expect(javascriptDate.getUTCFullYear()).toEqual(2011); expect(javascriptDate.getUTCMonth()).toEqual(11); expect(javascriptDate.getUTCDate()).toEqual(31); @@ -831,414 +824,338 @@ defineSuite([ it('toDate works a second before a leap second', function() { var expectedDate = new Date('6/30/1997 11:59:59 PM UTC'); - var date = new JulianDate(2450630, 43229.0, TimeStandard.TAI).toDate(); + var date = JulianDate.toDate(new JulianDate(2450630, 43229.0, TimeStandard.TAI)); expect(date).toEqual(expectedDate); }); it('toDate works on a leap second', function() { var expectedDate = new Date('6/30/1997 11:59:59 PM UTC'); - var date = new JulianDate(2450630, 43230.0, TimeStandard.TAI).toDate(); + var date = JulianDate.toDate(new JulianDate(2450630, 43230.0, TimeStandard.TAI)); expect(date).toEqual(expectedDate); }); it('toDate works a second after a leap second', function() { var expectedDate = new Date('7/1/1997 12:00:00 AM UTC'); - var date = new JulianDate(2450630, 43231.0, TimeStandard.TAI).toDate(); + var date = JulianDate.toDate(new JulianDate(2450630, 43231.0, TimeStandard.TAI)); expect(date).toEqual(expectedDate); }); it('toDate works on date before any leap seconds', function() { var expectedDate = new Date('09/10/1968 12:00:00 AM UTC'); - var date = new JulianDate(2440109, 43210.0, TimeStandard.TAI).toDate(); + var date = JulianDate.toDate(new JulianDate(2440109, 43210.0, TimeStandard.TAI)); expect(date).toEqual(expectedDate); }); it('toDate works on date later than all leap seconds', function() { var expectedDate = new Date('11/17/2039 12:00:00 AM UTC'); - var date = new JulianDate(2466109, 43235.0, TimeStandard.TAI).toDate(); + var date = JulianDate.toDate(new JulianDate(2466109, 43235.0, TimeStandard.TAI)); expect(date).toEqual(expectedDate); }); it('toIso8601 works a second before a leap second', function() { var expectedDate = '1997-06-30T23:59:59Z'; - var date = JulianDate.fromIso8601(expectedDate).toIso8601(); + var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate)); expect(date).toEqual(expectedDate); }); it('toIso8601 works on a leap second', function() { var expectedDate = '1997-06-30T23:59:60Z'; - var date = JulianDate.fromIso8601(expectedDate).toIso8601(); + var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate)); expect(date).toEqual(expectedDate); }); it('toIso8601 works a second after a leap second', function() { var expectedDate = '1997-07-01T00:00:00Z'; - var date = JulianDate.fromIso8601(expectedDate).toIso8601(); + var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate)); expect(date).toEqual(expectedDate); }); it('toIso8601 works on date before any leap seconds', function() { var expectedDate = '1968-09-10T00:00:00Z'; - var date = JulianDate.fromIso8601(expectedDate).toIso8601(); + var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate)); expect(date).toEqual(expectedDate); }); it('toIso8601 works on date later than all leap seconds', function() { var expectedDate = '2031-11-17T00:00:00Z'; - var date = JulianDate.fromIso8601(expectedDate).toIso8601(); + var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate)); expect(date).toEqual(expectedDate); }); it('toIso8601 works without precision', function() { var expectedDate = '0950-01-02T03:04:05.5Z'; - var date = JulianDate.fromIso8601(expectedDate).toIso8601(); + var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate)); expect(date).toEqual(expectedDate); }); it('toIso8601 pads zeros for year less than four digits or time components less than two digits', function() { var expectedDate = '0950-01-02T03:04:05.005Z'; - var date = JulianDate.fromIso8601(expectedDate).toIso8601(3); + var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate), 3); expect(date).toEqual(expectedDate); }); it('toIso8601 does not show milliseconds if they are 0', function() { var expectedDate = '0950-01-02T03:04:05Z'; - var date = JulianDate.fromIso8601(expectedDate).toIso8601(); + var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate)); expect(date).toEqual(expectedDate); }); it('toIso8601 works with specified precision', function() { var isoDate = '0950-01-02T03:04:05.012345Z'; var date; - date = JulianDate.fromIso8601(isoDate).toIso8601(0); + date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 0); expect(date).toEqual('0950-01-02T03:04:05Z'); - date = JulianDate.fromIso8601(isoDate).toIso8601(1); + date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 1); expect(date).toEqual('0950-01-02T03:04:05.0Z'); - date = JulianDate.fromIso8601(isoDate).toIso8601(2); + date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 2); expect(date).toEqual('0950-01-02T03:04:05.01Z'); - date = JulianDate.fromIso8601(isoDate).toIso8601(3); + date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 3); expect(date).toEqual('0950-01-02T03:04:05.012Z'); - date = JulianDate.fromIso8601(isoDate).toIso8601(4); + date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 4); expect(date).toEqual('0950-01-02T03:04:05.0123Z'); - date = JulianDate.fromIso8601(isoDate).toIso8601(5); + date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 5); expect(date).toEqual('0950-01-02T03:04:05.01234Z'); - date = JulianDate.fromIso8601(isoDate).toIso8601(6); + date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 6); expect(date).toEqual('0950-01-02T03:04:05.012345Z'); - date = JulianDate.fromIso8601(isoDate).toIso8601(7); + date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 7); expect(date).toEqual('0950-01-02T03:04:05.0123450Z'); }); it('getSecondsDifference works in UTC', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); var end = JulianDate.fromDate(new Date('July 5, 2011 12:01:00 UTC')); - expect(start.getSecondsDifference(end)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); + expect(JulianDate.getSecondsDifference(start, end)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); }); it('getSecondsDifference works in TAI', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); var end = JulianDate.fromDate(new Date('July 5, 2011 12:01:00 UTC')); - expect(start.getSecondsDifference(end)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); + expect(JulianDate.getSecondsDifference(start, end)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); }); it('getSecondsDifference works with mixed time standards', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); var end = JulianDate.fromDate(new Date('July 5, 2011 12:01:00 UTC')); - expect(start.getSecondsDifference(end)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); - }); - - it('getMinutesDifference works in UTC', function() { - var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - var end = JulianDate.fromDate(new Date('July 5, 2011 12:01:00 UTC')); - expect(start.getMinutesDifference(end)).toEqualEpsilon(TimeConstants.MINUTES_PER_DAY + 1.0, CesiumMath.EPSILON5); - }); - - it('getMinutesDifference works in TAI', function() { - var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - var end = JulianDate.fromDate(new Date('July 5, 2011 12:01:00 UTC')); - expect(start.getMinutesDifference(end)).toEqualEpsilon(TimeConstants.MINUTES_PER_DAY + 1.0, CesiumMath.EPSILON5); - }); - - it('getMinutesDifference works with mixed time standards', function() { - var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - var end = JulianDate.fromDate(new Date('July 5, 2011 12:01:00 UTC')); - expect(start.getMinutesDifference(end)).toEqualEpsilon(TimeConstants.MINUTES_PER_DAY + 1.0, CesiumMath.EPSILON5); + expect(JulianDate.getSecondsDifference(start, end)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); }); it('getDaysDifference works', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); var end = JulianDate.fromDate(new Date('July 5, 2011 14:24:00')); - var difference = start.getDaysDifference(end); + var difference = JulianDate.getDaysDifference(start, end); expect(difference).toEqual(1.1); }); it('getDaysDifference works with negative result', function() { var end = JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); var start = JulianDate.fromDate(new Date('July 5, 2011 14:24:00')); - var difference = start.getDaysDifference(end); + var difference = JulianDate.getDaysDifference(start, end); expect(difference).toEqual(-1.1); }); it('addSeconds works with whole seconds', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:30 UTC')); - var end = start.addSeconds(95); - expect(end.toDate().getUTCSeconds()).toEqualEpsilon(5, CesiumMath.EPSILON5); - expect(end.toDate().getUTCMinutes()).toEqualEpsilon(2, CesiumMath.EPSILON5); + var end = JulianDate.addSeconds(start, 95); + expect(JulianDate.toDate(end).getUTCSeconds()).toEqualEpsilon(5, CesiumMath.EPSILON5); + expect(JulianDate.toDate(end).getUTCMinutes()).toEqualEpsilon(2, CesiumMath.EPSILON5); }); it('addSeconds works with fractions (1)', function() { var start = new JulianDate(2454832, 0, TimeStandard.TAI); - var end = start.addSeconds(1.5); - expect(start.getSecondsDifference(end)).toEqual(1.5); + var end = JulianDate.addSeconds(start, 1.5); + expect(JulianDate.getSecondsDifference(start, end)).toEqual(1.5); }); it('addSeconds works with fractions (2)', function() { var start = JulianDate.fromDate(new Date('August 11 2011 6:00:00 UTC')); - var end = start.addSeconds(0.5); - expect(start.getSecondsDifference(end)).toEqual(0.5); + var end = JulianDate.addSeconds(start, 0.5); + expect(JulianDate.getSecondsDifference(start, end)).toEqual(0.5); }); it('addSeconds works with fractions (3)', function() { var start = JulianDate.fromDate(new Date('August 11 2011 11:59:59 UTC')); - var end = start.addSeconds(1.25); - expect(start.getSecondsDifference(end)).toEqual(1.25); + var end = JulianDate.addSeconds(start, 1.25); + expect(JulianDate.getSecondsDifference(start, end)).toEqual(1.25); }); it('addSeconds works with negative numbers', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:01:30 UTC')); - var end = start.addSeconds(-60.0); - expect(start.getSecondsDifference(end)).toEqual(-60.0); + var end = JulianDate.addSeconds(start, -60.0); + expect(JulianDate.getSecondsDifference(start, end)).toEqual(-60.0); }); it('addSeconds works with more seconds than in a day', function() { var seconds = TimeConstants.SECONDS_PER_DAY * 7 + 15; var start = new JulianDate(2448444, 0, TimeStandard.UTC); - var end = start.addSeconds(seconds); - expect(start.getSecondsDifference(end)).toEqual(seconds); + var end = JulianDate.addSeconds(start, seconds); + expect(JulianDate.getSecondsDifference(start, end)).toEqual(seconds); }); it('addSeconds works with negative seconds more than in a day', function() { var seconds = -TimeConstants.SECONDS_PER_DAY * 7 - 15; var start = new JulianDate(2448444, 0, TimeStandard.UTC); - var end = start.addSeconds(seconds); - expect(start.getSecondsDifference(end)).toEqual(seconds); + var end = JulianDate.addSeconds(start, seconds); + expect(JulianDate.getSecondsDifference(start, end)).toEqual(seconds); }); - - it('addSeconds fails with non-numeric input', function() { - expect(function() { - return new JulianDate().addSeconds('banana'); - }).toThrowDeveloperError(); - }); - - it('addSeconds fails with null input', function() { - expect(function() { - return new JulianDate().addSeconds(null); - }).toThrowDeveloperError(); - }); - it('addSeconds fails with undefined input', function() { expect(function() { - return new JulianDate().addSeconds(undefined); + return JulianDate.addSeconds(new JulianDate(), undefined); }).toThrowDeveloperError(); }); it('addMinutes works', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - var end = start.addMinutes(65); - expect(end.toDate().getUTCMinutes()).toEqualEpsilon(5, CesiumMath.EPSILON5); - expect(end.toDate().getUTCHours()).toEqualEpsilon(13, CesiumMath.EPSILON5); + var end = JulianDate.addMinutes(start, 65); + expect(JulianDate.toDate(end).getUTCMinutes()).toEqualEpsilon(5, CesiumMath.EPSILON5); + expect(JulianDate.toDate(end).getUTCHours()).toEqualEpsilon(13, CesiumMath.EPSILON5); }); it('addMinutes works with negative numbers', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - var end = start.addMinutes(-35); - expect(end.toDate().getUTCMinutes()).toEqualEpsilon(25, CesiumMath.EPSILON5); - expect(end.toDate().getUTCHours()).toEqualEpsilon(11, CesiumMath.EPSILON5); - }); - - it('addMinutes fails with non-numeric input', function() { - expect(function() { - return new JulianDate().addMinutes('banana'); - }).toThrowDeveloperError(); - }); - - it('addMinutes fails with null input', function() { - expect(function() { - return new JulianDate().addMinutes(null); - }).toThrowDeveloperError(); + var end = JulianDate.addMinutes(start, -35); + expect(JulianDate.toDate(end).getUTCMinutes()).toEqualEpsilon(25, CesiumMath.EPSILON5); + expect(JulianDate.toDate(end).getUTCHours()).toEqualEpsilon(11, CesiumMath.EPSILON5); }); it('addMinutes fails with undefined input', function() { expect(function() { - return new JulianDate().addMinutes(undefined); + return JulianDate.addMinutes(new JulianDate(), undefined); }).toThrowDeveloperError(); }); it('addHours works', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - var end = start.addHours(6); - expect(end.toDate().getUTCHours()).toEqualEpsilon(18, CesiumMath.EPSILON5); + var end = JulianDate.addHours(start, 6); + expect(JulianDate.toDate(end).getUTCHours()).toEqualEpsilon(18, CesiumMath.EPSILON5); }); it('addHours works with negative numbers', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - var end = start.addHours(-6); - expect(end.toDate().getUTCHours()).toEqualEpsilon(6, CesiumMath.EPSILON5); - }); - - it('addHours fails with non-numeric input', function() { - expect(function() { - return new JulianDate().addHours('banana'); - }).toThrowDeveloperError(); - }); - - it('addHours fails with null input', function() { - expect(function() { - return new JulianDate().addHours(null); - }).toThrowDeveloperError(); + var end = JulianDate.addHours(start, -6); + expect(JulianDate.toDate(end).getUTCHours()).toEqualEpsilon(6, CesiumMath.EPSILON5); }); - it('addHours fails with undefined input', function() { expect(function() { - return new JulianDate().addHours(undefined); + return JulianDate.addHours(new JulianDate(), undefined); }).toThrowDeveloperError(); }); it('addDays works', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - var end = start.addDays(32); - expect(end.toDate().getUTCDate()).toEqualEpsilon(5, CesiumMath.EPSILON5); - expect(end.toDate().getUTCMonth()).toEqualEpsilon(7, CesiumMath.EPSILON5); + var end = JulianDate.addDays(start, 32); + expect(JulianDate.toDate(end).getUTCDate()).toEqualEpsilon(5, CesiumMath.EPSILON5); + expect(JulianDate.toDate(end).getUTCMonth()).toEqualEpsilon(7, CesiumMath.EPSILON5); }); it('addDays works with negative numbers', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - var end = start.addDays(-4); - expect(end.toDate().getUTCDate()).toEqualEpsilon(30, CesiumMath.EPSILON5); - expect(end.toDate().getUTCMonth()).toEqualEpsilon(5, CesiumMath.EPSILON5); - }); - - it('addDays fails with non-numeric input', function() { - expect(function() { - return new JulianDate().addDays('banana'); - }).toThrowDeveloperError(); - }); - - it('addDays fails with null input', function() { - expect(function() { - return new JulianDate().addDays(null); - }).toThrowDeveloperError(); + var end = JulianDate.addDays(start, -4); + expect(JulianDate.toDate(end).getUTCDate()).toEqualEpsilon(30, CesiumMath.EPSILON5); + expect(JulianDate.toDate(end).getUTCMonth()).toEqualEpsilon(5, CesiumMath.EPSILON5); }); it('addDays fails with undefined input', function() { expect(function() { - return new JulianDate().addDays(undefined); + return JulianDate.addDays(new JulianDate(), undefined); }).toThrowDeveloperError(); }); it('lessThan works', function() { var start = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); var end = JulianDate.fromDate(new Date('July 6, 2011 12:01:00')); - expect(start.lessThan(end)).toEqual(true); + expect(JulianDate.lessThan(start, end)).toEqual(true); }); it('lessThan works with equal values', function() { var start = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); var end = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); - expect(start.lessThan(end)).toEqual(false); - expect(start.lessThan(end.addSeconds(1))).toEqual(true); + expect(JulianDate.lessThan(start, end)).toEqual(false); + expect(JulianDate.lessThan(start, JulianDate.addSeconds(end, 1))).toEqual(true); }); it('lessThan works with different time standards', function() { var start = JulianDate.fromDate(new Date('July 6, 1991 12:00:00'), TimeStandard.UTC); var end = JulianDate.fromDate(new Date('July 6, 2011 12:00:00'), TimeStandard.TAI); - expect(start.lessThan(end)).toEqual(true); + expect(JulianDate.lessThan(start, end)).toEqual(true); }); it('lessThanOrEquals works', function() { var start = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); var end = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); - expect(start.lessThanOrEquals(end)).toEqual(true); - expect(start.addSeconds(1).lessThanOrEquals(end)).toEqual(false); - expect(start.addSeconds(-1).lessThanOrEquals(end)).toEqual(true); + expect(JulianDate.lessThanOrEquals(start, end)).toEqual(true); + expect(JulianDate.lessThanOrEquals(JulianDate.addSeconds(start, 1), end)).toEqual(false); + expect(JulianDate.lessThanOrEquals(JulianDate.addSeconds(start, -1), end)).toEqual(true); }); it('greaterThan works', function() { var start = JulianDate.fromDate(new Date('July 6, 2011 12:01:00')); var end = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); - expect(start.greaterThan(end)).toEqual(true); + expect(JulianDate.greaterThan(start, end)).toEqual(true); }); it('greaterThan works with equal values', function() { var start = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); var end = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); - expect(start.greaterThan(end)).toEqual(false); - expect(start.greaterThan(end.addSeconds(-1))).toEqual(true); + expect(JulianDate.greaterThan(start, end)).toEqual(false); + expect(JulianDate.greaterThan(start, JulianDate.addSeconds(end, -1))).toEqual(true); }); it('greaterThan works with different time standards', function() { var start = JulianDate.fromDate(new Date('July 6, 2011 12:01:00'), TimeStandard.TAI); var end = JulianDate.fromDate(new Date('July 6, 1991 12:00:00'), TimeStandard.UTC); - expect(start.greaterThan(end)).toEqual(true); + expect(JulianDate.greaterThan(start, end)).toEqual(true); }); it('greaterThanOrEquals works', function() { var start = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); var end = JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); - expect(start.greaterThanOrEquals(end)).toEqual(true); - expect(start.addSeconds(-1).greaterThanOrEquals(end)).toEqual(false); - expect(start.addSeconds(1).greaterThanOrEquals(end)).toEqual(true); + expect(JulianDate.greaterThanOrEquals(start, end)).toEqual(true); + expect(JulianDate.greaterThanOrEquals(JulianDate.addSeconds(start, -1), end)).toEqual(false); + expect(JulianDate.greaterThanOrEquals(JulianDate.addSeconds(start, 1), end)).toEqual(true); }); it('can be equal to within an epsilon of another JulianDate', function() { var original = JulianDate.fromDate(new Date('September 7, 2011 12:55:00 UTC')); var clone = JulianDate.fromDate(new Date('September 7, 2011 12:55:00 UTC')); - clone = clone.addSeconds(1); + clone = JulianDate.addSeconds(clone, 1); expect(original.equalsEpsilon(clone, 2)).toEqual(true); }); it('getTotalDays works', function() { var totalDays = 2455784.7500058; var original = JulianDate.fromTotalDays(totalDays, TimeStandard.TAI); - expect(totalDays).toEqual(original.getTotalDays()); + expect(totalDays).toEqual(JulianDate.getTotalDays(original)); }); it('equalsEpsilon works', function() { var date = new JulianDate(); - var datePlusOne = date.addSeconds(0.01); + var datePlusOne = JulianDate.addSeconds(date, 0.01); expect(date.equalsEpsilon(datePlusOne, CesiumMath.EPSILON1)).toEqual(true); }); it('getTaiMinusUtc works before all leap seconds', function() { var date = new Date('July 11, 1970 12:00:00 UTC'); var jd = JulianDate.fromDate(date, TimeStandard.TAI); - var difference = jd.getTaiMinusUtc(); + var difference = JulianDate.getTaiMinusUtc(jd); expect(difference).toEqual(10); }); it('getTaiMinusUtc works a second before a leap second', function() { var date = new JulianDate(2456109, 43233.0, TimeStandard.TAI); - expect(date.getTaiMinusUtc()).toEqual(34); + expect(JulianDate.getTaiMinusUtc(date)).toEqual(34); }); it('getTaiMinusUtc works on a leap second', function() { var date = new JulianDate(2456109, 43234.0, TimeStandard.TAI); - expect(date.getTaiMinusUtc()).toEqual(34); + expect(JulianDate.getTaiMinusUtc(date)).toEqual(34); }); it('getTaiMinusUtc works a second after a leap second', function() { var date = new JulianDate(2456109, 43235.0, TimeStandard.TAI); - expect(date.getTaiMinusUtc()).toEqual(35); + expect(JulianDate.getTaiMinusUtc(date)).toEqual(35); }); it('getTaiMinusUtc works after all leap seconds', function() { var date = new JulianDate(2556109, 43235.0, TimeStandard.TAI); - expect(date.getTaiMinusUtc()).toEqual(35); - }); - - it('can compare instances with compareTo', function() { - var date = new JulianDate(0, 0.0, TimeStandard.TAI); - var date2 = new JulianDate(1, 0.0, TimeStandard.TAI); - - expect(date.compareTo(date2)).toBeLessThan(0); - expect(date2.compareTo(date)).toBeGreaterThan(0); + expect(JulianDate.getTaiMinusUtc(date)).toEqual(35); }); }); diff --git a/Specs/Core/TimeIntervalSpec.js b/Specs/Core/TimeIntervalSpec.js index b6636aeac235..bc921e8bef13 100644 --- a/Specs/Core/TimeIntervalSpec.js +++ b/Specs/Core/TimeIntervalSpec.js @@ -14,7 +14,7 @@ defineSuite([ it('Construction correctly sets all properties.', function() { var start = new JulianDate(); - var stop = start.addDays(1); + var stop = JulianDate.addDays(start, 1); var isStartIncluded = false; var isStopIncluded = true; var data = {}; @@ -29,7 +29,7 @@ defineSuite([ it('Optional constructor parameters initialize properties to expected defaults.', function() { var start = new JulianDate(); - var stop = start.addDays(1); + var stop = JulianDate.addDays(start, 1); var interval = new TimeInterval(start, stop); expect(interval.start).toEqual(start); expect(interval.stop).toEqual(stop); diff --git a/Specs/Core/TransformsSpec.js b/Specs/Core/TransformsSpec.js index 0d3d3773b78f..b3b73f877426 100644 --- a/Specs/Core/TransformsSpec.js +++ b/Specs/Core/TransformsSpec.js @@ -138,8 +138,8 @@ defineSuite([ it('computeTemeToPseudoFixedMatrix works before noon', function() { var time = new JulianDate(); - var secondsDiff = TimeConstants.SECONDS_PER_DAY - time.getSecondsOfDay(); - time = time.addSeconds(secondsDiff); + var secondsDiff = TimeConstants.SECONDS_PER_DAY - time.secondsOfDay; + time = JulianDate.addSeconds(time, secondsDiff); var t = Transforms.computeTemeToPseudoFixedMatrix(time); @@ -151,7 +151,7 @@ defineSuite([ var t4 = Matrix4.fromRotationTranslation(t, Cartesian3.ZERO); expect(Matrix4.inverse(t4)).toEqualEpsilon(Matrix4.inverseTransformation(t4), CesiumMath.EPSILON14); - time = time.addHours(23.93447); // add one sidereal day + time = JulianDate.addHours(time, 23.93447); // add one sidereal day var u = Transforms.computeTemeToPseudoFixedMatrix(time); var tAngle = Quaternion.getAngle(Quaternion.fromRotationMatrix(t)); var uAngle = Quaternion.getAngle(Quaternion.fromRotationMatrix(u)); @@ -160,8 +160,8 @@ defineSuite([ it('computeTemeToPseudoFixedMatrix works after noon', function() { var time = new JulianDate(); - var secondsDiff = TimeConstants.SECONDS_PER_DAY - time.getSecondsOfDay(); - time = time.addSeconds(secondsDiff + TimeConstants.SECONDS_PER_DAY * 0.5); + var secondsDiff = TimeConstants.SECONDS_PER_DAY - time.secondsOfDay; + time = JulianDate.addSeconds(time, secondsDiff + TimeConstants.SECONDS_PER_DAY * 0.5); var t = Transforms.computeTemeToPseudoFixedMatrix(time); @@ -173,7 +173,7 @@ defineSuite([ var t4 = Matrix4.fromRotationTranslation(t, Cartesian3.ZERO); expect(Matrix4.inverse(t4)).toEqualEpsilon(Matrix4.inverseTransformation(t4), CesiumMath.EPSILON14); - time = time.addHours(23.93447); // add one sidereal day + time = JulianDate.addHours(time, 23.93447); // add one sidereal day var u = Transforms.computeTemeToPseudoFixedMatrix(time); var tAngle = Quaternion.getAngle(Quaternion.fromRotationMatrix(t)); var uAngle = Quaternion.getAngle(Quaternion.fromRotationMatrix(u)); @@ -182,8 +182,8 @@ defineSuite([ it('computeTemeToPseudoFixedMatrix works with a result parameter', function() { var time = new JulianDate(); - var secondsDiff = TimeConstants.SECONDS_PER_DAY - time.getSecondsOfDay(); - time = time.addSeconds(secondsDiff); + var secondsDiff = TimeConstants.SECONDS_PER_DAY - time.secondsOfDay; + time = JulianDate.addSeconds(time, secondsDiff); var resultT = new Matrix3(); var t = Transforms.computeTemeToPseudoFixedMatrix(time, resultT); @@ -197,7 +197,7 @@ defineSuite([ var t4 = Matrix4.fromRotationTranslation(t, Cartesian3.ZERO); expect(Matrix4.inverse(t4)).toEqualEpsilon(Matrix4.inverseTransformation(t4), CesiumMath.EPSILON14); - time = time.addHours(23.93447); // add one sidereal day + time = JulianDate.addHours(time, 23.93447); // add one sidereal day var resultU = new Matrix3(); var u = Transforms.computeTemeToPseudoFixedMatrix(time, resultU); expect(u).toBe(resultU); @@ -312,7 +312,7 @@ defineSuite([ var t4 = Matrix4.fromRotationTranslation(t, Cartesian3.ZERO); expect(Matrix4.inverse(t4)).toEqualEpsilon(Matrix4.inverseTransformation(t4), CesiumMath.EPSILON14); - time = time.addHours(23.93447); // add one sidereal day + time = JulianDate.addHours(time, 23.93447); // add one sidereal day var resultU = new Matrix3(); var u = Transforms.computeIcrfToFixedMatrix(time, resultU); expect(u).toBe(resultU); @@ -414,7 +414,7 @@ defineSuite([ // Purposefully do not load EOP! EOP doesn't make a lot of sense before 1972. // Even though we are trying to load the data for 1970, // we don't have the data in Cesium to load. - preloadTransformationData(time, time.addDays(1)); + preloadTransformationData(time, JulianDate.addDays(time, 1)); var resultT = new Matrix3(); var t = Transforms.computeIcrfToFixedMatrix(time, resultT); // Check that we get undefined, since we don't have ICRF data @@ -427,7 +427,7 @@ defineSuite([ // Purposefully do not load EOP! EOP doesn't exist yet that far into the future // Even though we are trying to load the data for 2030, // we don't have the data in Cesium to load. - preloadTransformationData(time, time.addDays(1)); + preloadTransformationData(time, JulianDate.addDays(time, 1)); var resultT = new Matrix3(); var t = Transforms.computeIcrfToFixedMatrix(time, resultT); // Check that we get undefined, since we don't have ICRF data diff --git a/Specs/DynamicScene/CzmlDataSourceSpec.js b/Specs/DynamicScene/CzmlDataSourceSpec.js index b2ac86a80c74..c197b0cbb137 100644 --- a/Specs/DynamicScene/CzmlDataSourceSpec.js +++ b/Specs/DynamicScene/CzmlDataSourceSpec.js @@ -163,7 +163,7 @@ defineSuite([ expect(clock.currentTime).toEqual(interval.start); expect(clock.clockRange).toEqual(ClockRange.LOOP_STOP); expect(clock.clockStep).toEqual(ClockStep.SYSTEM_CLOCK_MULTIPLIER); - expect(clock.multiplier).toEqual(interval.start.getSecondsDifference(interval.stop) / 120.0); + expect(clock.multiplier).toEqual(JulianDate.getSecondsDifference(interval.start, interval.stop) / 120.0); }); it('processUrl loads expected data', function() { @@ -512,7 +512,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(billboardPacket.billboard.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(billboardPacket); @@ -699,7 +699,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(conePacket.cone.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(conePacket); @@ -756,7 +756,7 @@ defineSuite([ var czml = { position : { - epoch : epoch.toIso8601(), + epoch : JulianDate.toIso8601(epoch), cartographicDegrees : [0, 34, 117, 10000, 1, 34, 117, 20000] } }; @@ -770,17 +770,17 @@ defineSuite([ var resultCartesian = dynamicObject.position.getValue(epoch); expect(resultCartesian).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic)); - resultCartesian = dynamicObject.position.getValue(epoch.addSeconds(1)); + resultCartesian = dynamicObject.position.getValue(JulianDate.addSeconds(epoch, 1)); expect(resultCartesian).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic2)); }); it('CZML sampled positions work without epoch.', function() { var lastDate = new JulianDate(); - var firstDate = new JulianDate(lastDate.getJulianDayNumber() - 1, 0); + var firstDate = new JulianDate(lastDate.dayNumber - 1, 0); var czml = { position : { - cartographicDegrees : [firstDate.toIso8601(), 34, 117, 10000, lastDate.toIso8601(), 34, 117, 20000] + cartographicDegrees : [JulianDate.toIso8601(firstDate), 34, 117, 10000, JulianDate.toIso8601(lastDate), 34, 117, 20000] } }; var cartographic = Cartographic.fromDegrees(34, 117, 10000); @@ -820,7 +820,7 @@ defineSuite([ var czml = { position : { referenceFrame : 'INERTIAL', - epoch : epoch.toIso8601(), + epoch : JulianDate.toIso8601(epoch), cartesian : [1.0, 2.0, 3.0] } }; @@ -832,7 +832,7 @@ defineSuite([ czml = { position : { referenceFrame : 'FIXED', - epoch : epoch.toIso8601(), + epoch : JulianDate.toIso8601(epoch), cartesian : [1.0, 2.0, 3.0] } }; @@ -849,7 +849,7 @@ defineSuite([ var czml = { position : { referenceFrame : 'INERTIAL', - epoch : epoch.toIso8601(), + epoch : JulianDate.toIso8601(epoch), cartesian : [1.0, 2.0, 3.0] } }; @@ -860,7 +860,7 @@ defineSuite([ var czml2 = { position : { - epoch : epoch.toIso8601(), + epoch : JulianDate.toIso8601(epoch), cartesian : [1.0, 2.0, 3.0] } }; @@ -874,7 +874,7 @@ defineSuite([ var czml = { position : { - epoch : epoch.toIso8601(), + epoch : JulianDate.toIso8601(epoch), cartographicRadians : [0, 2, 0.3, 10000, 1, 0.2, 0.5, 20000] } }; @@ -888,19 +888,19 @@ defineSuite([ var resultCartesian = dynamicObject.position.getValue(epoch); expect(resultCartesian).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic)); - resultCartesian = dynamicObject.position.getValue(epoch.addSeconds(1)); + resultCartesian = dynamicObject.position.getValue(JulianDate.addSeconds(epoch, 1)); expect(resultCartesian).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic2)); }); it('CZML sampled numbers work without epoch.', function() { var firstDate = Iso8601.MINIMUM_VALUE; - var midDate = firstDate.addDays(1); - var lastDate = firstDate.addDays(2); + var midDate = JulianDate.addDays(firstDate, 1); + var lastDate = JulianDate.addDays(firstDate, 2); var ellipsePacket = { ellipse : { semiMajorAxis : { - number : [firstDate.toIso8601(), 0, lastDate.toIso8601(), 10] + number : [JulianDate.toIso8601(firstDate), 0, JulianDate.toIso8601(lastDate), 10] } } }; @@ -949,7 +949,7 @@ defineSuite([ var dynamicObject = dataSource.dynamicObjects.getObjects()[0]; var validTime = TimeInterval.fromIso8601(ellipsePacketInterval.ellipse.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); expect(dynamicObject.ellipse).toBeDefined(); expect(dynamicObject.ellipse.semiMajorAxis.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.semiMajorAxis); @@ -1011,7 +1011,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(ellipsoidPacketInterval.ellipsoid.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(ellipsoidPacketInterval); @@ -1100,7 +1100,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(labelPacket.label.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(labelPacket); @@ -1337,7 +1337,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(pathPacket.path.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(pathPacket); @@ -1404,7 +1404,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(pointPacket.point.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(pointPacket); @@ -1471,7 +1471,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(polygonPacket.polygon.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(polygonPacket); @@ -1529,7 +1529,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(polylinePacket.polyline.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(polylinePacket); @@ -1634,7 +1634,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(pyramidPacket.pyramid.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(pyramidPacket); @@ -1706,7 +1706,7 @@ defineSuite([ }; var validTime = TimeInterval.fromIso8601(vectorPacket.vector.interval).start; - var invalidTime = validTime.addSeconds(-1); + var invalidTime = JulianDate.addSeconds(validTime, -1); var dataSource = new CzmlDataSource(); dataSource.load(vectorPacket); @@ -1800,13 +1800,13 @@ defineSuite([ var date = JulianDate.fromIso8601('2000-01-01'); var object = {}; - CzmlDataSource.processPacketData(JulianDate, object, 'simpleDate', date.toIso8601()); + CzmlDataSource.processPacketData(JulianDate, object, 'simpleDate', JulianDate.toIso8601(date)); expect(object.simpleDate).toBeDefined(); expect(object.simpleDate.getValue()).toEqual(date); CzmlDataSource.processPacketData(JulianDate, object, 'objDate', { - date : date.toIso8601() + date : JulianDate.toIso8601(date) }); expect(object.objDate).toBeDefined(); diff --git a/Specs/DynamicScene/DynamicObjectSpec.js b/Specs/DynamicScene/DynamicObjectSpec.js index 8d28f7af027d..b2ea9e226038 100644 --- a/Specs/DynamicScene/DynamicObjectSpec.js +++ b/Specs/DynamicScene/DynamicObjectSpec.js @@ -40,10 +40,10 @@ defineSuite([ var dynamicObject = new DynamicObject(); var interval = TimeInterval.fromIso8601('2000-01-01/2001-01-01'); dynamicObject.availability = interval; - expect(dynamicObject.isAvailable(interval.start.addSeconds(-1))).toEqual(false); + expect(dynamicObject.isAvailable(JulianDate.addSeconds(interval.start, -1))).toEqual(false); expect(dynamicObject.isAvailable(interval.start)).toEqual(true); expect(dynamicObject.isAvailable(interval.stop)).toEqual(true); - expect(dynamicObject.isAvailable(interval.stop.addSeconds(1))).toEqual(false); + expect(dynamicObject.isAvailable(JulianDate.addSeconds(interval.stop, 1))).toEqual(false); }); it('definitionChanged works for all properties', function() { diff --git a/Specs/DynamicScene/DynamicPathVisualizerSpec.js b/Specs/DynamicScene/DynamicPathVisualizerSpec.js index 1f509fc032b7..7d76529ce4c4 100644 --- a/Specs/DynamicScene/DynamicPathVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPathVisualizerSpec.js @@ -129,9 +129,9 @@ defineSuite([ var polylineCollection = scene.primitives.get(0); var primitive = polylineCollection.get(0); - expect(primitive.positions[0]).toEqual(testObject.position.getValue(updateTime.addSeconds(-path.trailTime.getValue()))); + expect(primitive.positions[0]).toEqual(testObject.position.getValue(JulianDate.addSeconds(updateTime, -path.trailTime.getValue()))); expect(primitive.positions[1]).toEqual(testObject.position.getValue(updateTime)); - expect(primitive.positions[2]).toEqual(testObject.position.getValue(updateTime.addSeconds(path.leadTime.getValue()))); + expect(primitive.positions[2]).toEqual(testObject.position.getValue(JulianDate.addSeconds(updateTime, path.leadTime.getValue()))); expect(primitive.show).toEqual(testObject.path.show.getValue(updateTime)); expect(primitive.width).toEqual(testObject.path.width.getValue(updateTime)); @@ -285,9 +285,9 @@ defineSuite([ var expectedStep = 28800; DynamicPathVisualizer._subSample(property, start, stop, updateTime, referenceFrame, maximumStep, result); expect(result).toEqual([property.getValue(start), - property.getValue(start.addSeconds(expectedStep)), + property.getValue(JulianDate.addSeconds(start, expectedStep)), property.getValue(updateTime), - property.getValue(start.addSeconds(expectedStep * 2)), + property.getValue(JulianDate.addSeconds(start, expectedStep * 2)), property.getValue(stop)]); //An maximum step size that is slightly more than halfway between points causes a single step halfway between points @@ -296,7 +296,7 @@ defineSuite([ updateTime = new JulianDate(0, 64800); DynamicPathVisualizer._subSample(property, start, stop, updateTime, referenceFrame, maximumStep, result); expect(result).toEqual([property.getValue(start), - property.getValue(start.addSeconds(expectedStep)), + property.getValue(JulianDate.addSeconds(start, expectedStep)), property.getValue(updateTime), property.getValue(stop)]); @@ -307,8 +307,8 @@ defineSuite([ DynamicPathVisualizer._subSample(property, start, stop, updateTime, referenceFrame, maximumStep, result); expect(result).toEqual([property.getValue(start), property.getValue(updateTime), - property.getValue(start.addSeconds(expectedStep)), - property.getValue(start.addSeconds(expectedStep * 2)), + property.getValue(JulianDate.addSeconds(start, expectedStep)), + property.getValue(JulianDate.addSeconds(start, expectedStep * 2)), property.getValue(stop)]); }); @@ -379,13 +379,13 @@ defineSuite([ var result = []; DynamicPathVisualizer._subSample(property, t1, t4, updateTime, referenceFrame, maximumStep, result); expect(result).toEqual([sampledProperty.getValue(t1), - sampledProperty.getValue(t1.addSeconds(maximumStep)), - sampledProperty.getValue(t1.addSeconds(maximumStep*2)), + sampledProperty.getValue(JulianDate.addSeconds(t1, maximumStep)), + sampledProperty.getValue(JulianDate.addSeconds(t1, maximumStep*2)), sampledProperty.getValue(updateTime), - sampledProperty.getValue(t1.addSeconds(maximumStep*3)), - sampledProperty.getValue(t1.addSeconds(maximumStep*4)), - sampledProperty.getValue(t1.addSeconds(maximumStep*5)), - sampledProperty.getValue(t1.addSeconds(maximumStep*6))]); + sampledProperty.getValue(JulianDate.addSeconds(t1, maximumStep*3)), + sampledProperty.getValue(JulianDate.addSeconds(t1, maximumStep*4)), + sampledProperty.getValue(JulianDate.addSeconds(t1, maximumStep*5)), + sampledProperty.getValue(JulianDate.addSeconds(t1, maximumStep*6))]); }); it('subSample works for composite properties', function() { @@ -420,7 +420,7 @@ defineSuite([ expect(result).toEqual([intervalProperty.intervals.get(0).data, constantProperty.getValue(t1), sampledProperty.getValue(t3), - sampledProperty.getValue(t3.addSeconds(maximumStep)), + sampledProperty.getValue(JulianDate.addSeconds(t3, maximumStep)), sampledProperty.getValue(t4)]); }); diff --git a/Specs/DynamicScene/SampledPositionPropertySpec.js b/Specs/DynamicScene/SampledPositionPropertySpec.js index 92e664fc59b0..515a722da87b 100644 --- a/Specs/DynamicScene/SampledPositionPropertySpec.js +++ b/Specs/DynamicScene/SampledPositionPropertySpec.js @@ -190,7 +190,7 @@ defineSuite([ property.addSample(time, value); expect(property.getValue(time)).toEqual(value); - expect(property.getValue(time.addSeconds(4))).toBeUndefined(); + expect(property.getValue(JulianDate.addSeconds(time, 4))).toBeUndefined(); }); it('throws with no time parameter', function() { diff --git a/Specs/DynamicScene/SampledPropertySpec.js b/Specs/DynamicScene/SampledPropertySpec.js index cf186648b5cd..c360f5180211 100644 --- a/Specs/DynamicScene/SampledPropertySpec.js +++ b/Specs/DynamicScene/SampledPropertySpec.js @@ -192,7 +192,7 @@ defineSuite([ property.addSample(time, value); expect(property.getValue(time)).toEqual(value); - expect(property.getValue(time.addSeconds(4))).toBeUndefined(); + expect(property.getValue(JulianDate.addSeconds(time, 4))).toBeUndefined(); }); it('mergeNewSamples works with huge data sets.', function() { @@ -207,7 +207,7 @@ defineSuite([ for ( var i = 0; i < 200000; i++) { data.push(i); data.push(i); - expectedTimes.push(epoch.addSeconds(i)); + expectedTimes.push(JulianDate.addSeconds(epoch, i)); expectedValues.push(i); } @@ -225,7 +225,7 @@ defineSuite([ var newData = [0, 'a', 1, 'b', 2, 'c']; var newData2 = [3, 'd', 4, 'e', 5, 'f']; - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4), epoch.addSeconds(5)]; + var expectedTimes = [JulianDate.addSeconds(epoch, 0), JulianDate.addSeconds(epoch, 1), JulianDate.addSeconds(epoch, 2), JulianDate.addSeconds(epoch, 3), JulianDate.addSeconds(epoch, 4), JulianDate.addSeconds(epoch, 5)]; var expectedValues = ['a', 'b', 'c', 'd', 'e', 'f']; SampledProperty._mergeNewSamples(epoch, times, values, newData, 1); @@ -243,7 +243,7 @@ defineSuite([ var newData = ['2010-01-01T12:00:00', 'a', '2010-01-01T12:00:01', 'b', '2010-01-01T12:00:02', 'c']; var newData2 = ['2010-01-01T12:00:03', 'd', '2010-01-01T12:00:04', 'e', '2010-01-01T12:00:05', 'f']; - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4), epoch.addSeconds(5)]; + var expectedTimes = [JulianDate.addSeconds(epoch, 0), JulianDate.addSeconds(epoch, 1), JulianDate.addSeconds(epoch, 2), JulianDate.addSeconds(epoch, 3), JulianDate.addSeconds(epoch, 4), JulianDate.addSeconds(epoch, 5)]; var expectedValues = ['a', 'b', 'c', 'd', 'e', 'f']; SampledProperty._mergeNewSamples(undefined, times, values, newData, 1); @@ -261,7 +261,7 @@ defineSuite([ var newData = [1, 'b', 'b', 4, 'e', 'e', 0, 'a', 'a']; var newData2 = [2, 'c', 'c', 3, 'd', 'd']; - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4)]; + var expectedTimes = [JulianDate.addSeconds(epoch, 0), JulianDate.addSeconds(epoch, 1), JulianDate.addSeconds(epoch, 2), JulianDate.addSeconds(epoch, 3), JulianDate.addSeconds(epoch, 4)]; var expectedValues = ['a', 'a', 'b', 'b', 'c', 'c', 'd', 'd', 'e', 'e']; SampledProperty._mergeNewSamples(epoch, times, values, newData, 2); @@ -279,7 +279,7 @@ defineSuite([ var newData = [1, 'b', 4, 'e', 0, 'a']; var newData2 = [5, 'f', 2, 'c', 3, 'd']; - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4), epoch.addSeconds(5)]; + var expectedTimes = [JulianDate.addSeconds(epoch, 0), JulianDate.addSeconds(epoch, 1), JulianDate.addSeconds(epoch, 2), JulianDate.addSeconds(epoch, 3), JulianDate.addSeconds(epoch, 4), JulianDate.addSeconds(epoch, 5)]; var expectedValues = ['a', 'b', 'c', 'd', 'e', 'f']; SampledProperty._mergeNewSamples(epoch, times, values, newData, 1); @@ -295,7 +295,7 @@ defineSuite([ var epoch = new JulianDate(); var newData = [0, 'a', 1, 'b', 1, 'c', 0, 'd', 4, 'e', 5, 'f']; - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(4), epoch.addSeconds(5)]; + var expectedTimes = [JulianDate.addSeconds(epoch, 0), JulianDate.addSeconds(epoch, 1), JulianDate.addSeconds(epoch, 4), JulianDate.addSeconds(epoch, 5)]; var expectedValues = ['d', 'c', 'e', 'f']; SampledProperty._mergeNewSamples(epoch, times, values, newData, 1); diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index f56f430c23f2..18a7f5a63460 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -590,7 +590,7 @@ defineSuite([ waitsFor(function() { scene.renderForSpecs(time); - time = time.addSeconds(1.0, time); + time = JulianDate.addSeconds(time, 1.0, time); return stopped; }, 'raises animation start, update, and stop events when removeOnStop is true', 10000); @@ -626,7 +626,7 @@ defineSuite([ animBoxesModel.show = true; scene.renderForSpecs(time); // Does not fire start - scene.renderForSpecs(time.addSeconds(1.0)); + scene.renderForSpecs(JulianDate.addSeconds(time, 1.0)); expect(spyStart.calls.length).toEqual(1); @@ -650,8 +650,8 @@ defineSuite([ animBoxesModel.show = true; scene.renderForSpecs(time); - scene.renderForSpecs(time.addSeconds(1.0)); - scene.renderForSpecs(time.addSeconds(2.0)); // Does not fire update + scene.renderForSpecs(JulianDate.addSeconds(time, 1.0)); + scene.renderForSpecs(JulianDate.addSeconds(time, 2.0)); // Does not fire update expect(spyUpdate.calls.length).toEqual(2); expect(spyUpdate.calls[0].args[2]).toEqualEpsilon(0.0, CesiumMath.EPSILON14); @@ -674,8 +674,8 @@ defineSuite([ animBoxesModel.show = true; scene.renderForSpecs(time); - scene.renderForSpecs(time.addSeconds(1.0)); - scene.renderForSpecs(time.addSeconds(2.0)); + scene.renderForSpecs(JulianDate.addSeconds(time, 1.0)); + scene.renderForSpecs(JulianDate.addSeconds(time, 2.0)); expect(spyUpdate.calls.length).toEqual(3); expect(spyUpdate.calls[0].args[2]).toEqualEpsilon(0.0, CesiumMath.EPSILON14); @@ -699,9 +699,9 @@ defineSuite([ animBoxesModel.show = true; scene.renderForSpecs(time); - scene.renderForSpecs(time.addSeconds(1.0)); - scene.renderForSpecs(time.addSeconds(2.0)); - scene.renderForSpecs(time.addSeconds(3.0)); + scene.renderForSpecs(JulianDate.addSeconds(time, 1.0)); + scene.renderForSpecs(JulianDate.addSeconds(time, 2.0)); + scene.renderForSpecs(JulianDate.addSeconds(time, 3.0)); expect(spyUpdate.calls.length).toEqual(4); expect(spyUpdate.calls[0].args[2]).toEqualEpsilon(3.708, CesiumMath.EPSILON3); @@ -726,7 +726,7 @@ defineSuite([ animBoxesModel.show = true; for (var i = 0; i < 8; ++i) { - scene.renderForSpecs(time.addSeconds(i)); + scene.renderForSpecs(JulianDate.addSeconds(time, i)); } expect(spyUpdate.calls.length).toEqual(8); @@ -756,7 +756,7 @@ defineSuite([ animBoxesModel.show = true; for (var i = 0; i < 8; ++i) { - scene.renderForSpecs(time.addSeconds(i)); + scene.renderForSpecs(JulianDate.addSeconds(time, i)); } expect(spyUpdate.calls.length).toEqual(8); @@ -786,7 +786,7 @@ defineSuite([ animBoxesModel.zoomTo(); for (var i = 0; i < 4; ++i) { - var t = time.addSeconds(i); + var t = JulianDate.addSeconds(time, i); expect(scene.renderForSpecs(t)).toEqual([0, 0, 0, 255]); animBoxesModel.show = true; @@ -822,7 +822,7 @@ defineSuite([ riggedFigureModel.zoomTo(); for (var i = 0; i < 6; ++i) { - var t = time.addSeconds(0.25 * i); + var t = JulianDate.addSeconds(time, 0.25 * i); expect(scene.renderForSpecs(t)).toEqual([0, 0, 0, 255]); riggedFigureModel.show = true; diff --git a/Specs/Widgets/Animation/AnimationViewModelSpec.js b/Specs/Widgets/Animation/AnimationViewModelSpec.js index 1b0c0d966585..5e6814b2b7ae 100644 --- a/Specs/Widgets/Animation/AnimationViewModelSpec.js +++ b/Specs/Widgets/Animation/AnimationViewModelSpec.js @@ -428,36 +428,36 @@ defineSuite([ //UNBOUNDED but available when start/stop time does not include realtime clockViewModel.systemTime = new JulianDate(); clockViewModel.clockRange = ClockRange.UNBOUNDED; - clockViewModel.startTime = clockViewModel.systemTime.addSeconds(-60); - clockViewModel.stopTime = clockViewModel.systemTime.addSeconds(-30); + clockViewModel.startTime = JulianDate.addSeconds(clockViewModel.systemTime, -60); + clockViewModel.stopTime = JulianDate.addSeconds(clockViewModel.systemTime, -30); expect(viewModel.playRealtimeViewModel.command.canExecute).toEqual(true); expect(viewModel.playRealtimeViewModel.tooltip).toEqual('Today (real-time)'); //CLAMPED but unavailable when start/stop time does not include realtime clockViewModel.clockRange = ClockRange.CLAMPED; - clockViewModel.startTime = clockViewModel.systemTime.addSeconds(-60); - clockViewModel.stopTime = clockViewModel.systemTime.addSeconds(-30); + clockViewModel.startTime = JulianDate.addSeconds(clockViewModel.systemTime, -60); + clockViewModel.stopTime = JulianDate.addSeconds(clockViewModel.systemTime, -30); expect(viewModel.playRealtimeViewModel.command.canExecute).toEqual(false); expect(viewModel.playRealtimeViewModel.tooltip).toEqual('Current time not in range'); //CLAMPED but available when start/stop time includes realtime clockViewModel.clockRange = ClockRange.CLAMPED; - clockViewModel.startTime = clockViewModel.systemTime.addSeconds(-60); - clockViewModel.stopTime = clockViewModel.systemTime.addSeconds(60); + clockViewModel.startTime = JulianDate.addSeconds(clockViewModel.systemTime, -60); + clockViewModel.stopTime = JulianDate.addSeconds(clockViewModel.systemTime, 60); expect(viewModel.playRealtimeViewModel.command.canExecute).toEqual(true); expect(viewModel.playRealtimeViewModel.tooltip).toEqual('Today (real-time)'); //LOOP_STOP but unavailable when start/stop time does not include realtime clockViewModel.clockRange = ClockRange.LOOP_STOP; - clockViewModel.startTime = clockViewModel.systemTime.addSeconds(-60); - clockViewModel.stopTime = clockViewModel.systemTime.addSeconds(-30); + clockViewModel.startTime = JulianDate.addSeconds(clockViewModel.systemTime, -60); + clockViewModel.stopTime = JulianDate.addSeconds(clockViewModel.systemTime, -30); expect(viewModel.playRealtimeViewModel.command.canExecute).toEqual(false); expect(viewModel.playRealtimeViewModel.tooltip).toEqual('Current time not in range'); //LOOP_STOP but available when start/stop time includes realtime clockViewModel.clockRange = ClockRange.LOOP_STOP; - clockViewModel.startTime = clockViewModel.systemTime.addSeconds(-60); - clockViewModel.stopTime = clockViewModel.systemTime.addSeconds(60); + clockViewModel.startTime = JulianDate.addSeconds(clockViewModel.systemTime, -60); + clockViewModel.stopTime = JulianDate.addSeconds(clockViewModel.systemTime, 60); expect(viewModel.playRealtimeViewModel.command.canExecute).toEqual(true); expect(viewModel.playRealtimeViewModel.tooltip).toEqual('Today (real-time)'); }); From 7a7423f88750ccc2899a7d7747ba577589adb363 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Tue, 10 Jun 2014 10:35:39 -0400 Subject: [PATCH 02/11] Ongoing JulianDate refactoring Default constructing a JulianDate no longer creates an instance set to the current time; I added JulianDate.now() for this purpose. --- Apps/TimelineDemo/TimelineDemo.js | 2 +- Source/Core/Clock.js | 4 +- Source/Core/GregorianDate.js | 23 +- Source/Core/Iau2000Orientation.js | 4 +- Source/Core/IauOrientationAxes.js | 2 +- Source/Core/JulianDate.js | 207 ++++++++---------- Source/Core/Simon1994PlanetaryPositions.js | 4 +- Source/Scene/ModelAnimationCollection.js | 2 +- Source/Scene/Scene.js | 4 +- Source/Widgets/ClockViewModel.js | 4 +- Specs/Core/JulianDateSpec.js | 122 ++--------- Specs/Core/LeapSecondSpec.js | 4 +- Specs/Core/TimeIntervalSpec.js | 8 +- Specs/Core/TransformsSpec.js | 6 +- .../DynamicScene/ColorMaterialPropertySpec.js | 4 +- .../CompositeDynamicObjectCollectionSpec.js | 6 +- .../CompositeMaterialPropertySpec.js | 4 +- .../CompositePositionPropertySpec.js | 4 +- Specs/DynamicScene/CompositePropertySpec.js | 2 +- .../ConstantPositionPropertySpec.js | 2 +- Specs/DynamicScene/ConstantPropertySpec.js | 2 +- Specs/DynamicScene/CzmlDataSourceSpec.js | 24 +- .../DynamicBillboardVisualizerSpec.js | 12 +- Specs/DynamicScene/DynamicClockSpec.js | 24 +- ...amicConeVisualizerUsingCustomSensorSpec.js | 16 +- .../DynamicLabelVisualizerSpec.js | 12 +- .../DynamicModelVisualizerSpec.js | 10 +- Specs/DynamicScene/DynamicObjectSpec.js | 2 +- Specs/DynamicScene/DynamicObjectViewSpec.js | 8 +- .../DynamicScene/DynamicPathVisualizerSpec.js | 4 +- .../DynamicPointVisualizerSpec.js | 10 +- .../DynamicPyramidVisualizerSpec.js | 12 +- .../DynamicVectorVisualizerSpec.js | 10 +- .../EllipseGeometryUpdaterSpec.js | 2 +- .../EllipsoidGeometryUpdaterSpec.js | 2 +- Specs/DynamicScene/GeometryVisualizerSpec.js | 2 +- .../DynamicScene/GridMaterialPropertySpec.js | 14 +- .../DynamicScene/ImageMaterialPropertySpec.js | 4 +- .../PolygonGeometryUpdaterSpec.js | 2 +- .../PolylineGeometryUpdaterSpec.js | 2 +- .../PolylineGlowMaterialPropertySpec.js | 4 +- .../PolylineOutlineMaterialPropertySpec.js | 4 +- .../DynamicScene/PositionPropertyArraySpec.js | 2 +- Specs/DynamicScene/PropertyArraySpec.js | 2 +- .../RectangleGeometryUpdaterSpec.js | 2 +- Specs/DynamicScene/ReferencePropertySpec.js | 2 +- .../SampledPositionPropertySpec.js | 14 +- Specs/DynamicScene/SampledPropertySpec.js | 12 +- .../StripeMaterialPropertySpec.js | 4 +- ...eIntervalCollectionPositionPropertySpec.js | 4 +- .../TimeIntervalCollectionPropertySpec.js | 2 +- .../Animation/AnimationViewModelSpec.js | 2 +- 52 files changed, 264 insertions(+), 382 deletions(-) diff --git a/Apps/TimelineDemo/TimelineDemo.js b/Apps/TimelineDemo/TimelineDemo.js index 2a99c32c954a..545b46906d4c 100644 --- a/Apps/TimelineDemo/TimelineDemo.js +++ b/Apps/TimelineDemo/TimelineDemo.js @@ -214,7 +214,7 @@ define([ dijit.byId('startTimeSel').set('value', 'T00:00:00'); dijit.byId('endTimeSel').set('value', 'T24:00:00'); - var today = new JulianDate(); + var today = JulianDate.now(); var tomorrow = JulianDate.addDays(today, 1); dijit.byId('startCal').set('value', JulianDate.toDate(today)); dijit.byId('endCal').set('value', JulianDate.toDate(tomorrow)); diff --git a/Source/Core/Clock.js b/Source/Core/Clock.js index dd0fa63199c9..166c936c14bc 100644 --- a/Source/Core/Clock.js +++ b/Source/Core/Clock.js @@ -64,7 +64,7 @@ define([ var currentTimeUndefined = !defined(currentTime); if (startTimeUndefined && stopTimeUndefined && currentTimeUndefined) { - currentTime = new JulianDate(); + currentTime = JulianDate.now(); startTime = JulianDate.clone(currentTime); stopTime = JulianDate.addDays(currentTime, 1.0); } else if (startTimeUndefined && stopTimeUndefined) { @@ -172,7 +172,7 @@ define([ if (this.canAnimate && this.shouldAnimate) { if (this.clockStep === ClockStep.SYSTEM_CLOCK) { - currentTime = new JulianDate(); + currentTime = JulianDate.now(); } else { if (this.clockStep === ClockStep.TICK_DEPENDENT) { currentTime = JulianDate.addSeconds(currentTime, multiplier); diff --git a/Source/Core/GregorianDate.js b/Source/Core/GregorianDate.js index 3475dc0bc302..ad2f0a90fe0c 100644 --- a/Source/Core/GregorianDate.js +++ b/Source/Core/GregorianDate.js @@ -3,50 +3,51 @@ define(function() { "use strict"; /** - * The object returned by {@link JulianDate#toGregorianDate}. - * + * Represents a Gregorian date in a more precise format than the JavaScript Date object. + * In addition to submillisecond precision, this object can also represent leap seconds. * @alias GregorianDate - * @see JulianDate#toGregorianDate * @constructor + * + * @see JulianDate#toGregorianDate */ var GregorianDate = function(year, month, day, hour, minute, second, millisecond, isLeapSecond) { /** - * The year, a whole number. + * Gets or sets the year as a whole number. * @type {Number} */ this.year = year; /** - * The month, a whole number with range [1, 12]. + * Gets or sets the month as a whole number with range [1, 12]. * @type {Number} */ this.month = month; /** - * The day, a whole number with range 1. + * Gets or sets the day of the month as a whole number starting at 1. * @type {Number} */ this.day = day; /** - * The hour, a whole number with range [0, 23]. + * Gets or sets the hour as a whole number with range [0, 23]. * @type {Number} */ this.hour = hour; /** - * The minute, a whole number with range [0, 59]. + * Gets or sets the minute of the hour as a whole number with range [0, 59]. * @type {Number} */ this.minute = minute; /** - * The second, a whole number with range [0, 60], with 60 representing a leap second. + * Gets or sets the second of the minute as a whole number with range [0, 60], with 60 representing a leap second. * @type {Number} */ this.second = second; /** - * The millisecond, a floating point number with range [0.0, 1000.0). + * Gets or sets the millisecond of the second as a floating point number with range [0.0, 1000.0). * @type {Number} */ this.millisecond = millisecond; /** - * True if this date is during a leap second. + * Gets or sets whether this time is during a leap second. * @type {Boolean} */ this.isLeapSecond = isLeapSecond; diff --git a/Source/Core/Iau2000Orientation.js b/Source/Core/Iau2000Orientation.js index 109bed56540b..dbc92f5337e7 100644 --- a/Source/Core/Iau2000Orientation.js +++ b/Source/Core/Iau2000Orientation.js @@ -43,13 +43,13 @@ define([ /** * Compute the orientation parameters for the Moon. * - * @param {JulianDate} [date=new JulianDate()] The date to evaluate the parameters. + * @param {JulianDate} [date=JulianDate.now()] The date to evaluate the parameters. * @param {IauOrientationParameters} [result] The object onto which to store the result. * @returns {IauOrientationParameters} The modified result parameter or a new instance representing the orientation of the Earth's Moon. */ Iau2000Orientation.ComputeMoon = function(date, result) { if (!defined(date)) { - date = new JulianDate(); + date = JulianDate.now(); } var dateTT = JulianDate.addSeconds(date, TdtMinusTai); diff --git a/Source/Core/IauOrientationAxes.js b/Source/Core/IauOrientationAxes.js index 2960eeb64582..96caf82271e2 100644 --- a/Source/Core/IauOrientationAxes.js +++ b/Source/Core/IauOrientationAxes.js @@ -83,7 +83,7 @@ define([ */ IauOrientationAxes.prototype.evaluate = function(date, result) { if (!defined(date)) { - date = new JulianDate(); + date = JulianDate.now(); } var alphaDeltaW = this._computeFunction(date); diff --git a/Source/Core/JulianDate.js b/Source/Core/JulianDate.js index 6c8c604f6741..79feab01e08a 100644 --- a/Source/Core/JulianDate.js +++ b/Source/Core/JulianDate.js @@ -167,76 +167,38 @@ define([ var iso8601ErrorMessage = 'Valid ISO 8601 date string required.'; /** - * Constructs a JulianDate instance from a Julian day number, the number of seconds elapsed - * into that day, and the time standard which the parameters are in. Passing no parameters will - * construct a JulianDate that represents the current system time. - * - * An astronomical Julian date is the number of days since noon on January 1, -4712 (4713 BC). + * Represents an astronomical Julian date, which is the number of days since noon on January 1, -4712 (4713 BC). * For increased precision, this class stores the whole number part of the date and the seconds * part of the date in separate components. In order to be safe for arithmetic and represent * leap seconds, the date is always stored in the International Atomic Time standard * {@link TimeStandard.TAI}. - * * @alias JulianDate * @constructor - * @immutable * * @param {Number} julianDayNumber The Julian Day Number representing the number of whole days. Fractional days will also be handled correctly. * @param {Number} julianSecondsOfDay The number of seconds into the current Julian Day Number. Fractional seconds, negative seconds and seconds greater than a day will be handled correctly. * @param {TimeStandard} [timeStandard=TimeStandard.UTC] The time standard in which the first two parameters are defined. - * - * @exception {DeveloperError} timeStandard is not a known TimeStandard. - * - * @see JulianDate.fromDate - * @see JulianDate.fromTotalDays - * @see JulianDate.fromIso8601 - * @see TimeStandard - * @see LeapSecond - * - * @example - * // Example 1. Construct a JulianDate representing the current system time. - * var julianDate = new Cesium.JulianDate(); - * - * @example - * // Example 2. Construct a JulianDate from a Julian day number and seconds of the day. - * var julianDayNumber = 2448257; // January 1, 1991 - * var secondsOfDay = 21600; // 06:00:00 - * var julianDate = new Cesium.JulianDate(julianDayNumber, secondsOfDay, Cesium.TimeStandard.UTC); */ var JulianDate = function(julianDayNumber, julianSecondsOfDay, timeStandard) { + /** + * Gets or sets the number of whole days. + * @type {Number} + */ this.dayNumber = undefined; - this.secondsOfDay = undefined; - var wholeDays; - var secondsOfDay; - //If any of the properties are defined, then we are constructing from components. - if (defined(julianDayNumber) || defined(julianSecondsOfDay) || defined(timeStandard)) { - timeStandard = defaultValue(timeStandard, TimeStandard.UTC); + /** + * Gets or sets the number of seconds into the current day. + * @type {Number} + */ + this.secondsOfDay = undefined; - //>>includeStart('debug', pragmas.debug); - if (timeStandard !== TimeStandard.UTC && timeStandard !== TimeStandard.TAI) { - throw new DeveloperError('timeStandard is not a known TimeStandard.'); - } - if (julianDayNumber === null || isNaN(julianDayNumber)) { - throw new DeveloperError('julianDayNumber is required.'); - } - if (julianSecondsOfDay === null || isNaN(julianSecondsOfDay)) { - throw new DeveloperError('julianSecondsOfDay is required.'); - } - //>>includeEnd('debug'); + julianDayNumber = defaultValue(julianDayNumber, 0.0); + julianSecondsOfDay = defaultValue(julianSecondsOfDay, 0.0); + timeStandard = defaultValue(timeStandard, TimeStandard.UTC); - //coerce to integer - wholeDays = julianDayNumber | 0; - //If julianDayNumber was fractional, add the number of seconds the fraction represented - secondsOfDay = julianSecondsOfDay + (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY; - } else { - //Create a new date from the current time. - var date = new Date(); - var components = computeJulianDateComponentsFromDate(date); - wholeDays = components[0]; - secondsOfDay = components[1]; - timeStandard = TimeStandard.UTC; - } + //If julianDayNumber was fractional, make it an integer and add the number of seconds the fraction represented + var wholeDays = julianDayNumber | 0; + var secondsOfDay = julianSecondsOfDay + (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY; setComponents(wholeDays, secondsOfDay, this); @@ -245,42 +207,17 @@ define([ } }; - /** - * Duplicates a JulianDate instance. - * - * @param {Cartesian3} date The JulianDate to duplicate. - * @param {Cartesian3} [result] The object onto which to store the JulianDate. - * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. (Returns undefined if date is undefined) - */ - JulianDate.clone = function(date, result) { - if (!defined(date)) { - return undefined; - } - if (!defined(result)) { - return new JulianDate(date.dayNumber, date.secondsOfDay, TimeStandard.TAI); - } - result.dayNumber = date.dayNumber; - result.secondsOfDay = date.secondsOfDay; - return result; - }; - /** * Creates a JulianDate instance from a JavaScript Date object. * While the JavaScript Date object defaults to the system's local time zone, * the JulianDate is computed using the UTC values. * * @param {Date} date The JavaScript Date object representing the time to be converted to a JulianDate. - * @param {TimeStandard} [timeStandard=TimeStandard.UTC] Indicates the time standard in which this JulianDate is represented. + * @param {TimeStandard} [timeStandard=TimeStandard.UTC] Indicates the time standard in which this date is represented. * @returns {JulianDate} The new {@Link JulianDate} instance. * * @exception {DeveloperError} date must be a valid JavaScript Date. * - * @see JulianDate - * @see JulianDate.fromTotalDays - * @see JulianDate.fromIso8601 - * @see TimeStandard - * @see LeapSecond - * * @example * // Construct a JulianDate specifying the UTC time standard * var date = new Date('January 1, 2011 12:00:00 EST'); @@ -593,6 +530,42 @@ define([ return new JulianDate(totalDays, 0, timeStandard); }; + /** + * Creates a new instance that represents the current system time. + * This is equivalent to calling JulianDate.fromDate(new Date());. + * + * @param {JulianDate} [result] An existing instance to store the result into. + * @returns {JulianDate} The modified result parameter or a new instance if none was provided. + */ + JulianDate.now = function(result) { + var components = computeJulianDateComponentsFromDate(new Date()); + if (!defined(result)) { + return new JulianDate(components[0], components[1], TimeStandard.UTC); + } + setComponents(components[0], components[1], result); + convertUtcToTai(result); + return result; + }; + + /** + * Duplicates a JulianDate instance. + * + * @param {JulianDate} date The JulianDate to duplicate. + * @param {JulianDate} [result] The object onto which to store the JulianDate. + * @returns {JulianDate} The modified result parameter or a new JulianDate instance if one was not provided. (Returns undefined if date is undefined) + */ + JulianDate.clone = function(date, result) { + if (!defined(date)) { + return undefined; + } + if (!defined(result)) { + return new JulianDate(date.dayNumber, date.secondsOfDay, TimeStandard.TAI); + } + result.dayNumber = date.dayNumber; + result.secondsOfDay = date.secondsOfDay; + return result; + }; + /** * Compares two JulianDate instances. * @@ -602,12 +575,12 @@ define([ * a positive value if a is greater than b, * or zero if a and b are equal. */ - JulianDate.compare = function(a, b) { - var julianDayNumberDifference = a.dayNumber - b.dayNumber; + JulianDate.compare = function(left, right) { + var julianDayNumberDifference = left.dayNumber - right.dayNumber; if (julianDayNumberDifference !== 0) { return julianDayNumberDifference; } - return a.secondsOfDay - b.secondsOfDay; + return left.secondsOfDay - right.secondsOfDay; }; /** @@ -648,23 +621,13 @@ define([ return Math.abs(JulianDate.getSecondsDifference(left, right)) <= epsilon; }; - /** - * Duplicates this JulianDate. - * - * @param {Cartesian3} [result] The object onto which to store the JulianDate. - * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. - */ - JulianDate.prototype.clone = function(result) { - return JulianDate.clone(this, result); - }; - /** * Returns the total number of whole and fractional days represented by this astronomical Julian date. * * @returns {Number} The Julian date as single floating point number. */ - JulianDate.getTotalDays = function(value) { - return value.dayNumber + (value.secondsOfDay / TimeConstants.SECONDS_PER_DAY); + JulianDate.getTotalDays = function(julianDate) { + return julianDate.dayNumber + (julianDate.secondsOfDay / TimeConstants.SECONDS_PER_DAY); }; var toGregorianDateScratch = new JulianDate(0, 0, TimeStandard.TAI); @@ -674,14 +637,14 @@ define([ * * @returns {GregorianDate} A gregorian date. */ - JulianDate.toGregorianDate = function(value) { + JulianDate.toGregorianDate = function(julianDate) { var isLeapSecond = false; - var thisUtc = convertTaiToUtc(value, toGregorianDateScratch); + var thisUtc = convertTaiToUtc(julianDate, toGregorianDateScratch); if (!defined(thisUtc)) { //Conversion to UTC will fail if we are during a leap second. //If that's the case, subtract a second and convert again. //JavaScript doesn't support leap seconds, so this results in second 59 being repeated twice. - JulianDate.addSeconds(value, -1, toGregorianDateScratch); + JulianDate.addSeconds(julianDate, -1, toGregorianDateScratch); thisUtc = convertTaiToUtc(toGregorianDateScratch, toGregorianDateScratch); isLeapSecond = true; } @@ -729,12 +692,14 @@ define([ /** * Creates a JavaScript Date representation of this date in UTC. - * Javascript dates are only accurate to the nearest millisecond. + * Javascript dates are only accurate to the nearest millisecond and + * many implementation cannot represet a leap second. Consider using + * {@link JulianDate#toGregorianDate} instead. * * @returns {Date} A new JavaScript Date equivalent to this JulianDate. */ - JulianDate.toDate = function(value) { - var gDate = JulianDate.toGregorianDate(value); + JulianDate.toDate = function(julianDate) { + var gDate = JulianDate.toGregorianDate(julianDate); var second = gDate.second; if (gDate.isLeapSecond) { second -= 1; @@ -748,8 +713,8 @@ define([ * @param {Number} [precision] The number of fractional digits used to represent the seconds component. By default, the most precise representation is used. * @returns {String} An ISO8601 string represenation of this JulianDate. */ - JulianDate.toIso8601 = function(value, precision) { - var gDate = JulianDate.toGregorianDate(value); + JulianDate.toIso8601 = function(julianDate, precision) { + var gDate = JulianDate.toGregorianDate(julianDate); var millisecondStr; if (!defined(precision) && gDate.millisecond !== 0) { @@ -813,8 +778,8 @@ define([ * @see LeapSecond * @see TimeStandard */ - JulianDate.getTaiMinusUtc = function(value) { - binarySearchScratchLeapSecond.julianDate = value; + JulianDate.getTaiMinusUtc = function(julianDate) { + binarySearchScratchLeapSecond.julianDate = julianDate; var leapSeconds = LeapSecond._leapSeconds; var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, LeapSecond.compareLeapSecondDate); if (index < 0) { @@ -884,14 +849,14 @@ define([ * @param {Number} duration An integer number of hours to add or subtract. * @returns {JulianDate} A new JulianDate object */ - JulianDate.addHours = function(julianDate, value) { + JulianDate.addHours = function(julianDate, hours) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('duration is required.'); + if (!defined(hours)) { + throw new DeveloperError('hours is required.'); } //>>includeEnd('debug'); - var newSecondsOfDay = julianDate.secondsOfDay + (value * TimeConstants.SECONDS_PER_HOUR); + var newSecondsOfDay = julianDate.secondsOfDay + (hours * TimeConstants.SECONDS_PER_HOUR); return new JulianDate(julianDate.dayNumber, newSecondsOfDay, TimeStandard.TAI); }; @@ -972,15 +937,13 @@ define([ }; /** - * Compares this date to another date. + * Duplicates this JulianDate. * - * @param {JulianDate} other The other JulianDate to compare to. - * @returns {Number} A negative value if this instance is less than the other, - * a positive value if this instance is greater than the other, - * or zero if this instance and the other are equal. + * @param {JulianDate} [result] The object onto which to store the JulianDate. + * @returns {JulianDate} The modified result parameter or a new JulianDate instance if one was not provided. */ - JulianDate.prototype.compareTo = function(other) { - return JulianDate.compare(this, other); + JulianDate.prototype.clone = function(result) { + return JulianDate.clone(this, result); }; /** @@ -1021,6 +984,18 @@ define([ return JulianDate.equalsEpsilon(this, other, epsilon); }; + /** + * Compares this date to another date. + * + * @param {JulianDate} other The other JulianDate to compare to. + * @returns {Number} A negative value if this instance is less than the other, + * a positive value if this instance is greater than the other, + * or zero if this instance and the other are equal. + */ + JulianDate.prototype.compareTo = function(other) { + return JulianDate.compare(this, other); + }; + //To avoid circular dependencies, we load the default list of leap seconds //here, rather than in the LeapSecond class itself. if (LeapSecond._leapSeconds.length === 0) { diff --git a/Source/Core/Simon1994PlanetaryPositions.js b/Source/Core/Simon1994PlanetaryPositions.js index 9191d2db2992..99fb34fe3208 100644 --- a/Source/Core/Simon1994PlanetaryPositions.js +++ b/Source/Core/Simon1994PlanetaryPositions.js @@ -484,7 +484,7 @@ define([ */ Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame= function(date, result){ if (!defined(date)) { - date = new JulianDate(); + date = JulianDate.now(); } //first forward transformation translation = computeSimonEarthMoonBarycenter(date, translation); @@ -508,7 +508,7 @@ define([ */ Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame = function(date, result){ if (!defined(date)) { - date = new JulianDate(); + date = JulianDate.now(); } result = computeSimonMoon(date, result); Matrix3.multiplyByVector(axesTransformation, result, result); diff --git a/Source/Scene/ModelAnimationCollection.js b/Source/Scene/ModelAnimationCollection.js index 16bb2edfb04c..4492bf9bd7db 100644 --- a/Source/Scene/ModelAnimationCollection.js +++ b/Source/Scene/ModelAnimationCollection.js @@ -113,7 +113,7 @@ define([ * * @example * // Example 2. Add an animation and provide all properties and events - * var startTime = new JulianDate(); + * var startTime = JulianDate.now(); * * var animation = model.activeAnimations.add({ * name : 'another animation name', diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 2ef0488fb0de..f451ff3e3acf 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -450,7 +450,7 @@ define([ updateFrustums(near, far, this.farToNearRatio, numFrustums, this._frustumCommandsList); // give frameState, camera, and screen space camera controller initial state before rendering - updateFrameState(this, 0.0, new JulianDate()); + updateFrameState(this, 0.0, JulianDate.now()); this.initializeFrame(); }; @@ -1289,7 +1289,7 @@ define([ function render(scene, time) { if (!defined(time)) { - time = new JulianDate(); + time = JulianDate.now(); } scene._preRender.raiseEvent(scene, time); diff --git a/Source/Widgets/ClockViewModel.js b/Source/Widgets/ClockViewModel.js index 38488d0380b0..aa1053282ca9 100644 --- a/Source/Widgets/ClockViewModel.js +++ b/Source/Widgets/ClockViewModel.js @@ -43,7 +43,7 @@ define([ * @type {JulianDate} * @default JulianDate() */ - this.systemTime = knockout.observable(new JulianDate()); + this.systemTime = knockout.observable(JulianDate.now()); this.systemTime.equalityComparer = JulianDate.equals; knockout.track(this, ['systemTime']); @@ -223,7 +223,7 @@ define([ var canAnimate = clock.canAnimate; var shouldAnimate = clock.shouldAnimate; - this.systemTime = new JulianDate(); + this.systemTime = JulianDate.now(); this.startTime = startTime; this.stopTime = stopTime; this.currentTime = currentTime; diff --git a/Specs/Core/JulianDateSpec.js b/Specs/Core/JulianDateSpec.js index 785a976ba690..259c10bea365 100644 --- a/Specs/Core/JulianDateSpec.js +++ b/Specs/Core/JulianDateSpec.js @@ -14,13 +14,19 @@ defineSuite([ // All exact Julian Dates found using NASA's Time Conversion Tool: http://ssd.jpl.nasa.gov/tc.cgi it('Construct a default date', function() { + var defaultDate = new JulianDate(); + expect(defaultDate.dayNumber).toEqual(0); + expect(defaultDate.secondsOfDay).toEqual(10); + }); + + it('Construct a date at the current time', function() { // Default constructing a date uses 'now'. Unfortunately, // there's no way to know exactly what that time will be, so we // give ourselves a 5 second epsilon as a hack to avoid possible // race conditions. In reality, it might be better to just omit // a check in this test, since if this breaks, tons of other stuff // will as well. - var defaultDate = new JulianDate(); + var defaultDate = JulianDate.now(); var dateNow = JulianDate.fromDate(new Date()); expect(defaultDate.equalsEpsilon(dateNow, 5)).toEqual(true); }); @@ -35,7 +41,7 @@ defineSuite([ }); it('clone works without result parameter', function() { - var julianDate = new JulianDate(); + var julianDate = JulianDate.now(); var returnedResult = julianDate.clone(); expect(returnedResult).toEqual(julianDate); expect(returnedResult).toNotBe(julianDate); @@ -43,7 +49,7 @@ defineSuite([ it('clone works with result parameter', function() { var julianDate = new JulianDate(1, 2); - var result = new JulianDate(); + var result = JulianDate.now(); var returnedResult = julianDate.clone(result); expect(returnedResult).toBe(result); expect(returnedResult).toNotBe(julianDate); @@ -106,76 +112,6 @@ defineSuite([ expect(julianDateDefault).toEqual(julianDateUtc); }); - it('Fail to construct a date with invalid time standard', function() { - var dayNumber = 12; - var seconds = 12.5; - var timeStandard = 'invalid'; - expect(function() { - return new JulianDate(dayNumber, seconds, timeStandard); - }).toThrowDeveloperError(); - }); - - it('Fail to construct a date with a null time standard', function() { - var dayNumber = 12; - var seconds = 12.5; - var timeStandard = null; - expect(function() { - return new JulianDate(dayNumber, seconds, timeStandard); - }).toThrowDeveloperError(); - }); - - it('Fail to construct a date with an undefined secondsOfDay', function() { - var dayNumber = 12; - var timeStandard = TimeStandard.UTC; - expect(function() { - return new JulianDate(dayNumber, undefined, timeStandard); - }).toThrowDeveloperError(); - }); - - it('Fail to construct a date with null secondsOfDay', function() { - var dayNumber = 12; - var seconds = null; - var timeStandard = TimeStandard.UTC; - expect(function() { - return new JulianDate(dayNumber, seconds, timeStandard); - }).toThrowDeveloperError(); - }); - - it('Fail to construct a date with non-numerical secondsOfDay', function() { - var dayNumber = 12; - var seconds = 'not a number'; - var timeStandard = TimeStandard.UTC; - expect(function() { - return new JulianDate(dayNumber, seconds, timeStandard); - }).toThrowDeveloperError(); - }); - - it('Fail to construct a date with undefined day number', function() { - var seconds = 12.5; - var timeStandard = TimeStandard.UTC; - expect(function() { - return new JulianDate(undefined, seconds, timeStandard); - }).toThrowDeveloperError(); - }); - - it('Fail to construct a date with null day number', function() { - var dayNumber = null; - var seconds = 12.5; - var timeStandard = TimeStandard.UTC; - expect(function() { - return new JulianDate(dayNumber, seconds, timeStandard); - }).toThrowDeveloperError(); - }); - - it('Fail to construct a date with non-numerical day number', function() { - var dayNumber = 'not a number'; - var seconds = 12.5; - var timeStandard = TimeStandard.UTC; - expect(function() { - return new JulianDate(dayNumber, seconds, timeStandard); - }).toThrowDeveloperError(); - }); - it('Construct a date from a JavaScript Date (1)', function() { var date = new Date('January 1, 1991 06:00:00 UTC'); var julianDate = JulianDate.fromDate(date, TimeStandard.TAI); @@ -222,12 +158,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('Fail to construct from a JavaScript Date with invalid time standard', function() { - expect(function() { - return JulianDate.fromDate(new Date(), 'invalid'); - }).toThrowDeveloperError(); - }); - it('Construct a date from total days (1)', function() { var julianDate = JulianDate.fromTotalDays(2448257.75, TimeStandard.UTC); var expected = JulianDate.fromDate(new Date('January 1, 1991 06:00:00 UTC')); @@ -258,30 +188,12 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('Fail to construct from null total days', function() { - expect(function() { - return JulianDate.fromTotalDays(null, TimeStandard.UTC); - }).toThrowDeveloperError(); - }); - it('Fail to construct from undefined total days', function() { expect(function() { return JulianDate.fromTotalDays(undefined, TimeStandard.UTC); }).toThrowDeveloperError(); }); - it('Fail to construct from total days with null time standard', function() { - expect(function() { - return JulianDate.fromTotalDays(1234, null); - }).toThrowDeveloperError(); - }); - - it('Fail to construct from total days with invalid time standard', function() { - expect(function() { - return JulianDate.fromTotalDays(1234, 'invalid'); - }).toThrowDeveloperError(); - }); - it('Construct from ISO8601 local calendar date, basic format', function() { var expectedDate = JulianDate.fromDate(new Date(2009, 7, 1)); var computedDate = JulianDate.fromIso8601('20090801'); @@ -588,12 +500,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('Fails to construct an ISO8601 date from null', function() { - expect(function() { - return JulianDate.fromIso8601(null); - }).toThrowDeveloperError(); - }); - it('Fails to construct an ISO8601 from complete garbage', function() { expect(function() { return JulianDate.fromIso8601('this is not a date'); @@ -999,7 +905,7 @@ defineSuite([ }); it('addSeconds fails with undefined input', function() { expect(function() { - return JulianDate.addSeconds(new JulianDate(), undefined); + return JulianDate.addSeconds(JulianDate.now(), undefined); }).toThrowDeveloperError(); }); it('addMinutes works', function() { @@ -1018,7 +924,7 @@ defineSuite([ it('addMinutes fails with undefined input', function() { expect(function() { - return JulianDate.addMinutes(new JulianDate(), undefined); + return JulianDate.addMinutes(JulianDate.now(), undefined); }).toThrowDeveloperError(); }); @@ -1035,7 +941,7 @@ defineSuite([ }); it('addHours fails with undefined input', function() { expect(function() { - return JulianDate.addHours(new JulianDate(), undefined); + return JulianDate.addHours(JulianDate.now(), undefined); }).toThrowDeveloperError(); }); @@ -1055,7 +961,7 @@ defineSuite([ it('addDays fails with undefined input', function() { expect(function() { - return JulianDate.addDays(new JulianDate(), undefined); + return JulianDate.addDays(JulianDate.now(), undefined); }).toThrowDeveloperError(); }); @@ -1127,7 +1033,7 @@ defineSuite([ }); it('equalsEpsilon works', function() { - var date = new JulianDate(); + var date = JulianDate.now(); var datePlusOne = JulianDate.addSeconds(date, 0.01); expect(date.equalsEpsilon(datePlusOne, CesiumMath.EPSILON1)).toEqual(true); }); diff --git a/Specs/Core/LeapSecondSpec.js b/Specs/Core/LeapSecondSpec.js index b3b177e018c7..4472048115ed 100644 --- a/Specs/Core/LeapSecondSpec.js +++ b/Specs/Core/LeapSecondSpec.js @@ -20,12 +20,12 @@ defineSuite([ it('throws an exception if constructed without an offset', function() { expect(function() { - return new LeapSecond(new JulianDate()); + return new LeapSecond(JulianDate.now()); }).toThrowDeveloperError(); }); it('can get the TAI offset from UTC', function() { - var ls = new LeapSecond(new JulianDate(), 1.0); + var ls = new LeapSecond(JulianDate.now(), 1.0); expect(ls.offset).toEqual(1.0); }); diff --git a/Specs/Core/TimeIntervalSpec.js b/Specs/Core/TimeIntervalSpec.js index bc921e8bef13..8de82fcab65c 100644 --- a/Specs/Core/TimeIntervalSpec.js +++ b/Specs/Core/TimeIntervalSpec.js @@ -13,7 +13,7 @@ defineSuite([ } it('Construction correctly sets all properties.', function() { - var start = new JulianDate(); + var start = JulianDate.now(); var stop = JulianDate.addDays(start, 1); var isStartIncluded = false; var isStopIncluded = true; @@ -28,7 +28,7 @@ defineSuite([ }); it('Optional constructor parameters initialize properties to expected defaults.', function() { - var start = new JulianDate(); + var start = JulianDate.now(); var stop = JulianDate.addDays(start, 1); var interval = new TimeInterval(start, stop); expect(interval.start).toEqual(start); @@ -40,13 +40,13 @@ defineSuite([ it('throws when constructing with an undefined start', function() { expect(function() { - return new TimeInterval(undefined, new JulianDate()); + return new TimeInterval(undefined, JulianDate.now()); }).toThrowDeveloperError(); }); it('throws when constructing with an undefined stop', function() { expect(function() { - return new TimeInterval(new JulianDate()); + return new TimeInterval(JulianDate.now()); }).toThrowDeveloperError(); }); diff --git a/Specs/Core/TransformsSpec.js b/Specs/Core/TransformsSpec.js index b3b73f877426..7fde417970cd 100644 --- a/Specs/Core/TransformsSpec.js +++ b/Specs/Core/TransformsSpec.js @@ -137,7 +137,7 @@ defineSuite([ }); it('computeTemeToPseudoFixedMatrix works before noon', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var secondsDiff = TimeConstants.SECONDS_PER_DAY - time.secondsOfDay; time = JulianDate.addSeconds(time, secondsDiff); @@ -159,7 +159,7 @@ defineSuite([ }); it('computeTemeToPseudoFixedMatrix works after noon', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var secondsDiff = TimeConstants.SECONDS_PER_DAY - time.secondsOfDay; time = JulianDate.addSeconds(time, secondsDiff + TimeConstants.SECONDS_PER_DAY * 0.5); @@ -181,7 +181,7 @@ defineSuite([ }); it('computeTemeToPseudoFixedMatrix works with a result parameter', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var secondsDiff = TimeConstants.SECONDS_PER_DAY - time.secondsOfDay; time = JulianDate.addSeconds(time, secondsDiff); diff --git a/Specs/DynamicScene/ColorMaterialPropertySpec.js b/Specs/DynamicScene/ColorMaterialPropertySpec.js index dc7b81035922..754debe55426 100644 --- a/Specs/DynamicScene/ColorMaterialPropertySpec.js +++ b/Specs/DynamicScene/ColorMaterialPropertySpec.js @@ -36,7 +36,7 @@ defineSuite([ var property = new ColorMaterialProperty(); property.color = new ConstantProperty(Color.RED); - var result = property.getValue(new JulianDate()); + var result = property.getValue(JulianDate.now()); expect(result.color).toEqual(Color.RED); }); @@ -70,7 +70,7 @@ defineSuite([ var result = { color : Color.BLUE.clone() }; - var returnedResult = property.getValue(new JulianDate(), result); + var returnedResult = property.getValue(JulianDate.now(), result); expect(returnedResult).toBe(result); expect(result.color).toEqual(Color.RED); }); diff --git a/Specs/DynamicScene/CompositeDynamicObjectCollectionSpec.js b/Specs/DynamicScene/CompositeDynamicObjectCollectionSpec.js index 406352a59e51..29cc61b11bee 100644 --- a/Specs/DynamicScene/CompositeDynamicObjectCollectionSpec.js +++ b/Specs/DynamicScene/CompositeDynamicObjectCollectionSpec.js @@ -523,13 +523,13 @@ defineSuite([ composite2.addCollection(collection1); composite2.addCollection(collection2); - expect(composite1.getById(id).billboard.show.getValue(new JulianDate())).toEqual(true); - expect(composite2.getById(id).billboard.show.getValue(new JulianDate())).toEqual(false); + expect(composite1.getById(id).billboard.show.getValue(JulianDate.now())).toEqual(true); + expect(composite2.getById(id).billboard.show.getValue(JulianDate.now())).toEqual(false); // switch the billboard show for the dynamic object in collection2 to true, this should affect // composite2 but not composite1 dynamicObject2.billboard.show = new ConstantProperty(true); - expect(composite2.getById(id).billboard.show.getValue(new JulianDate())).toEqual(true); + expect(composite2.getById(id).billboard.show.getValue(JulianDate.now())).toEqual(true); expect(composite1.getById(id).billboard.show).toBe(dynamicObject1.billboard.show); expect(composite2.getById(id).billboard.show).toBe(dynamicObject2.billboard.show); diff --git a/Specs/DynamicScene/CompositeMaterialPropertySpec.js b/Specs/DynamicScene/CompositeMaterialPropertySpec.js index 0eb47e30f8ec..5a88fede0f1d 100644 --- a/Specs/DynamicScene/CompositeMaterialPropertySpec.js +++ b/Specs/DynamicScene/CompositeMaterialPropertySpec.js @@ -22,8 +22,8 @@ defineSuite([ var property = new CompositeMaterialProperty(); expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); expect(property.isConstant).toBe(true); - expect(property.getType(new JulianDate())).toBeUndefined(); - expect(property.getValue(new JulianDate())).toBeUndefined(); + expect(property.getType(JulianDate.now())).toBeUndefined(); + expect(property.getValue(JulianDate.now())).toBeUndefined(); }); it('works without a result parameter', function() { diff --git a/Specs/DynamicScene/CompositePositionPropertySpec.js b/Specs/DynamicScene/CompositePositionPropertySpec.js index 224cda07ed4a..6656b4239b73 100644 --- a/Specs/DynamicScene/CompositePositionPropertySpec.js +++ b/Specs/DynamicScene/CompositePositionPropertySpec.js @@ -23,7 +23,7 @@ defineSuite([ it('default constructor has expected values', function() { var property = new CompositePositionProperty(); expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); - expect(property.getValue(new JulianDate())).toBeUndefined(); + expect(property.getValue(JulianDate.now())).toBeUndefined(); expect(property.referenceFrame).toBe(ReferenceFrame.FIXED); expect(property.isConstant).toBe(true); }); @@ -171,7 +171,7 @@ defineSuite([ it('getValueInReferenceFrame throws with no referenceFrame parameter', function() { var property = new CompositePositionProperty(); - var time = new JulianDate(); + var time = JulianDate.now(); expect(function() { property.getValueInReferenceFrame(time, undefined); }).toThrowDeveloperError(); diff --git a/Specs/DynamicScene/CompositePropertySpec.js b/Specs/DynamicScene/CompositePropertySpec.js index 4ef9f18d12e1..7bc522823647 100644 --- a/Specs/DynamicScene/CompositePropertySpec.js +++ b/Specs/DynamicScene/CompositePropertySpec.js @@ -19,7 +19,7 @@ defineSuite([ it('default constructor has expected values', function() { var property = new CompositeProperty(); expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); - expect(property.getValue(new JulianDate())).toBeUndefined(); + expect(property.getValue(JulianDate.now())).toBeUndefined(); expect(property.isConstant).toBe(true); }); diff --git a/Specs/DynamicScene/ConstantPositionPropertySpec.js b/Specs/DynamicScene/ConstantPositionPropertySpec.js index 588dfadde331..833c97d313a0 100644 --- a/Specs/DynamicScene/ConstantPositionPropertySpec.js +++ b/Specs/DynamicScene/ConstantPositionPropertySpec.js @@ -14,7 +14,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); it('Constructor sets expected defaults', function() { var property = new ConstantPositionProperty(); diff --git a/Specs/DynamicScene/ConstantPropertySpec.js b/Specs/DynamicScene/ConstantPropertySpec.js index ea17dbdb3995..853c5bf86177 100644 --- a/Specs/DynamicScene/ConstantPropertySpec.js +++ b/Specs/DynamicScene/ConstantPropertySpec.js @@ -10,7 +10,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); it('works with basic types', function() { var expected = 5; diff --git a/Specs/DynamicScene/CzmlDataSourceSpec.js b/Specs/DynamicScene/CzmlDataSourceSpec.js index c197b0cbb137..fb19c2712d6d 100644 --- a/Specs/DynamicScene/CzmlDataSourceSpec.js +++ b/Specs/DynamicScene/CzmlDataSourceSpec.js @@ -747,12 +747,12 @@ defineSuite([ dataSource.load(czml); var dynamicObject = dataSource.dynamicObjects.getObjects()[0]; - var resultCartesian = dynamicObject.position.getValue(new JulianDate()); + var resultCartesian = dynamicObject.position.getValue(JulianDate.now()); expect(resultCartesian).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic)); }); it('CZML sampled cartographicsDegrees positions work.', function() { - var epoch = new JulianDate(); + var epoch = JulianDate.now(); var czml = { position : { @@ -775,7 +775,7 @@ defineSuite([ }); it('CZML sampled positions work without epoch.', function() { - var lastDate = new JulianDate(); + var lastDate = JulianDate.now(); var firstDate = new JulianDate(lastDate.dayNumber - 1, 0); var czml = { @@ -809,12 +809,12 @@ defineSuite([ dataSource.load(czml); var dynamicObject = dataSource.dynamicObjects.getObjects()[0]; - var resultCartesian = dynamicObject.position.getValue(new JulianDate()); + var resultCartesian = dynamicObject.position.getValue(JulianDate.now()); expect(resultCartesian).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic)); }); it('Can set reference frame', function() { - var epoch = new JulianDate(); + var epoch = JulianDate.now(); var dataSource = new CzmlDataSource(); var czml = { @@ -843,7 +843,7 @@ defineSuite([ }); it('Default reference frame on existing interval does not reset value to FIXED.', function() { - var epoch = new JulianDate(); + var epoch = JulianDate.now(); var dataSource = new CzmlDataSource(); var czml = { @@ -870,7 +870,7 @@ defineSuite([ }); it('CZML sampled cartographicRadians positions work.', function() { - var epoch = new JulianDate(); + var epoch = JulianDate.now(); var czml = { position : { @@ -1996,7 +1996,7 @@ defineSuite([ }); it('Can use constant reference properties', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var packets = [{ id : 'targetId', point : { @@ -2060,7 +2060,7 @@ defineSuite([ }); it('Can use constant reference properties for position', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var packets = [{ id : 'targetId', @@ -2085,7 +2085,7 @@ defineSuite([ }); it('Can use interval reference properties for positions', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var packets = [{ id : 'targetId', @@ -2123,7 +2123,7 @@ defineSuite([ }); it('Can reference properties before they exist.', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var packets = [{ id : 'referenceId', point : { @@ -2149,7 +2149,7 @@ defineSuite([ }); it('Can reference local properties.', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var packet = { id : 'testObject', point : { diff --git a/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js b/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js index 156d07326737..130b769f5691 100644 --- a/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js @@ -85,7 +85,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); var billboardCollection = scene.primitives.get(0); expect(billboardCollection.length).toEqual(0); }); @@ -99,7 +99,7 @@ defineSuite([ billboard.show = new ConstantProperty(true); billboard.image = new ConstantProperty('Data/Images/Blue.png'); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); var billboardCollection = scene.primitives.get(0); expect(billboardCollection.length).toEqual(0); }); @@ -113,7 +113,7 @@ defineSuite([ var billboard = testObject.billboard = new DynamicBillboard(); billboard.show = new ConstantProperty(true); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); var billboardCollection = scene.primitives.get(0); expect(billboardCollection.length).toEqual(0); }); @@ -127,7 +127,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); var billboard = testObject.billboard = new DynamicBillboard(); var bb; @@ -236,7 +236,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); var billboard = testObject.billboard = new DynamicBillboard(); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); @@ -268,7 +268,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); var billboard = testObject.billboard = new DynamicBillboard(); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); diff --git a/Specs/DynamicScene/DynamicClockSpec.js b/Specs/DynamicScene/DynamicClockSpec.js index 1193544af46b..726bdc52143d 100644 --- a/Specs/DynamicScene/DynamicClockSpec.js +++ b/Specs/DynamicScene/DynamicClockSpec.js @@ -14,9 +14,9 @@ defineSuite([ it('merge assigns unassigned properties', function() { var source = new DynamicClock(); - source.startTime = new JulianDate(); - source.stopTime = new JulianDate(); - source.currentTime = new JulianDate(); + source.startTime = JulianDate.now(); + source.stopTime = JulianDate.now(); + source.currentTime = JulianDate.now(); source.clockRange = ClockRange.CLAMPED; source.clockStep = ClockStep.TICK_DEPENDENT; source.multiplier = 1; @@ -34,16 +34,16 @@ defineSuite([ it('merge does not assign assigned properties', function() { var source = new DynamicClock(); - source.startTime = new JulianDate(); - source.stopTime = new JulianDate(); - source.currentTime = new JulianDate(); + source.startTime = JulianDate.now(); + source.stopTime = JulianDate.now(); + source.currentTime = JulianDate.now(); source.clockRange = ClockRange.CLAMPED; source.clockStep = ClockStep.TICK_DEPENDENT; source.multiplier = 1; - var startTime = new JulianDate(); - var stopTime = new JulianDate(); - var currentTime = new JulianDate(); + var startTime = JulianDate.now(); + var stopTime = JulianDate.now(); + var currentTime = JulianDate.now(); var clockRange = ClockRange.CLAMPED; var clockStep = ClockStep.TICK_DEPENDENT; var multiplier = 1; @@ -68,9 +68,9 @@ defineSuite([ it('clone works', function() { var source = new DynamicClock(); - source.startTime = new JulianDate(); - source.stopTime = new JulianDate(); - source.currentTime = new JulianDate(); + source.startTime = JulianDate.now(); + source.stopTime = JulianDate.now(); + source.currentTime = JulianDate.now(); source.clockRange = ClockRange.CLAMPED; source.clockStep = ClockStep.TICK_DEPENDENT; source.multiplier = 1; diff --git a/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js b/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js index a2667b83ee86..9f50f9a104b8 100644 --- a/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js +++ b/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js @@ -77,7 +77,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); @@ -90,7 +90,7 @@ defineSuite([ var cone = testObject.cone = new DynamicCone(); cone.maximumClockAngle = new ConstantProperty(1); cone.outerHalfAngle = new ConstantProperty(1); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); @@ -103,12 +103,12 @@ defineSuite([ var cone = testObject.cone = new DynamicCone(); cone.maximumClockAngle = new ConstantProperty(1); cone.outerHalfAngle = new ConstantProperty(1); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); it('A DynamicCone causes a ComplexConicSensor to be created and updated.', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); @@ -150,7 +150,7 @@ defineSuite([ }); it('IntersectionColor is set correctly with multiple cones.', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); @@ -179,7 +179,7 @@ defineSuite([ }); it('An empty DynamicCone causes a ComplexConicSensor to be created with CZML defaults.', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); @@ -211,7 +211,7 @@ defineSuite([ cone.maximumClockAngle = new ConstantProperty(1); cone.outerHalfAngle = new ConstantProperty(1); - var time = new JulianDate(); + var time = JulianDate.now(); expect(scene.primitives.length).toEqual(0); visualizer.update(time); expect(scene.primitives.length).toEqual(1); @@ -233,7 +233,7 @@ defineSuite([ cone.maximumClockAngle = new ConstantProperty(1); cone.outerHalfAngle = new ConstantProperty(1); - var time = new JulianDate(); + var time = JulianDate.now(); visualizer.update(time); expect(scene.primitives.get(0).id).toEqual(testObject); }); diff --git a/Specs/DynamicScene/DynamicLabelVisualizerSpec.js b/Specs/DynamicScene/DynamicLabelVisualizerSpec.js index 0fa54cf8bf06..25e7dc081233 100644 --- a/Specs/DynamicScene/DynamicLabelVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicLabelVisualizerSpec.js @@ -85,7 +85,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); var labelCollection = scene.primitives.get(0); expect(labelCollection.length).toEqual(0); }); @@ -99,7 +99,7 @@ defineSuite([ label.show = new ConstantProperty(true); label.text = new ConstantProperty('lorum ipsum'); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); var labelCollection = scene.primitives.get(0); expect(labelCollection.length).toEqual(0); }); @@ -113,7 +113,7 @@ defineSuite([ var label = testObject.label = new DynamicLabel(); label.show = new ConstantProperty(true); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); var labelCollection = scene.primitives.get(0); expect(labelCollection.length).toEqual(0); }); @@ -127,7 +127,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); var label = testObject.label = new DynamicLabel(); var l; @@ -216,7 +216,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); var label = testObject.label = new DynamicLabel(); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); @@ -244,7 +244,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); var label = testObject.label = new DynamicLabel(); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); diff --git a/Specs/DynamicScene/DynamicModelVisualizerSpec.js b/Specs/DynamicScene/DynamicModelVisualizerSpec.js index 79cbbfb68931..a3f9fc4f5ebe 100644 --- a/Specs/DynamicScene/DynamicModelVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicModelVisualizerSpec.js @@ -68,7 +68,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); @@ -80,12 +80,12 @@ defineSuite([ var model = testObject.model = new DynamicModel(); model.uri = new ConstantProperty(duckUrl); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); it('A DynamicModel causes a primtive to be created and updated.', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicModelVisualizer(scene, dynamicObjectCollection); @@ -117,7 +117,7 @@ defineSuite([ var model = new DynamicModel(); model.uri = new ConstantProperty(duckUrl); - var time = new JulianDate(); + var time = JulianDate.now(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1101112)); testObject.model = model; @@ -134,7 +134,7 @@ defineSuite([ var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicModelVisualizer(scene, dynamicObjectCollection); - var time = new JulianDate(); + var time = JulianDate.now(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); var model = new DynamicModel(); testObject.model = model; diff --git a/Specs/DynamicScene/DynamicObjectSpec.js b/Specs/DynamicScene/DynamicObjectSpec.js index b2ea9e226038..e1ecb0e1ff84 100644 --- a/Specs/DynamicScene/DynamicObjectSpec.js +++ b/Specs/DynamicScene/DynamicObjectSpec.js @@ -19,7 +19,7 @@ defineSuite([ it('isAvailable is always true if no availability defined.', function() { var dynamicObject = new DynamicObject('someId'); - expect(dynamicObject.isAvailable(new JulianDate())).toEqual(true); + expect(dynamicObject.isAvailable(JulianDate.now())).toEqual(true); }); it('isAvailable throw if no time specified.', function() { diff --git a/Specs/DynamicScene/DynamicObjectViewSpec.js b/Specs/DynamicScene/DynamicObjectViewSpec.js index b01f70eef3da..e6d4938c9b5e 100644 --- a/Specs/DynamicScene/DynamicObjectViewSpec.js +++ b/Specs/DynamicScene/DynamicObjectViewSpec.js @@ -58,7 +58,7 @@ defineSuite([ it('update throws without dynamicObject property', function() { var view = new DynamicObjectView(undefined, scene); expect(function() { - view.update(new JulianDate()); + view.update(JulianDate.now()); }).toThrowDeveloperError(); }); @@ -68,7 +68,7 @@ defineSuite([ dynamicObject.position = new ConstantPositionProperty(Cartesian3.ZERO); var view = new DynamicObjectView(dynamicObject, undefined); expect(function() { - view.update(new JulianDate()); + view.update(JulianDate.now()); }).toThrowDeveloperError(); }); @@ -78,7 +78,7 @@ defineSuite([ var view = new DynamicObjectView(dynamicObject, scene); view.ellipsoid = undefined; expect(function() { - view.update(new JulianDate()); + view.update(JulianDate.now()); }).toThrowDeveloperError(); }); @@ -86,7 +86,7 @@ defineSuite([ var dynamicObject = new DynamicObject(); var view = new DynamicObjectView(dynamicObject, scene); expect(function() { - view.update(new JulianDate()); + view.update(JulianDate.now()); }).toThrowDeveloperError(); }); }, 'WebGL'); diff --git a/Specs/DynamicScene/DynamicPathVisualizerSpec.js b/Specs/DynamicScene/DynamicPathVisualizerSpec.js index 7d76529ce4c4..232b1e03f7a5 100644 --- a/Specs/DynamicScene/DynamicPathVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPathVisualizerSpec.js @@ -82,7 +82,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.position = new ConstantProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); @@ -94,7 +94,7 @@ defineSuite([ var path = testObject.path = new DynamicPath(); path.show = new ConstantProperty(true); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); diff --git a/Specs/DynamicScene/DynamicPointVisualizerSpec.js b/Specs/DynamicScene/DynamicPointVisualizerSpec.js index 0b79d9038fda..3af8c6ab090f 100644 --- a/Specs/DynamicScene/DynamicPointVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPointVisualizerSpec.js @@ -78,7 +78,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); var billboardCollection = scene.primitives.get(0); expect(billboardCollection.length).toEqual(0); }); @@ -91,13 +91,13 @@ defineSuite([ var point = testObject.point = new DynamicPoint(); point.show = new ConstantProperty(true); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); var billboardCollection = scene.primitives.get(0); expect(billboardCollection.length).toEqual(0); }); it('A DynamicPoint causes a Billboard to be created and updated.', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicPointVisualizer(scene, dynamicObjectCollection); @@ -160,7 +160,7 @@ defineSuite([ var billboardCollection = scene.primitives.get(0); expect(billboardCollection.length).toEqual(0); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var point = testObject.point = new DynamicPoint(); @@ -186,7 +186,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); var point = testObject.point = new DynamicPoint(); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); diff --git a/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js b/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js index bebdea969c1f..2af3e3462180 100644 --- a/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js @@ -79,7 +79,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); @@ -91,7 +91,7 @@ defineSuite([ testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var pyramid = testObject.pyramid = new DynamicPyramid(); pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); @@ -103,12 +103,12 @@ defineSuite([ testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var pyramid = testObject.pyramid = new DynamicPyramid(); pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(0); }); it('A DynamicPyramid causes a CustomSensor to be created and updated.', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); @@ -151,7 +151,7 @@ defineSuite([ var pyramid = testObject.pyramid = new DynamicPyramid(); pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); - var time = new JulianDate(); + var time = JulianDate.now(); expect(scene.primitives.length).toEqual(0); visualizer.update(time); expect(scene.primitives.length).toEqual(1); @@ -172,7 +172,7 @@ defineSuite([ var pyramid = testObject.pyramid = new DynamicPyramid(); pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); - var time = new JulianDate(); + var time = JulianDate.now(); visualizer.update(time); expect(scene.primitives.get(0).id).toEqual(testObject); }); diff --git a/Specs/DynamicScene/DynamicVectorVisualizerSpec.js b/Specs/DynamicScene/DynamicVectorVisualizerSpec.js index 0bf74775aa8b..dc07b5d8dc4b 100644 --- a/Specs/DynamicScene/DynamicVectorVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicVectorVisualizerSpec.js @@ -74,7 +74,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(1); var polylineCollection = scene.primitives.get(0); expect(polylineCollection.length).toEqual(0); @@ -88,14 +88,14 @@ defineSuite([ var vector = testObject.vector = new DynamicVector(); vector.show = new ConstantProperty(true); - visualizer.update(new JulianDate()); + visualizer.update(JulianDate.now()); expect(scene.primitives.length).toEqual(1); var polylineCollection = scene.primitives.get(0); expect(polylineCollection.length).toEqual(0); }); it('A DynamicVector causes a primtive to be created and updated.', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicVectorVisualizer(scene, dynamicObjectCollection); @@ -149,7 +149,7 @@ defineSuite([ visualizer = new DynamicVectorVisualizer(scene, dynamicObjectCollection); expect(scene.primitives.length).toEqual(1); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1101112)); var vector = testObject.vector = new DynamicVector(); @@ -179,7 +179,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var time = JulianDate.now(); var vector = testObject.vector = new DynamicVector(); testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1101112)); diff --git a/Specs/DynamicScene/EllipseGeometryUpdaterSpec.js b/Specs/DynamicScene/EllipseGeometryUpdaterSpec.js index 864d5fb1c994..8f86c8b465bb 100644 --- a/Specs/DynamicScene/EllipseGeometryUpdaterSpec.js +++ b/Specs/DynamicScene/EllipseGeometryUpdaterSpec.js @@ -40,7 +40,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); function createBasicEllipse() { var ellipse = new DynamicEllipse(); diff --git a/Specs/DynamicScene/EllipsoidGeometryUpdaterSpec.js b/Specs/DynamicScene/EllipsoidGeometryUpdaterSpec.js index 0d4bab89a9e3..ebfa409163d6 100644 --- a/Specs/DynamicScene/EllipsoidGeometryUpdaterSpec.js +++ b/Specs/DynamicScene/EllipsoidGeometryUpdaterSpec.js @@ -46,7 +46,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); var scene; beforeEach(function() { scene = createScene(); diff --git a/Specs/DynamicScene/GeometryVisualizerSpec.js b/Specs/DynamicScene/GeometryVisualizerSpec.js index 35072f667e15..0096dd79c0e4 100644 --- a/Specs/DynamicScene/GeometryVisualizerSpec.js +++ b/Specs/DynamicScene/GeometryVisualizerSpec.js @@ -38,7 +38,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); var scene; beforeAll(function() { diff --git a/Specs/DynamicScene/GridMaterialPropertySpec.js b/Specs/DynamicScene/GridMaterialPropertySpec.js index d68e85984937..9597e979b87c 100644 --- a/Specs/DynamicScene/GridMaterialPropertySpec.js +++ b/Specs/DynamicScene/GridMaterialPropertySpec.js @@ -46,7 +46,7 @@ defineSuite([ property.lineThickness = new ConstantProperty(new Cartesian2(2, 3)); property.lineOffset = new ConstantProperty(new Cartesian2(0.7, 0.8)); - var result = property.getValue(new JulianDate()); + var result = property.getValue(JulianDate.now()); expect(result.color).toEqual(Color.RED); expect(result.cellAlpha).toEqual(1); expect(result.lineCount).toEqual(new Cartesian2(3.4, 5.0)); @@ -108,7 +108,7 @@ defineSuite([ property.lineOffset = new ConstantProperty(new Cartesian2(0.7, 0.8)); var result = {}; - var returnedResult = property.getValue(new JulianDate(), result); + var returnedResult = property.getValue(JulianDate.now(), result); expect(result).toBe(returnedResult); expect(result.color).toEqual(Color.RED); expect(result.cellAlpha).toEqual(1.0); @@ -235,31 +235,31 @@ defineSuite([ expect(property.isConstant).toBe(true); property.color = new SampledProperty(Color); - property.color.addSample(new JulianDate(), Color.WHITE); + property.color.addSample(JulianDate.now(), Color.WHITE); expect(property.isConstant).toBe(false); property.color = undefined; expect(property.isConstant).toBe(true); property.cellAlpha = new SampledProperty(Number); - property.cellAlpha.addSample(new JulianDate(), 0); + property.cellAlpha.addSample(JulianDate.now(), 0); expect(property.isConstant).toBe(false); property.cellAlpha = undefined; expect(property.isConstant).toBe(true); property.lineCount = new SampledProperty(Number); - property.lineCount.addSample(new JulianDate(), 1); + property.lineCount.addSample(JulianDate.now(), 1); expect(property.isConstant).toBe(false); property.lineCount = undefined; expect(property.isConstant).toBe(true); property.lineThickness = new SampledProperty(Number); - property.lineThickness.addSample(new JulianDate(), 1); + property.lineThickness.addSample(JulianDate.now(), 1); expect(property.isConstant).toBe(false); property.lineThickness = undefined; expect(property.isConstant).toBe(true); property.lineOffset = new SampledProperty(Number); - property.lineOffset.addSample(new JulianDate(), 1); + property.lineOffset.addSample(JulianDate.now(), 1); expect(property.isConstant).toBe(false); }); }); \ No newline at end of file diff --git a/Specs/DynamicScene/ImageMaterialPropertySpec.js b/Specs/DynamicScene/ImageMaterialPropertySpec.js index fa39618a0bc8..d842f0d98807 100644 --- a/Specs/DynamicScene/ImageMaterialPropertySpec.js +++ b/Specs/DynamicScene/ImageMaterialPropertySpec.js @@ -30,7 +30,7 @@ defineSuite([ property.image = new ConstantProperty('http://test.invalid/image.png'); property.repeat = new ConstantProperty(new Cartesian2(2, 3)); - var result = property.getValue(new JulianDate()); + var result = property.getValue(JulianDate.now()); expect(result.image).toEqual('http://test.invalid/image.png'); expect(result.repeat).toEqual(new Cartesian2(2, 3)); }); @@ -68,7 +68,7 @@ defineSuite([ property.repeat = new ConstantProperty(new Cartesian2(2, 3)); var result = {}; - var returnedResult = property.getValue(new JulianDate(), result); + var returnedResult = property.getValue(JulianDate.now(), result); expect(result).toBe(returnedResult); expect(result.image).toEqual('http://test.invalid/image.png'); expect(result.repeat).toEqual(new Cartesian2(2, 3)); diff --git a/Specs/DynamicScene/PolygonGeometryUpdaterSpec.js b/Specs/DynamicScene/PolygonGeometryUpdaterSpec.js index e8a4b9ee34d8..637251e49a89 100644 --- a/Specs/DynamicScene/PolygonGeometryUpdaterSpec.js +++ b/Specs/DynamicScene/PolygonGeometryUpdaterSpec.js @@ -44,7 +44,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); function createBasicPolygon() { var polygon = new DynamicPolygon(); diff --git a/Specs/DynamicScene/PolylineGeometryUpdaterSpec.js b/Specs/DynamicScene/PolylineGeometryUpdaterSpec.js index 2fc0c787a2ef..60354977afb7 100644 --- a/Specs/DynamicScene/PolylineGeometryUpdaterSpec.js +++ b/Specs/DynamicScene/PolylineGeometryUpdaterSpec.js @@ -44,7 +44,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); function createBasicPolyline() { var polyline = new DynamicPolyline(); diff --git a/Specs/DynamicScene/PolylineGlowMaterialPropertySpec.js b/Specs/DynamicScene/PolylineGlowMaterialPropertySpec.js index 97b57354b889..90b0becdba1f 100644 --- a/Specs/DynamicScene/PolylineGlowMaterialPropertySpec.js +++ b/Specs/DynamicScene/PolylineGlowMaterialPropertySpec.js @@ -31,7 +31,7 @@ defineSuite([ property.color = new ConstantProperty(Color.RED); property.glowPower = new ConstantProperty(0.75); - var result = property.getValue(new JulianDate()); + var result = property.getValue(JulianDate.now()); expect(result.color).toEqual(Color.RED); expect(result.glowPower).toEqual(0.75); }); @@ -74,7 +74,7 @@ defineSuite([ color : Color.BLUE.clone(), glowPower: 0.12 }; - var returnedResult = property.getValue(new JulianDate(), result); + var returnedResult = property.getValue(JulianDate.now(), result); expect(returnedResult).toBe(result); expect(result.color).toEqual(Color.RED); expect(result.glowPower).toEqual(0.43); diff --git a/Specs/DynamicScene/PolylineOutlineMaterialPropertySpec.js b/Specs/DynamicScene/PolylineOutlineMaterialPropertySpec.js index 21bd65c74c66..8c11a86f2d70 100644 --- a/Specs/DynamicScene/PolylineOutlineMaterialPropertySpec.js +++ b/Specs/DynamicScene/PolylineOutlineMaterialPropertySpec.js @@ -31,7 +31,7 @@ defineSuite([ property.color = new ConstantProperty(Color.RED); property.outlineColor = new ConstantProperty(Color.BLUE); - var result = property.getValue(new JulianDate()); + var result = property.getValue(JulianDate.now()); expect(result.color).toEqual(Color.RED); expect(result.outlineColor).toEqual(Color.BLUE); }); @@ -72,7 +72,7 @@ defineSuite([ color : Color.YELLOW.clone(), outlineColor : Color.BROWN.clone() }; - var returnedResult = property.getValue(new JulianDate(), result); + var returnedResult = property.getValue(JulianDate.now(), result); expect(returnedResult).toBe(result); expect(result.color).toEqual(Color.RED); expect(result.outlineColor).toEqual(Color.BLUE); diff --git a/Specs/DynamicScene/PositionPropertyArraySpec.js b/Specs/DynamicScene/PositionPropertyArraySpec.js index d23b0b05e609..227e421afad9 100644 --- a/Specs/DynamicScene/PositionPropertyArraySpec.js +++ b/Specs/DynamicScene/PositionPropertyArraySpec.js @@ -16,7 +16,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); it('default constructor sets expected values', function() { var property = new PositionPropertyArray(); diff --git a/Specs/DynamicScene/PropertyArraySpec.js b/Specs/DynamicScene/PropertyArraySpec.js index 6266c6ab8f98..6e816835e944 100644 --- a/Specs/DynamicScene/PropertyArraySpec.js +++ b/Specs/DynamicScene/PropertyArraySpec.js @@ -12,7 +12,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); it('default constructor sets expected values', function() { var property = new PropertyArray(); diff --git a/Specs/DynamicScene/RectangleGeometryUpdaterSpec.js b/Specs/DynamicScene/RectangleGeometryUpdaterSpec.js index 957ea9c37eb5..0317d2e6135a 100644 --- a/Specs/DynamicScene/RectangleGeometryUpdaterSpec.js +++ b/Specs/DynamicScene/RectangleGeometryUpdaterSpec.js @@ -127,7 +127,7 @@ defineSuite([ var dynamicObject = createBasicRectangle(); var updater = new RectangleGeometryUpdater(dynamicObject); dynamicObject.rectangle.coordinates = new SampledProperty(Rectangle); - dynamicObject.rectangle.coordinates.addSample(new JulianDate(), new Rectangle()); + dynamicObject.rectangle.coordinates.addSample(JulianDate.now(), new Rectangle()); expect(updater.isDynamic).toBe(true); }); diff --git a/Specs/DynamicScene/ReferencePropertySpec.js b/Specs/DynamicScene/ReferencePropertySpec.js index dca76cd43d26..a9e9de22cbc5 100644 --- a/Specs/DynamicScene/ReferencePropertySpec.js +++ b/Specs/DynamicScene/ReferencePropertySpec.js @@ -28,7 +28,7 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var time = new JulianDate(); + var time = JulianDate.now(); it('constructor sets expected values', function() { var collection = new DynamicObjectCollection(); diff --git a/Specs/DynamicScene/SampledPositionPropertySpec.js b/Specs/DynamicScene/SampledPositionPropertySpec.js index 515a722da87b..9cbf9987106c 100644 --- a/Specs/DynamicScene/SampledPositionPropertySpec.js +++ b/Specs/DynamicScene/SampledPositionPropertySpec.js @@ -35,7 +35,7 @@ defineSuite([ }); it('getValue works without a result parameter', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var value = new Cartesian3(1, 2, 3); var property = new SampledPositionProperty(); property.addSample(time, value); @@ -46,7 +46,7 @@ defineSuite([ }); it('getValue works with a result parameter', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var value = new Cartesian3(1, 2, 3); var property = new SampledPositionProperty(); property.addSample(time, value); @@ -58,7 +58,7 @@ defineSuite([ }); it('getValue returns in fixed frame', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var valueInertial = new Cartesian3(1, 2, 3); var valueFixed = PositionProperty.convertToReferenceFrame(time, valueInertial, ReferenceFrame.INERTIAL, ReferenceFrame.FIXED); var property = new SampledPositionProperty(ReferenceFrame.INERTIAL); @@ -69,7 +69,7 @@ defineSuite([ }); it('getValueInReferenceFrame works without a result parameter', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var value = new Cartesian3(1, 2, 3); var property = new SampledPositionProperty(); property.addSample(time, value); @@ -80,7 +80,7 @@ defineSuite([ }); it('getValueInReferenceFrame works with a result parameter', function() { - var time = new JulianDate(); + var time = JulianDate.now(); var value = new Cartesian3(1, 2, 3); var property = new SampledPositionProperty(ReferenceFrame.INERTIAL); property.addSample(time, value); @@ -202,7 +202,7 @@ defineSuite([ it('throws with no reference frame parameter', function() { var property = new SampledPositionProperty(); - var time = new JulianDate(); + var time = JulianDate.now(); expect(function() { property.getValueInReferenceFrame(time, undefined); }).toThrowDeveloperError(); @@ -253,7 +253,7 @@ defineSuite([ var right = new SampledPositionProperty(); expect(left.equals(right)).toEqual(true); - var time = new JulianDate(); + var time = JulianDate.now(); var value = new Cartesian3(1, 2, 3); left.addSample(time, value); expect(left.equals(right)).toEqual(false); diff --git a/Specs/DynamicScene/SampledPropertySpec.js b/Specs/DynamicScene/SampledPropertySpec.js index c360f5180211..009b9fc88c06 100644 --- a/Specs/DynamicScene/SampledPropertySpec.js +++ b/Specs/DynamicScene/SampledPropertySpec.js @@ -198,7 +198,7 @@ defineSuite([ it('mergeNewSamples works with huge data sets.', function() { var times = []; var values = []; - var epoch = new JulianDate(); + var epoch = JulianDate.now(); var data = []; var expectedTimes = []; @@ -220,7 +220,7 @@ defineSuite([ it('mergeNewSamples works for sorted non-intersecting data.', function() { var times = []; var values = []; - var epoch = new JulianDate(); + var epoch = JulianDate.now(); var newData = [0, 'a', 1, 'b', 2, 'c']; var newData2 = [3, 'd', 4, 'e', 5, 'f']; @@ -256,7 +256,7 @@ defineSuite([ it('mergeNewSamples works for elements of size 2.', function() { var times = []; var values = []; - var epoch = new JulianDate(); + var epoch = JulianDate.now(); var newData = [1, 'b', 'b', 4, 'e', 'e', 0, 'a', 'a']; var newData2 = [2, 'c', 'c', 3, 'd', 'd']; @@ -274,7 +274,7 @@ defineSuite([ it('mergeNewSamples works for unsorted intersecting data.', function() { var times = []; var values = []; - var epoch = new JulianDate(); + var epoch = JulianDate.now(); var newData = [1, 'b', 4, 'e', 0, 'a']; var newData2 = [5, 'f', 2, 'c', 3, 'd']; @@ -292,7 +292,7 @@ defineSuite([ it('mergeNewSamples works for data with repeated values.', function() { var times = []; var values = []; - var epoch = new JulianDate(); + var epoch = JulianDate.now(); var newData = [0, 'a', 1, 'b', 1, 'c', 0, 'd', 4, 'e', 5, 'f']; var expectedTimes = [JulianDate.addSeconds(epoch, 0), JulianDate.addSeconds(epoch, 1), JulianDate.addSeconds(epoch, 4), JulianDate.addSeconds(epoch, 5)]; @@ -366,7 +366,7 @@ defineSuite([ var right = new SampledProperty(Number); expect(left.equals(right)).toEqual(true); - var time = new JulianDate(); + var time = JulianDate.now(); left.addSample(time, 5); expect(left.equals(right)).toEqual(false); diff --git a/Specs/DynamicScene/StripeMaterialPropertySpec.js b/Specs/DynamicScene/StripeMaterialPropertySpec.js index 8e0bc3dcf804..40ad2239182b 100644 --- a/Specs/DynamicScene/StripeMaterialPropertySpec.js +++ b/Specs/DynamicScene/StripeMaterialPropertySpec.js @@ -39,7 +39,7 @@ defineSuite([ property.offset = new ConstantProperty(10); property.repeat = new ConstantProperty(20); - var result = property.getValue(new JulianDate()); + var result = property.getValue(JulianDate.now()); expect(result.horizontal).toEqual(false); expect(result.evenColor).toEqual(Color.RED); expect(result.oddColor).toEqual(Color.BLUE); @@ -109,7 +109,7 @@ defineSuite([ offset : 3, repeat : 4 }; - var returnedResult = property.getValue(new JulianDate(), result); + var returnedResult = property.getValue(JulianDate.now(), result); expect(returnedResult).toBe(result); expect(result.horizontal).toEqual(false); expect(result.evenColor).toEqual(Color.RED); diff --git a/Specs/DynamicScene/TimeIntervalCollectionPositionPropertySpec.js b/Specs/DynamicScene/TimeIntervalCollectionPositionPropertySpec.js index 1f9c030c6113..cc8530a2df8c 100644 --- a/Specs/DynamicScene/TimeIntervalCollectionPositionPropertySpec.js +++ b/Specs/DynamicScene/TimeIntervalCollectionPositionPropertySpec.js @@ -21,7 +21,7 @@ defineSuite([ it('default constructor has expected values', function() { var property = new TimeIntervalCollectionPositionProperty(); expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); - expect(property.getValue(new JulianDate())).toBeUndefined(); + expect(property.getValue(JulianDate.now())).toBeUndefined(); expect(property.referenceFrame).toBe(ReferenceFrame.FIXED); }); @@ -129,7 +129,7 @@ defineSuite([ it('throws with no reference frame parameter', function() { var property = new TimeIntervalCollectionPositionProperty(); - var time = new JulianDate(); + var time = JulianDate.now(); expect(function() { property.getValueInReferenceFrame(time, undefined); }).toThrowDeveloperError(); diff --git a/Specs/DynamicScene/TimeIntervalCollectionPropertySpec.js b/Specs/DynamicScene/TimeIntervalCollectionPropertySpec.js index 4abc4b68fcba..7aa9b2b25dfe 100644 --- a/Specs/DynamicScene/TimeIntervalCollectionPropertySpec.js +++ b/Specs/DynamicScene/TimeIntervalCollectionPropertySpec.js @@ -17,7 +17,7 @@ defineSuite([ it('default constructor has expected values', function() { var property = new TimeIntervalCollectionProperty(); expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); - expect(property.getValue(new JulianDate())).toBeUndefined(); + expect(property.getValue(JulianDate.now())).toBeUndefined(); expect(property.isConstant).toBe(true); }); diff --git a/Specs/Widgets/Animation/AnimationViewModelSpec.js b/Specs/Widgets/Animation/AnimationViewModelSpec.js index 5e6814b2b7ae..15115594c2f6 100644 --- a/Specs/Widgets/Animation/AnimationViewModelSpec.js +++ b/Specs/Widgets/Animation/AnimationViewModelSpec.js @@ -426,7 +426,7 @@ defineSuite([ var viewModel = new AnimationViewModel(clockViewModel); //UNBOUNDED but available when start/stop time does not include realtime - clockViewModel.systemTime = new JulianDate(); + clockViewModel.systemTime = JulianDate.now(); clockViewModel.clockRange = ClockRange.UNBOUNDED; clockViewModel.startTime = JulianDate.addSeconds(clockViewModel.systemTime, -60); clockViewModel.stopTime = JulianDate.addSeconds(clockViewModel.systemTime, -30); From 70fd5b10742d27d9900c5ee0e8525c4a1ec79b6d Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Tue, 10 Jun 2014 14:51:01 -0400 Subject: [PATCH 03/11] Ongoing JulianDate refactoring. 1. Clean up documentation. 2. Make all relevant function take result parameters. --- Source/Core/JulianDate.js | 553 +++++++++--------- Source/Core/Simon1994PlanetaryPositions.js | 2 +- Source/Core/TimeInterval.js | 2 +- Specs/Core/ClockSpec.js | 92 +-- Specs/Core/JulianDateSpec.js | 98 +--- Specs/Core/Simon1994PlanetaryPositionsSpec.js | 12 +- Specs/Core/TimeIntervalCollectionSpec.js | 142 ++--- Specs/Core/TimeIntervalSpec.js | 124 ++-- 8 files changed, 496 insertions(+), 529 deletions(-) diff --git a/Source/Core/JulianDate.js b/Source/Core/JulianDate.js index 79feab01e08a..18722fe59021 100644 --- a/Source/Core/JulianDate.js +++ b/Source/Core/JulianDate.js @@ -23,6 +23,7 @@ define([ TimeStandard) { "use strict"; + var gregorianDateScratch = new GregorianDate(); var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; var daysInLeapFeburary = 29; @@ -140,10 +141,6 @@ define([ return [dayNumber, secondsOfDay]; } - function computeJulianDateComponentsFromDate(date) { - return computeJulianDateComponents(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()); - } - //Regular expressions used for ISO8601 date parsing. //YYYY var matchCalendarYear = /^(\d{4})$/; @@ -164,7 +161,7 @@ define([ // Match hours/minutes HH:MM:SS HHMMSS.xxxxx var matchHoursMinutesSeconds = /^(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?/.source + utcOffset.source; - var iso8601ErrorMessage = 'Valid ISO 8601 date string required.'; + var iso8601ErrorMessage = 'Invalid ISO 8601 date.'; /** * Represents an astronomical Julian date, which is the number of days since noon on January 1, -4712 (4713 BC). @@ -196,7 +193,7 @@ define([ julianSecondsOfDay = defaultValue(julianSecondsOfDay, 0.0); timeStandard = defaultValue(timeStandard, TimeStandard.UTC); - //If julianDayNumber was fractional, make it an integer and add the number of seconds the fraction represented + //If julianDayNumber is fractional, make it an integer and add the number of seconds the fraction represented. var wholeDays = julianDayNumber | 0; var secondsOfDay = julianSecondsOfDay + (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY; @@ -208,61 +205,57 @@ define([ }; /** - * Creates a JulianDate instance from a JavaScript Date object. - * While the JavaScript Date object defaults to the system's local time zone, - * the JulianDate is computed using the UTC values. + * Creates a new instance from a JavaScript Date. * - * @param {Date} date The JavaScript Date object representing the time to be converted to a JulianDate. - * @param {TimeStandard} [timeStandard=TimeStandard.UTC] Indicates the time standard in which this date is represented. - * @returns {JulianDate} The new {@Link JulianDate} instance. + * @param {Date} date A JavaScript Date. + * @param {JulianDate} [result] An existing instance to use for the result. + * @returns {JulianDate} The modified result parameter or a new instance if none was provided. * * @exception {DeveloperError} date must be a valid JavaScript Date. * * @example - * // Construct a JulianDate specifying the UTC time standard - * var date = new Date('January 1, 2011 12:00:00 EST'); - * var julianDate = Cesium.JulianDate.fromDate(date, Cesium.TimeStandard.UTC); + * var julianDate = Cesium.JulianDate.fromDate(new Date('January 1, 2011 12:00:00 EST')); */ - JulianDate.fromDate = function(date, timeStandard) { + JulianDate.fromDate = function(date, result) { //>>includeStart('debug', pragmas.debug); if (!(date instanceof Date) || isNaN(date.getTime())) { throw new DeveloperError('date must be a valid JavaScript Date.'); } //>>includeEnd('debug'); - var components = computeJulianDateComponentsFromDate(date); - return new JulianDate(components[0], components[1], timeStandard); + var components = computeJulianDateComponents(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()); + if (!defined(result)) { + return new JulianDate(components[0], components[1], TimeStandard.UTC); + } + setComponents(components[0], components[1], result); + convertUtcToTai(result); + return result; }; /** - * Creates a JulianDate instance from an ISO 8601 date string. Unlike Date.parse, - * this method properly accounts for all valid formats defined by the ISO 8601 - * specification. It also properly handles leap seconds and sub-millisecond times. - * - * @param {String} iso8601String The ISO 8601 date string representing the time to be converted to a JulianDate. - * @returns {JulianDate} The new {@Link JulianDate} instance. + * Creates a new instance from a from an {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} date. + * This method is superior to Date.parse because it will handle all valid formats defined by the ISO 8601 + * specification, including leap seconds and sub-millisecond times, which discarded by most JavaScript implementations. * - * @exception {DeveloperError} Valid ISO 8601 date string required. + * @param {String} iso8601String An ISO 8601 date. + * @param {JulianDate} [result] An existing instance to use for the result. + * @returns {JulianDate} The modified result parameter or a new instance if none was provided. * - * @see JulianDate - * @see JulianDate.fromTotalDays - * @see JulianDate.fromDate - * @see LeapSecond - * @see {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601 on Wikipedia} + * @exception {DeveloperError} Invalid ISO 8601 date. * * @example - * // Example 1. Construct a JulianDate in UTC at April 24th, 2012 6:08PM UTC - * var julianDate = Cesium.JulianDate.fromIso8601('2012-04-24T18:08Z'); + * // Construct an instance at April 24th, 2012 6:08PM UTC + * var date = Cesium.JulianDate.fromIso8601('2012-04-24T18:08Z'); * * @example - * // Example 2. Construct a JulianDate in local time April 24th, 2012 12:00 AM - * var localDay = Cesium.JulianDate.fromIso8601('2012-04-24'); + * // Construct an instance in local time April 24th, 2012 12:00 AM + * var date = Cesium.JulianDate.fromIso8601('2012-04-24'); * * @example - * // Example 3. Construct a JulianDate 5 hours behind UTC April 24th, 2012 5:00 pm UTC - * var localDay = Cesium.JulianDate.fromIso8601('2012-04-24T12:00-05:00'); + * // Construct an instance 5 hours behind April 24th, 2012 5:00 PM UTC + * var date = Cesium.JulianDate.fromIso8601('2012-04-24T12:00-05:00'); */ - JulianDate.fromIso8601 = function(iso8601String) { + JulianDate.fromIso8601 = function(iso8601String, result) { //>>includeStart('debug', pragmas.debug); if (typeof iso8601String !== 'string') { throw new DeveloperError(iso8601ErrorMessage); @@ -493,7 +486,13 @@ define([ //Now create the JulianDate components from the Gregorian date and actually create our instance. var components = computeJulianDateComponents(year, month, day, hour, minute, second, millisecond); - var result = new JulianDate(components[0], components[1], TimeStandard.UTC); + + if (!defined(result)) { + result = new JulianDate(components[0], components[1], TimeStandard.UTC); + } else { + setComponents(components[0], components[1], result); + convertUtcToTai(result); + } //If we were on a leap second, add it back. if (isLeapSecond) { @@ -503,141 +502,33 @@ define([ return result; }; - /** - * Creates a JulianDate instance from a single number representing the Julian day and fractional day. - * - * @param {Number} totalDays The combined Julian Day Number and fractional day. - * @param {TimeStandard} [timeStandard=TimeStandard.UTC] Indicates the time standard in which the first parameter is defined. - * @returns {JulianDate} The new {@Link JulianDate} instance. - * - * @see JulianDate - * @see JulianDate.fromDate - * @see JulianDate.fromIso8601 - * @see TimeStandard - * @see LeapSecond - * - * @example - * // Construct a date which corresponds to January 1, 1991 06:00:00 UTC. - * var julianDate = Cesium.JulianDate.fromTotalDays(2448257.75, Cesium.TimeStandard.UTC); - */ - JulianDate.fromTotalDays = function(totalDays, timeStandard) { - //>>includeStart('debug', pragmas.debug); - if (totalDays === null || isNaN(totalDays)) { - throw new DeveloperError('totalDays is required.'); - } - //>>includeEnd('debug'); - - return new JulianDate(totalDays, 0, timeStandard); - }; - /** * Creates a new instance that represents the current system time. * This is equivalent to calling JulianDate.fromDate(new Date());. * - * @param {JulianDate} [result] An existing instance to store the result into. + * @param {JulianDate} [result] An existing instance to use for the result. * @returns {JulianDate} The modified result parameter or a new instance if none was provided. */ JulianDate.now = function(result) { - var components = computeJulianDateComponentsFromDate(new Date()); - if (!defined(result)) { - return new JulianDate(components[0], components[1], TimeStandard.UTC); - } - setComponents(components[0], components[1], result); - convertUtcToTai(result); - return result; - }; - - /** - * Duplicates a JulianDate instance. - * - * @param {JulianDate} date The JulianDate to duplicate. - * @param {JulianDate} [result] The object onto which to store the JulianDate. - * @returns {JulianDate} The modified result parameter or a new JulianDate instance if one was not provided. (Returns undefined if date is undefined) - */ - JulianDate.clone = function(date, result) { - if (!defined(date)) { - return undefined; - } - if (!defined(result)) { - return new JulianDate(date.dayNumber, date.secondsOfDay, TimeStandard.TAI); - } - result.dayNumber = date.dayNumber; - result.secondsOfDay = date.secondsOfDay; - return result; + return JulianDate.fromDate(new Date(), result); }; - /** - * Compares two JulianDate instances. - * - * @param {JulianDate} a The first instance. - * @param {JulianDate} b The second instance. - * @returns {Number} A negative value if a is less than b, - * a positive value if a is greater than b, - * or zero if a and b are equal. - */ - JulianDate.compare = function(left, right) { - var julianDayNumberDifference = left.dayNumber - right.dayNumber; - if (julianDayNumberDifference !== 0) { - return julianDayNumberDifference; - } - return left.secondsOfDay - right.secondsOfDay; - }; - - /** - * Returns true if the first JulianDate equals the second JulianDate. - * - * @param {JulianDate} left The first JulianDate to compare for equality. - * @param {JulianDate} right The second JulianDate to compare for equality. - * @returns {Boolean} true if the JulianDates are equal; otherwise, false. - */ - JulianDate.equals = function(left, right) { - return (left === right) || - (defined(left) && - defined(right) && - left.dayNumber === right.dayNumber && - left.secondsOfDay === right.secondsOfDay); - }; + var toGregorianDateScratch = new JulianDate(0, 0, TimeStandard.TAI); /** - * Returns true if the provided dates are within epsilon seconds of - * each other. That is, in order for the dates to be considered equal (and for - * this function to return true), the absolute value of the difference between them, in - * seconds, must be less than epsilon. - * - * @param {JulianDate} left The first JulianDate to be compared. - * @param {JulianDate} right The second JulianDate to be compared. - * @param {Number} epsilon The number of seconds that should separate the two JulianDates - * @returns {Boolean} true if the two JulianDates are within epsilon seconds of each other; otherwise false. + * Creates a {@link GregorianDate} from the provided instance. * - * @see JulianDate#equals + * @param {JulianDate} julianDate The date to be converted. + * @param {GregorianDate} [result] An existing instance to use for the result. + * @returns {GregorianDate} The modified result parameter or a new instance if none was provided. */ - JulianDate.equalsEpsilon = function(left, right, epsilon) { + JulianDate.toGregorianDate = function(julianDate, result) { //>>includeStart('debug', pragmas.debug); - if (epsilon === null || isNaN(epsilon)) { - throw new DeveloperError('epsilon is required and must be a number.'); + if (!defined(julianDate)) { + throw new DeveloperError('julianDate is required.'); } //>>includeEnd('debug'); - return Math.abs(JulianDate.getSecondsDifference(left, right)) <= epsilon; - }; - - /** - * Returns the total number of whole and fractional days represented by this astronomical Julian date. - * - * @returns {Number} The Julian date as single floating point number. - */ - JulianDate.getTotalDays = function(julianDate) { - return julianDate.dayNumber + (julianDate.secondsOfDay / TimeConstants.SECONDS_PER_DAY); - }; - - var toGregorianDateScratch = new JulianDate(0, 0, TimeStandard.TAI); - - /** - * Creates a GregorianDate representation of this date in UTC. - * - * @returns {GregorianDate} A gregorian date. - */ - JulianDate.toGregorianDate = function(julianDate) { var isLeapSecond = false; var thisUtc = convertTaiToUtc(julianDate, toGregorianDateScratch); if (!defined(thisUtc)) { @@ -687,19 +578,38 @@ define([ second += 1; } - return new GregorianDate(year, month, day, hour, minute, second, millisecond, isLeapSecond); + if (!defined(result)) { + return new GregorianDate(year, month, day, hour, minute, second, millisecond, isLeapSecond); + } + + result.year = year; + result.month = month; + result.day = day; + result.hour = hour; + result.minute = minute; + result.second = second; + result.millisecond = millisecond; + result.isLeapSecond = isLeapSecond; + return result; }; /** - * Creates a JavaScript Date representation of this date in UTC. - * Javascript dates are only accurate to the nearest millisecond and - * many implementation cannot represet a leap second. Consider using - * {@link JulianDate#toGregorianDate} instead. + * Creates a JavaScript Date from the provided instance. + * Since JavaScript dates are only accurate to the nearest millisecond and + * cannot represent a leap second, consider using {@link JulianDate.toGregorianDate} instead. + * If the provided JulianDate is during a leap second, the previous second is used. * - * @returns {Date} A new JavaScript Date equivalent to this JulianDate. + * @param {JulianDate} julianDate The date to be converted. + * @returns {Date} A new instance representing the provided date. */ JulianDate.toDate = function(julianDate) { - var gDate = JulianDate.toGregorianDate(julianDate); + //>>includeStart('debug', pragmas.debug); + if (!defined(julianDate)) { + throw new DeveloperError('julianDate is required.'); + } + //>>includeEnd('debug'); + + var gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch); var second = gDate.second; if (gDate.isLeapSecond) { second -= 1; @@ -708,13 +618,20 @@ define([ }; /** - * Creates an ISO8601 string represenation of this JulianDate in UTC. + * Creates an ISO8601 representation of the provided date. * + * @param {JulianDate} julianDate The date to be converted. * @param {Number} [precision] The number of fractional digits used to represent the seconds component. By default, the most precise representation is used. - * @returns {String} An ISO8601 string represenation of this JulianDate. + * @returns {String} The ISO8601 representation of the provided date. */ JulianDate.toIso8601 = function(julianDate, precision) { - var gDate = JulianDate.toGregorianDate(julianDate); + //>>includeStart('debug', pragmas.debug); + if (!defined(julianDate)) { + throw new DeveloperError('julianDate is required.'); + } + //>>includeEnd('debug'); + + var gDate = JulianDate.toGregorianDate(julianDate, gDate); var millisecondStr; if (!defined(precision) && gDate.millisecond !== 0) { @@ -734,49 +651,160 @@ define([ }; /** - * Computes the number of seconds that have elapsed from this JulianDate to the other - * JulianDate. + * Duplicates a JulianDate instance. * - * @param {JulianDate} other The other JulianDate, which is the end of the interval. - * @returns {Number} The number of seconds that have elpased from this JulianDate to the other JulianDate. + * @param {JulianDate} julianDate The date to duplicate. + * @param {JulianDate} [result] An existing instance to use for the result. + * @returns {JulianDate} The modified result parameter or a new instance if none was provided. Returns undefined if julianDate is undefined. + */ + JulianDate.clone = function(julianDate, result) { + if (!defined(julianDate)) { + return undefined; + } + if (!defined(result)) { + return new JulianDate(julianDate.dayNumber, julianDate.secondsOfDay, TimeStandard.TAI); + } + result.dayNumber = julianDate.dayNumber; + result.secondsOfDay = julianDate.secondsOfDay; + return result; + }; + + /** + * Compares two instances. + * + * @param {JulianDate} left The first instance. + * @param {JulianDate} right The second instance. + * @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. + */ + JulianDate.compare = function(left, right) { + //>>includeStart('debug', pragmas.debug); + if (!defined(left)) { + throw new DeveloperError('left is required.'); + } + if (!defined(right)) { + throw new DeveloperError('right is required.'); + } + //>>includeEnd('debug'); + + var julianDayNumberDifference = left.dayNumber - right.dayNumber; + if (julianDayNumberDifference !== 0) { + return julianDayNumberDifference; + } + return left.secondsOfDay - right.secondsOfDay; + }; + + /** + * Compares two instances and returns true if they are equal, false otherwise. + * + * @param {JulianDate} [left] The first instance. + * @param {JulianDate} [right] The second instance. + * @returns {Boolean} true if the dates are equal; otherwise, false. + */ + JulianDate.equals = function(left, right) { + return (left === right) || + (defined(left) && + defined(right) && + left.dayNumber === right.dayNumber && + left.secondsOfDay === right.secondsOfDay); + }; + + /** + * Compares two instances and returns true if they are within epsilon seconds of + * each other. That is, in order for the dates to be considered equal (and for + * this function to return true), the absolute value of the difference between them, in + * seconds, must be less than epsilon. + * + * @param {JulianDate} [left] The first instance. + * @param {JulianDate} [right] The second instance. + * @param {Number} epsilon The maximum number of seconds that should separate the two instances. + * @returns {Boolean} true if the two dates are within epsilon seconds of each other; otherwise false. + */ + JulianDate.equalsEpsilon = function(left, right, epsilon) { + //>>includeStart('debug', pragmas.debug); + if (!defined(epsilon)) { + throw new DeveloperError('epsilon is required.'); + } + //>>includeEnd('debug'); + + return (left === right) || + (defined(left) && + defined(right) && + Math.abs(JulianDate.getSecondsDifference(left, right)) <= epsilon); + }; + + /** + * Computes the total number of whole and fractional days represented by the provided instance. + * + * @param {JulianDate} julianDate The date. + * @returns {Number} The Julian date as single floating point number. + */ + JulianDate.getTotalDays = function(julianDate) { + //>>includeStart('debug', pragmas.debug); + if (!defined(julianDate)) { + throw new DeveloperError('julianDate is required.'); + } + //>>includeEnd('debug'); + return julianDate.dayNumber + (julianDate.secondsOfDay / TimeConstants.SECONDS_PER_DAY); + }; + + /** + * Computes the difference in seconds between the provided instance. * - * @see JulianDate#getDaysDifference + * @param {JulianDate} left The first instance. + * @param {JulianDate} right The second instance. + * @returns {Number} The difference, in seconds, when subtracting right from left. * * @example - * var start = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); - * var end = Cesium.JulianDate.fromDate(new Date('July 5, 2011 12:01:00')); - * var difference = start.getSecondsDifference(end); // 86460.0 seconds + * var left = Cesium.JulianDate.fromDate(new Date('July 5, 2011 12:01:00')); + * var right = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); + * var difference = JulianDate.getSecondsDifference(left, right); // -86460.0 seconds */ JulianDate.getSecondsDifference = function(left, right) { + //>>includeStart('debug', pragmas.debug); + if (!defined(left)) { + throw new DeveloperError('left is required.'); + } + if (!defined(right)) { + throw new DeveloperError('right is required.'); + } + //>>includeEnd('debug'); + var dayDifference = (right.dayNumber - left.dayNumber) * TimeConstants.SECONDS_PER_DAY; return (dayDifference + (right.secondsOfDay - left.secondsOfDay)); }; /** - * Computes the number of days that have elapsed from this JulianDate to the other - * JulianDate. A day is always exactly 86400.0 seconds. + * Computes the difference in days between the provided instance. * - * @param {JulianDate} other The other JulianDate, which is the end of the interval. - * @returns {Number} The number of days that have elpased from this JulianDate to the other JulianDate. + * @param {JulianDate} left The first instance. + * @param {JulianDate} right The second instance. + * @returns {Number} The difference, in days, when subtracting right from left. * * @example - * var start = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); - * var end = Cesium.JulianDate.fromDate(new Date('July 5, 2011 14:24:00')); - * var difference = JulianDate.getDaysDifference(start, end); // 1.1 days + * var left = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); + * var right = Cesium.JulianDate.fromDate(new Date('July 5, 2011 14:24:00')); + * var difference = JulianDate.getDaysDifference(left, right); // 1.1 days */ JulianDate.getDaysDifference = function(left, right) { + //>>includeStart('debug', pragmas.debug); + if (!defined(left)) { + throw new DeveloperError('left is required.'); + } + if (!defined(right)) { + throw new DeveloperError('right is required.'); + } + //>>includeEnd('debug'); + var dayDifference = (right.dayNumber - left.dayNumber); var secondDifference = (right.secondsOfDay - left.secondsOfDay) / TimeConstants.SECONDS_PER_DAY; return dayDifference + secondDifference; }; /** - * Returns the number of seconds this TAI date is ahead of UTC. - * - * @returns {Number} The number of seconds this TAI date is ahead of UTC + * Computes the number of seconds the provided instance is ahead of UTC. * - * @see LeapSecond - * @see TimeStandard + * @param {JulianDate} julianDate The date. + * @returns {Number} The number of seconds the provided isntance is ahead of UTC */ JulianDate.getTaiMinusUtc = function(julianDate) { binarySearchScratchLeapSecond.julianDate = julianDate; @@ -793,12 +821,12 @@ define([ }; /** - * Returns a new JulianDate representing a time duration seconds later - * (or earlier in the case of a negative amount). + * Adds the provided number of seconds to the provided date instance. * + * @param {JulianDate} julianDate The date. * @param {Number} seconds The number of seconds to add or subtract. - * @param {JulianDate} [result] The JulianDate to store the result into. - * @returns {JulianDate} The modified result parameter or a new JulianDate instance if it was not provided. + * @param {JulianDate} [result] An existing instance to use for the result. + * @returns {JulianDate} The modified result parameter or a new instance if none was provided. * * @example * var date = new Date(); @@ -809,6 +837,9 @@ define([ */ JulianDate.addSeconds = function(julianDate, seconds, result) { //>>includeStart('debug', pragmas.debug); + if (!defined(julianDate)) { + throw new DeveloperError('julianDate is required.'); + } if (!defined(seconds)) { throw new DeveloperError('seconds is required.'); } @@ -818,11 +849,12 @@ define([ }; /** - * Returns a new JulianDate representing a time duration minutes later - * (or earlier in the case of a negative amount). + * Adds the provided number of minutes to the provided date instance. * - * @param {Number} duration An integer number of minutes to add or subtract. - * @returns {JulianDate} A new JulianDate object + * @param {JulianDate} julianDate The date. + * @param {Number} minutes The number of minutes to add or subtract. + * @param {JulianDate} [result] An existing instance to use for the result. + * @returns {JulianDate} The modified result parameter or a new instance if none was provided. * * @example * var date = new Date(); @@ -831,26 +863,33 @@ define([ * var start = Cesium.JulianDate.fromDate(date); * var end = start.addMinutes(65); // July 4, 2011 @ 13:05 UTC */ - JulianDate.addMinutes = function(julianDate, duration) { + JulianDate.addMinutes = function(julianDate, minutes) { //>>includeStart('debug', pragmas.debug); - if (!defined(duration)) { - throw new DeveloperError('duration is required and must be a number.'); + if (!defined(julianDate)) { + throw new DeveloperError('julianDate is required.'); + } + if (!defined(minutes)) { + throw new DeveloperError('minutes is required.'); } //>>includeEnd('debug'); - var newSecondsOfDay = julianDate.secondsOfDay + (duration * TimeConstants.SECONDS_PER_MINUTE); + var newSecondsOfDay = julianDate.secondsOfDay + (minutes * TimeConstants.SECONDS_PER_MINUTE); return new JulianDate(julianDate.dayNumber, newSecondsOfDay, TimeStandard.TAI); }; /** - * Returns a new JulianDate representing a time duration hours later - * (or earlier in the case of a negative amount). + * Adds the provided number of hours to the provided date instance. * - * @param {Number} duration An integer number of hours to add or subtract. - * @returns {JulianDate} A new JulianDate object + * @param {JulianDate} julianDate The date. + * @param {Number} hours The number of hours to add or subtract. + * @param {JulianDate} [result] An existing instance to use for the result. + * @returns {JulianDate} The modified result parameter or a new instance if none was provided. */ JulianDate.addHours = function(julianDate, hours) { //>>includeStart('debug', pragmas.debug); + if (!defined(julianDate)) { + throw new DeveloperError('julianDate is required.'); + } if (!defined(hours)) { throw new DeveloperError('hours is required.'); } @@ -861,127 +900,103 @@ define([ }; /** - * Returns a new JulianDate representing a time duration days later - * (or earlier in the case of a negative amount). + * Adds the provided number of days to the provided date instance. * - * @param {Number} duration An integer number of days to add or subtract. - * @returns {JulianDate} A new JulianDate object + * @param {JulianDate} julianDate The date. + * @param {Number} days The number of days to add or subtract. + * @param {JulianDate} [result] An existing instance to use for the result. + * @returns {JulianDate} The modified result parameter or a new instance if none was provided. */ - JulianDate.addDays = function(julianDate, duration) { + JulianDate.addDays = function(julianDate, days) { //>>includeStart('debug', pragmas.debug); - if (!defined(duration)) { - throw new DeveloperError('duration is required and must be a number.'); + if (!defined(julianDate)) { + throw new DeveloperError('julianDate is required.'); + } + if (!defined(days)) { + throw new DeveloperError('days is required.'); } //>>includeEnd('debug'); - var newJulianDayNumber = julianDate.dayNumber + duration; + var newJulianDayNumber = julianDate.dayNumber + days; return new JulianDate(newJulianDayNumber, julianDate.secondsOfDay, TimeStandard.TAI); }; /** - * Returns true if other occurs after this JulianDate. + * Compares the provided instances and returns true if left is earlier than right, false otherwise. * - * @param {JulianDate} other The JulianDate to be compared. - * @returns {Boolean} true if this JulianDate is chronologically earlier than other; otherwise, false. + * @param {JulianDate} left The first instance. + * @param {JulianDate} right The second instance. + * @returns {Boolean} true if left is earlier than right, false otherwise. */ JulianDate.lessThan = function(left, right) { return JulianDate.compare(left, right) < 0; }; /** - * Returns true if other occurs at or after this JulianDate. - * - * @param {JulianDate} other The JulianDate to be compared. - * @returns {Boolean} true if this JulianDate is chronologically less than or equal toother; otherwise, false. - * - * @see JulianDate#lessThan - * @see JulianDate#greaterThan - * @see JulianDate#greaterThanOrEquals + * Compares the provided instances and returns true if left is earlier than or equal to right, false otherwise. * - * @example - * var start = Cesium.JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); - * var end = Cesium.JulianDate.fromDate(new Date('July 6, 2011 12:00:00')); - * JulianDate.lessThanOrEquals(start, end); // true + * @param {JulianDate} left The first instance. + * @param {JulianDate} right The second instance. + * @returns {Boolean} true if left is earlier than or equal to right, false otherwise. */ JulianDate.lessThanOrEquals = function(left, right) { return JulianDate.compare(left, right) <= 0; }; /** - * Returns true if other occurs before this JulianDate. - * - * @param {JulianDate} other The JulianDate to be compared. - * @returns {Boolean} true if this JulianDate is chronologically later than other; otherwise, false. - * - * @see JulianDate#lessThan - * @see JulianDate#lessThanOrEquals - * @see JulianDate#greaterThanOrEquals + * Compares the provided instances and returns true if left is later than right, false otherwise. * - * @example - * var start = Cesium.JulianDate.fromDate(new Date('July 6, 1991 12:00:00')); - * var end = Cesium.JulianDate.fromDate(new Date('July 6, 2011 12:01:00')); - * JulianDate.greaterThan(end, start); // true + * @param {JulianDate} left The first instance. + * @param {JulianDate} right The second instance. + * @returns {Boolean} true if left is later than right, false otherwise. */ JulianDate.greaterThan = function(left, right) { return JulianDate.compare(left, right) > 0; }; /** - * Returns true if other occurs at or before this JulianDate. + * Compares the provided instances and returns true if left is later than or equal to right, false otherwise. * - * @param {JulianDate} other The JulianDate to be compared. - * @returns {Boolean} true if this JulianDate is chronologically later than or equal to other; otherwise, false. + * @param {JulianDate} left The first instance. + * @param {JulianDate} right The second instance. + * @returns {Boolean} true if left is later than or equal to right, false otherwise. */ JulianDate.greaterThanOrEquals = function(left, right) { return JulianDate.compare(left, right) >= 0; }; /** - * Duplicates this JulianDate. + * Duplicates this instance. * - * @param {JulianDate} [result] The object onto which to store the JulianDate. - * @returns {JulianDate} The modified result parameter or a new JulianDate instance if one was not provided. + * @param {JulianDate} [result] An existing instance to use for the result. + * @returns {JulianDate} The modified result parameter or a new instance if none was provided. */ JulianDate.prototype.clone = function(result) { return JulianDate.clone(this, result); }; /** - * Returns true if this date is equivalent to the specified date. - * - * @param {JulianDate} other The JulianDate to be compared. - * @returns {Boolean} true if the two JulianDates are equal; otherwise false. + * Compares this and the provided instance and returns true if they are equal, false otherwise. * - * @see JulianDate#equalsEpsilon - * - * @example - * var original = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); - * var clone = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); - * original.equals(clone); // true + * @param {JulianDate} [right] The second instance. + * @returns {Boolean} true if the dates are equal; otherwise, false. */ - JulianDate.prototype.equals = function(other) { - return JulianDate.equals(this, other); + JulianDate.prototype.equals = function(right) { + return JulianDate.equals(this, right); }; /** - * Returns true if this date is within epsilon seconds of the - * specified date. That is, in order for the dates to be considered equal (and for + * Compares this and the provided instance and returns true if they are within epsilon seconds of + * each other. That is, in order for the dates to be considered equal (and for * this function to return true), the absolute value of the difference between them, in * seconds, must be less than epsilon. * - * @param {JulianDate} other The JulianDate to be compared. - * @param {Number} epsilon The number of seconds that should separate the two JulianDates - * @returns {Boolean} true if the two JulianDates are within epsilon seconds of each other; otherwise false. - * - * @see JulianDate#equals - * - * @example - * var original = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); - * var clone = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:01')); - * original.equalsEpsilon(clone, 2); // true + * @param {JulianDate} [right] The second instance. + * @param {Number} epsilon The maximum number of seconds that should separate the two instances. + * @returns {Boolean} true if the two dates are within epsilon seconds of each other; otherwise false. */ - JulianDate.prototype.equalsEpsilon = function(other, epsilon) { - return JulianDate.equalsEpsilon(this, other, epsilon); + JulianDate.prototype.equalsEpsilon = function(right, epsilon) { + return JulianDate.equalsEpsilon(this, right, epsilon); }; /** diff --git a/Source/Core/Simon1994PlanetaryPositions.js b/Source/Core/Simon1994PlanetaryPositions.js index 99fb34fe3208..16d2a9dde3e6 100644 --- a/Source/Core/Simon1994PlanetaryPositions.js +++ b/Source/Core/Simon1994PlanetaryPositions.js @@ -64,7 +64,7 @@ define([ return result; } - var epoch = JulianDate.fromTotalDays(2451545.0, TimeStandard.TAI); //Actually TDB (not TAI) + var epoch = new JulianDate(2451545, 0, TimeStandard.TAI); //Actually TDB (not TAI) var GravitationalParameterOfEarth = 3.98600435e14; var GravitationalParameterOfSun = GravitationalParameterOfEarth * (1.0 + 0.012300034) * 328900.56; var MetersPerKilometer = 1000.0; diff --git a/Source/Core/TimeInterval.js b/Source/Core/TimeInterval.js index 5899409f780a..2188f47cd0f7 100644 --- a/Source/Core/TimeInterval.js +++ b/Source/Core/TimeInterval.js @@ -35,7 +35,7 @@ define([ * * @example * // Construct an Timeinterval closed on one end with a Color payload. - * var interval = new Cesium.TimeInterval(Cesium.JulianDate.fromTotalDays(1000), Cesium.JulianDate.fromTotalDays(1001), true, false, Cesium.Color.WHITE); + * var interval = new Cesium.TimeInterval(Cesium.new JulianDate(1000), Cesium.new JulianDate(1001), true, false, Cesium.Color.WHITE); */ var TimeInterval = function(start, stop, isStartIncluded, isStopIncluded, data) { //>>includeStart('debug', pragmas.debug); diff --git a/Specs/Core/ClockSpec.js b/Specs/Core/ClockSpec.js index 97712a9dd000..4729089a7244 100644 --- a/Specs/Core/ClockSpec.js +++ b/Specs/Core/ClockSpec.js @@ -22,9 +22,9 @@ defineSuite([ }); it('constructor sets provided parameters correctly', function() { - var start = JulianDate.fromTotalDays(12); - var stop = JulianDate.fromTotalDays(112); - var currentTime = JulianDate.fromTotalDays(13); + var start = new JulianDate(12); + var stop = new JulianDate(112); + var currentTime = new JulianDate(13); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = 1.5; @@ -45,9 +45,9 @@ defineSuite([ }); it('constructor works with no currentTime parameter', function() { - var start = JulianDate.fromTotalDays(12); - var stop = JulianDate.fromTotalDays(112); - var currentTime = JulianDate.fromTotalDays(12); + var start = new JulianDate(12); + var stop = new JulianDate(112); + var currentTime = new JulianDate(12); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = 1.5; @@ -67,8 +67,8 @@ defineSuite([ }); it('constructor works with no startTime parameter', function() { - var stop = JulianDate.fromTotalDays(112); - var currentTime = JulianDate.fromTotalDays(13); + var stop = new JulianDate(112); + var currentTime = new JulianDate(13); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = 1.5; @@ -88,9 +88,9 @@ defineSuite([ }); it('constructor works with no start or stop time', function() { - var start = JulianDate.fromTotalDays(12); - var stop = JulianDate.fromTotalDays(13); - var currentTime = JulianDate.fromTotalDays(12); + var start = new JulianDate(12); + var stop = new JulianDate(13); + var currentTime = new JulianDate(12); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = 1.5; @@ -109,9 +109,9 @@ defineSuite([ }); it('constructor works with no start or current time', function() { - var start = JulianDate.fromTotalDays(12); - var stop = JulianDate.fromTotalDays(13); - var currentTime = JulianDate.fromTotalDays(12); + var start = new JulianDate(12); + var stop = new JulianDate(13); + var currentTime = new JulianDate(12); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = 1.5; @@ -131,9 +131,9 @@ defineSuite([ it('constructor works with no current or stop time', function() { - var start = JulianDate.fromTotalDays(12); - var stop = JulianDate.fromTotalDays(13); - var currentTime = JulianDate.fromTotalDays(12); + var start = new JulianDate(12); + var stop = new JulianDate(13); + var currentTime = new JulianDate(12); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = 1.5; @@ -152,9 +152,9 @@ defineSuite([ }); it('constructor works with no stopTime parameter', function() { - var start = JulianDate.fromTotalDays(12); - var stop = JulianDate.fromTotalDays(13); - var currentTime = JulianDate.fromTotalDays(12); + var start = new JulianDate(12); + var stop = new JulianDate(13); + var currentTime = new JulianDate(12); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = 1.5; @@ -174,9 +174,9 @@ defineSuite([ }); it('Tick dependant clock step works animating forward.', function() { - var start = JulianDate.fromTotalDays(0); - var stop = JulianDate.fromTotalDays(1); - var currentTime = JulianDate.fromTotalDays(0.5); + var start = new JulianDate(0); + var stop = new JulianDate(1); + var currentTime = new JulianDate(0.5); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = 1.5; @@ -200,9 +200,9 @@ defineSuite([ }); it('Tick dependant clock step works animating backwards.', function() { - var start = JulianDate.fromTotalDays(0); - var stop = JulianDate.fromTotalDays(1); - var currentTime = JulianDate.fromTotalDays(0.5); + var start = new JulianDate(0); + var stop = new JulianDate(1); + var currentTime = new JulianDate(0.5); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = -1.5; @@ -226,9 +226,9 @@ defineSuite([ }); it('Tick dependant clock step works unbounded animating forward.', function() { - var start = JulianDate.fromTotalDays(0); - var stop = JulianDate.fromTotalDays(1); - var currentTime = JulianDate.fromTotalDays(1); + var start = new JulianDate(0); + var stop = new JulianDate(1); + var currentTime = new JulianDate(1); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.UNBOUNDED; var multiplier = 1.5; @@ -252,9 +252,9 @@ defineSuite([ }); it('Tick dependant clock step works unbounded animating backwards.', function() { - var start = JulianDate.fromTotalDays(0); - var stop = JulianDate.fromTotalDays(1); - var currentTime = JulianDate.fromTotalDays(0); + var start = new JulianDate(0); + var stop = new JulianDate(1); + var currentTime = new JulianDate(0); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.UNBOUNDED; var multiplier = -1.5; @@ -278,9 +278,9 @@ defineSuite([ }); it('Tick dependant clock loops animating forward.', function() { - var start = JulianDate.fromTotalDays(0); - var stop = JulianDate.fromTotalDays(1); - var currentTime = JulianDate.fromTotalDays(1); + var start = new JulianDate(0); + var stop = new JulianDate(1); + var currentTime = new JulianDate(1); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = 1.5; @@ -304,10 +304,10 @@ defineSuite([ }); it('Tick dependant clock step stops at start when animating backwards with ClockRange.LOOP_STOP.', function() { - var start = JulianDate.fromTotalDays(0); - var stop = JulianDate.fromTotalDays(1); + var start = new JulianDate(0); + var stop = new JulianDate(1); - var currentTime = JulianDate.fromTotalDays(0); + var currentTime = new JulianDate(0); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.LOOP_STOP; var multiplier = -100.0; @@ -326,10 +326,10 @@ defineSuite([ }); it('Tick dependant clock step stops at end when animating forwards.', function() { - var start = JulianDate.fromTotalDays(0); - var stop = JulianDate.fromTotalDays(1); + var start = new JulianDate(0); + var stop = new JulianDate(1); - var currentTime = JulianDate.fromTotalDays(1); + var currentTime = new JulianDate(1); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.CLAMPED; var multiplier = 100.0; @@ -362,10 +362,10 @@ defineSuite([ }); it('Tick dependant clock step stops at start animating backwards.', function() { - var start = JulianDate.fromTotalDays(0); - var stop = JulianDate.fromTotalDays(1); + var start = new JulianDate(0); + var stop = new JulianDate(1); - var currentTime = JulianDate.fromTotalDays(0); + var currentTime = new JulianDate(0); var step = ClockStep.TICK_DEPENDENT; var range = ClockRange.CLAMPED; var multiplier = -100.0; @@ -384,8 +384,8 @@ defineSuite([ }); it('throws if start time is after stop time.', function() { - var start = JulianDate.fromTotalDays(1); - var stop = JulianDate.fromTotalDays(0); + var start = new JulianDate(1); + var stop = new JulianDate(0); expect(function() { return new Clock({ startTime : start, diff --git a/Specs/Core/JulianDateSpec.js b/Specs/Core/JulianDateSpec.js index 259c10bea365..47adadecb440 100644 --- a/Specs/Core/JulianDateSpec.js +++ b/Specs/Core/JulianDateSpec.js @@ -19,6 +19,12 @@ defineSuite([ expect(defaultDate.secondsOfDay).toEqual(10); }); + it('Construct a date with fractional day', function() { + var julianDate = new JulianDate(2448257.75, 0, TimeStandard.UTC); + var expected = new JulianDate(2448257, 64826, TimeStandard.TAI); + expect(julianDate).toEqual(expected); + }); + it('Construct a date at the current time', function() { // Default constructing a date uses 'now'. Unfortunately, // there's no way to know exactly what that time will be, so we @@ -114,36 +120,30 @@ defineSuite([ it('Construct a date from a JavaScript Date (1)', function() { var date = new Date('January 1, 1991 06:00:00 UTC'); - var julianDate = JulianDate.fromDate(date, TimeStandard.TAI); - expect(JulianDate.getTotalDays(julianDate)).toEqualEpsilon(2448257.75, CesiumMath.EPSILON5); + var julianDate = JulianDate.fromDate(date); + expect(julianDate.dayNumber).toEqual(2448257); + expect(julianDate.secondsOfDay).toEqual(64826); }); it('Construct a date from a JavaScript Date (2)', function() { var date = new Date('July 4, 2011 12:00:00 UTC'); - var julianDate = JulianDate.fromDate(date, TimeStandard.TAI); - expect(JulianDate.getTotalDays(julianDate)).toEqualEpsilon(2455747.0, CesiumMath.EPSILON5); + var julianDate = JulianDate.fromDate(date); + expect(julianDate.dayNumber).toEqual(2455747); + expect(julianDate.secondsOfDay).toEqual(34); }); it('Construct a date from a JavaScript Date (3)', function() { var date = new Date('December 31, 2021 18:00:00 UTC'); - var julianDate = JulianDate.fromDate(date, TimeStandard.TAI); - expect(JulianDate.getTotalDays(julianDate)).toEqualEpsilon(2459580.25, CesiumMath.EPSILON5); + var julianDate = JulianDate.fromDate(date); + expect(julianDate.dayNumber).toEqual(2459580); + expect(julianDate.secondsOfDay).toEqual(21635); }); it('Construct a date from a JavaScript Date (4)', function() { var jsDate = new Date('September 1, 2011 12:00:00 UTC'); - var julianDate = JulianDate.fromDate(jsDate, TimeStandard.TAI); - expect(JulianDate.getTotalDays(julianDate)).toEqualEpsilon(2455806.0, CesiumMath.EPSILON5); - }); - - it('Construct a date from a JavaScript Date in different TimeStandard', function() { - var taiDate = new Date('September 1, 2012 12:00:35'); - var taiJulianDate = JulianDate.fromDate(taiDate, TimeStandard.TAI); - - var utcDate = new Date('September 1, 2012 12:00:00'); - var utcJulianDate = JulianDate.fromDate(utcDate, TimeStandard.UTC); - - expect(taiJulianDate.equalsEpsilon(utcJulianDate, CesiumMath.EPSILON20)).toEqual(true); + var julianDate = JulianDate.fromDate(jsDate); + expect(julianDate.dayNumber).toEqual(2455806); + expect(julianDate.secondsOfDay).toEqual(34); }); it('Fail to construct from an undefined JavaScript Date', function() { @@ -158,42 +158,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('Construct a date from total days (1)', function() { - var julianDate = JulianDate.fromTotalDays(2448257.75, TimeStandard.UTC); - var expected = JulianDate.fromDate(new Date('January 1, 1991 06:00:00 UTC')); - expect(julianDate).toEqual(expected); - }); - - it('Construct a date from total days (2)', function() { - var julianDate = JulianDate.fromTotalDays(2455747.0, TimeStandard.UTC); - var expected = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); - expect(julianDate).toEqual(expected); - }); - - it('Construct a date from total days (3)', function() { - var julianDate = JulianDate.fromTotalDays(2459580.25, TimeStandard.UTC); - var expected = JulianDate.fromDate(new Date('December 31, 2021 18:00:00 UTC')); - expect(julianDate).toEqual(expected); - }); - - it('Construct a date from total days with different time standards', function() { - var julianDate = JulianDate.fromTotalDays(2455806, TimeStandard.TAI); - var expected = JulianDate.fromDate(new Date('September 1, 2011 12:00:00 UTC'), TimeStandard.TAI); - expect(julianDate).toEqual(expected); - }); - - it('Fail to construct from non-numeric total days', function() { - expect(function() { - return JulianDate.fromTotalDays('not a number', TimeStandard.UTC); - }).toThrowDeveloperError(); - }); - - it('Fail to construct from undefined total days', function() { - expect(function() { - return JulianDate.fromTotalDays(undefined, TimeStandard.UTC); - }).toThrowDeveloperError(); - }); - it('Construct from ISO8601 local calendar date, basic format', function() { var expectedDate = JulianDate.fromDate(new Date(2009, 7, 1)); var computedDate = JulianDate.fromIso8601('20090801'); @@ -704,20 +668,8 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('toDate works when constructed from total days', function() { - var julianDate = JulianDate.fromTotalDays(2455770.9986087964, TimeStandard.UTC); - var javascriptDate = JulianDate.toDate(julianDate); - expect(javascriptDate.getUTCFullYear()).toEqual(2011); - expect(javascriptDate.getUTCMonth()).toEqual(6); - expect(javascriptDate.getUTCDate()).toEqual(28); - expect(javascriptDate.getUTCHours()).toEqual(11); - expect(javascriptDate.getUTCMinutes()).toEqual(57); - expect(javascriptDate.getUTCSeconds()).toEqual(59); - expect(javascriptDate.getUTCMilliseconds()).toEqualEpsilon(800, 10); - }); - it('toDate works when using TAI', function() { - var julianDateTai = JulianDate.fromTotalDays(2455927.157772, TimeStandard.UTC); + var julianDateTai = new JulianDate(2455927.157772, 0, TimeStandard.UTC); var javascriptDate = JulianDate.toDate(julianDateTai); expect(javascriptDate.getUTCFullYear()).toEqual(2011); expect(javascriptDate.getUTCMonth()).toEqual(11); @@ -979,8 +931,8 @@ defineSuite([ }); it('lessThan works with different time standards', function() { - var start = JulianDate.fromDate(new Date('July 6, 1991 12:00:00'), TimeStandard.UTC); - var end = JulianDate.fromDate(new Date('July 6, 2011 12:00:00'), TimeStandard.TAI); + var start = new JulianDate(0, 0, TimeStandard.TAI); + var end = new JulianDate(0, 0, TimeStandard.UTC); expect(JulianDate.lessThan(start, end)).toEqual(true); }); @@ -1006,8 +958,8 @@ defineSuite([ }); it('greaterThan works with different time standards', function() { - var start = JulianDate.fromDate(new Date('July 6, 2011 12:01:00'), TimeStandard.TAI); - var end = JulianDate.fromDate(new Date('July 6, 1991 12:00:00'), TimeStandard.UTC); + var start = new JulianDate(0, 0, TimeStandard.UTC); + var end = new JulianDate(0, 0, TimeStandard.TAI); expect(JulianDate.greaterThan(start, end)).toEqual(true); }); @@ -1028,7 +980,7 @@ defineSuite([ it('getTotalDays works', function() { var totalDays = 2455784.7500058; - var original = JulianDate.fromTotalDays(totalDays, TimeStandard.TAI); + var original = new JulianDate(totalDays, 0, TimeStandard.TAI); expect(totalDays).toEqual(JulianDate.getTotalDays(original)); }); @@ -1040,7 +992,7 @@ defineSuite([ it('getTaiMinusUtc works before all leap seconds', function() { var date = new Date('July 11, 1970 12:00:00 UTC'); - var jd = JulianDate.fromDate(date, TimeStandard.TAI); + var jd = JulianDate.fromDate(date); var difference = JulianDate.getTaiMinusUtc(jd); expect(difference).toEqual(10); }); diff --git a/Specs/Core/Simon1994PlanetaryPositionsSpec.js b/Specs/Core/Simon1994PlanetaryPositionsSpec.js index ffcd83dae823..380c2a5c46b1 100644 --- a/Specs/Core/Simon1994PlanetaryPositionsSpec.js +++ b/Specs/Core/Simon1994PlanetaryPositionsSpec.js @@ -22,7 +22,7 @@ defineSuite([ // Values for the X Y and Z were found using the STK Components GeometryTransformer on the position of the // sun center of mass point and the earth J2000 reference frame. it('computes correct sun position', function() { - var date = JulianDate.fromTotalDays(2451545.0, TimeStandard.TAI); + var date = new JulianDate(2451545, 0, TimeStandard.TAI); var sun = PlanetaryPositions.computeSunPositionInEarthInertialFrame(date); var X = 26500268539.790234; var Y = -132756447253.27325; @@ -31,7 +31,7 @@ defineSuite([ expect(Y).toEqualEpsilon(sun.y, CesiumMath.EPSILON2); expect(Z).toEqualEpsilon(sun.z, CesiumMath.EPSILON2); - date = JulianDate.fromTotalDays(2456401.5, TimeStandard.TAI); + date = new JulianDate(2456401.5, 0, TimeStandard.TAI); sun = PlanetaryPositions.computeSunPositionInEarthInertialFrame(date); X = 131512388940.33589; Y = 66661342667.949928; @@ -40,7 +40,7 @@ defineSuite([ expect(Y).toEqualEpsilon(sun.y, CesiumMath.EPSILON3); expect(Z).toEqualEpsilon(sun.z, CesiumMath.EPSILON3); - date = JulianDate.fromTotalDays(2455998.591667, TimeStandard.TAI); + date = new JulianDate(2455998.591667, 0, TimeStandard.TAI); sun = PlanetaryPositions.computeSunPositionInEarthInertialFrame(date); X = 147109989956.19534; Y = -19599996881.217579; @@ -53,7 +53,7 @@ defineSuite([ // Values for X Y and Z were found using the STK Components GeometryTransformer on the Simon 1994 moon point and the earth // J2000 reference frame. it('computes correct moon position', function() { - var date = JulianDate.fromTotalDays(2451545.0, TimeStandard.TAI); + var date = new JulianDate(2451545.0, 0, TimeStandard.TAI); var moon = PlanetaryPositions.computeMoonPositionInEarthInertialFrame(date); var X = -291632410.61232185; var Y = -266522146.36821631; @@ -62,7 +62,7 @@ defineSuite([ expect(Y).toEqualEpsilon(moon.y, CesiumMath.EPSILON4); expect(Z).toEqualEpsilon(moon.z, CesiumMath.EPSILON4); - date = JulianDate.fromTotalDays(2456401.5, TimeStandard.TAI); + date = new JulianDate(2456401.5, 0, TimeStandard.TAI); moon = PlanetaryPositions.computeMoonPositionInEarthInertialFrame(date); X = -223792974.4736526; Y = 315772435.34490639; @@ -71,7 +71,7 @@ defineSuite([ expect(Y).toEqualEpsilon(moon.y, CesiumMath.EPSILON4); expect(Z).toEqualEpsilon(moon.z, CesiumMath.EPSILON4); - date = JulianDate.fromTotalDays(2455998.591667, TimeStandard.TAI); + date = new JulianDate(2455998.591667, 0, TimeStandard.TAI); moon = PlanetaryPositions.computeMoonPositionInEarthInertialFrame(date); X = -268426117.00202647; Y = -220468861.73998192; diff --git a/Specs/Core/TimeIntervalCollectionSpec.js b/Specs/Core/TimeIntervalCollectionSpec.js index c359f7c5cb2d..4959cb052285 100644 --- a/Specs/Core/TimeIntervalCollectionSpec.js +++ b/Specs/Core/TimeIntervalCollectionSpec.js @@ -33,21 +33,21 @@ defineSuite([ it('contains works for a simple interval collection.', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, false); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, true); intervals.addInterval(interval1); intervals.addInterval(interval2); - expect(intervals.contains(JulianDate.fromTotalDays(0.5))).toEqual(false); - expect(intervals.contains(JulianDate.fromTotalDays(1.5))).toEqual(true); - expect(intervals.contains(JulianDate.fromTotalDays(2.0))).toEqual(false); - expect(intervals.contains(JulianDate.fromTotalDays(2.5))).toEqual(true); - expect(intervals.contains(JulianDate.fromTotalDays(3.0))).toEqual(true); - expect(intervals.contains(JulianDate.fromTotalDays(3.5))).toEqual(false); + expect(intervals.contains(new JulianDate(0.5))).toEqual(false); + expect(intervals.contains(new JulianDate(1.5))).toEqual(true); + expect(intervals.contains(new JulianDate(2.0))).toEqual(false); + expect(intervals.contains(new JulianDate(2.5))).toEqual(true); + expect(intervals.contains(new JulianDate(3.0))).toEqual(true); + expect(intervals.contains(new JulianDate(3.5))).toEqual(false); }); it('contains works for a endpoints of a closed interval collection.', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, true); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, true); intervals.addInterval(interval1); expect(intervals.contains(interval1.start)).toEqual(true); expect(intervals.contains(interval1.stop)).toEqual(true); @@ -55,7 +55,7 @@ defineSuite([ it('contains works for a endpoints of an open interval collection.', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), false, false); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), false, false); intervals.addInterval(interval1); expect(intervals.contains(interval1.start)).toEqual(false); expect(intervals.contains(interval1.stop)).toEqual(false); @@ -63,36 +63,36 @@ defineSuite([ it('indexOf finds the correct interval for a valid date', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, false); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, true); intervals.addInterval(interval1); intervals.addInterval(interval2); - expect(intervals.indexOf(JulianDate.fromTotalDays(2.5))).toEqual(1); + expect(intervals.indexOf(new JulianDate(2.5))).toEqual(1); }); it('indexOf returns complement of index of the interval that a missing date would come before', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, false); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, true); intervals.addInterval(interval1); intervals.addInterval(interval2); - expect(intervals.indexOf(JulianDate.fromTotalDays(2))).toEqual(~1); + expect(intervals.indexOf(new JulianDate(2))).toEqual(~1); }); it('indexOf returns complement of collection length if the date is after all intervals.', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, false); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, true); intervals.addInterval(interval1); intervals.addInterval(interval2); - expect(intervals.indexOf(JulianDate.fromTotalDays(4))).toEqual(~2); + expect(intervals.indexOf(new JulianDate(4))).toEqual(~2); }); it('get returns the interval at the correct index', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), false, false); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, false); - var interval3 = new TimeInterval(JulianDate.fromTotalDays(4), JulianDate.fromTotalDays(5), false, false); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), false, false); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, false); + var interval3 = new TimeInterval(new JulianDate(4), new JulianDate(5), false, false); intervals.addInterval(interval1); intervals.addInterval(interval2); intervals.addInterval(interval3); @@ -106,9 +106,9 @@ defineSuite([ it('findInterval works when looking for an exact interval', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(0), JulianDate.fromTotalDays(1), false, false, 1); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false, 2); - var interval3 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, false, 3); + var interval1 = new TimeInterval(new JulianDate(0), new JulianDate(1), false, false, 1); + var interval2 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, false, 2); + var interval3 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, false, 3); intervals.addInterval(interval1); intervals.addInterval(interval2); intervals.addInterval(interval3); @@ -117,9 +117,9 @@ defineSuite([ it('findInterval works when you do not care about end points', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(0), JulianDate.fromTotalDays(1), false, false, 1); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false, 2); - var interval3 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, false, 3); + var interval1 = new TimeInterval(new JulianDate(0), new JulianDate(1), false, false, 1); + var interval2 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, false, 2); + var interval3 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, false, 3); intervals.addInterval(interval1); intervals.addInterval(interval2); intervals.addInterval(interval3); @@ -128,8 +128,8 @@ defineSuite([ it('getStart & getStop return expected values.', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), true, false); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, false); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), true, false); intervals.addInterval(interval1); intervals.addInterval(interval2); expect(intervals.start).toEqual(interval1.start); @@ -138,7 +138,7 @@ defineSuite([ it('isEmpty and clear return expected values', function() { var intervals = new TimeIntervalCollection(); - intervals.addInterval(new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false)); + intervals.addInterval(new TimeInterval(new JulianDate(1), new JulianDate(2), true, false)); expect(intervals.empty).toEqual(false); intervals.removeAll(); expect(intervals.empty).toEqual(true); @@ -148,10 +148,10 @@ defineSuite([ var intervals = new TimeIntervalCollection(); expect(intervals.length).toEqual(0); - intervals.addInterval(new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true, 1)); + intervals.addInterval(new TimeInterval(new JulianDate(1), new JulianDate(4), true, true, 1)); expect(intervals.length).toEqual(1); - intervals.addInterval(new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), true, true, 2)); + intervals.addInterval(new TimeInterval(new JulianDate(2), new JulianDate(3), true, true, 2)); expect(intervals.length).toEqual(3); intervals.removeAll(); @@ -161,10 +161,10 @@ defineSuite([ it('length returns the correct length after two intervals with the same data are merged.', function() { var intervals = new TimeIntervalCollection(); - intervals.addInterval(new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true, 1)); + intervals.addInterval(new TimeInterval(new JulianDate(1), new JulianDate(4), true, true, 1)); expect(intervals.length).toEqual(1); - intervals.addInterval(new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), true, true, 1)); + intervals.addInterval(new TimeInterval(new JulianDate(2), new JulianDate(3), true, true, 1)); expect(intervals.length).toEqual(1); intervals.removeAll(); @@ -172,9 +172,9 @@ defineSuite([ }); it('addInterval and findIntervalContainingDate work when using non-overlapping intervals', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, true, 1); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true, 2); - var interval3 = new TimeInterval(JulianDate.fromTotalDays(4), JulianDate.fromTotalDays(5), true, true, 3); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, true, 1); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, true, 2); + var interval3 = new TimeInterval(new JulianDate(4), new JulianDate(5), true, true, 3); var intervals = new TimeIntervalCollection(); @@ -212,8 +212,8 @@ defineSuite([ }); it('addInterval and findIntervalContainingDate work when using overlapping intervals', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2.5), true, true, 1); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true, 2); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2.5), true, true, 1); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, true, 2); var interval3 = new TimeInterval(interval1.start, interval2.stop, true, true, 3); var intervals = new TimeIntervalCollection(); @@ -253,8 +253,8 @@ defineSuite([ }); it('findDataForIntervalContainingDate works', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2.5), true, true, 1); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true, 2); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2.5), true, true, 1); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, true, 2); var intervals = new TimeIntervalCollection(); intervals.addInterval(interval1); @@ -266,16 +266,16 @@ defineSuite([ expect(intervals.findDataForIntervalContainingDate(interval1.stop)).toEqual(2); expect(intervals.findDataForIntervalContainingDate(interval2.stop)).toEqual(2); - expect(intervals.findDataForIntervalContainingDate(JulianDate.fromTotalDays(5))).toBeUndefined(); + expect(intervals.findDataForIntervalContainingDate(new JulianDate(5))).toBeUndefined(); }); it('addInterval correctly intervals that have the same data when using equalsCallback', function() { var intervals = new TimeIntervalCollection(); - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true, new TestObject(2)); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(3), true, false, new TestObject(2)); - var interval3 = new TimeInterval(JulianDate.fromTotalDays(3), JulianDate.fromTotalDays(4), false, true, new TestObject(2)); - var interval4 = new TimeInterval(JulianDate.fromTotalDays(3), JulianDate.fromTotalDays(4), true, true, new TestObject(3)); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(4), true, true, new TestObject(2)); + var interval2 = new TimeInterval(new JulianDate(1), new JulianDate(3), true, false, new TestObject(2)); + var interval3 = new TimeInterval(new JulianDate(3), new JulianDate(4), false, true, new TestObject(2)); + var interval4 = new TimeInterval(new JulianDate(3), new JulianDate(4), true, true, new TestObject(3)); intervals.addInterval(interval1, TestObject.equals); expect(intervals.length).toEqual(1); @@ -314,8 +314,8 @@ defineSuite([ it('removeInterval leaves a hole', function() { var intervals = new TimeIntervalCollection(); - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true); - var removedInterval = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), true, false); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(4), true, true); + var removedInterval = new TimeInterval(new JulianDate(2), new JulianDate(3), true, false); intervals.addInterval(interval); expect(intervals.removeInterval(removedInterval)).toEqual(true); @@ -333,7 +333,7 @@ defineSuite([ it('removeInterval with an interval of the exact same size works..', function() { var intervals = new TimeIntervalCollection(); - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, false); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(4), true, false); intervals.addInterval(interval); expect(intervals.length).toEqual(1); @@ -348,7 +348,7 @@ defineSuite([ it('removeInterval with an empty interval has no affect.', function() { var intervals = new TimeIntervalCollection(); - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(4), true, true); intervals.addInterval(interval); expect(intervals.length).toEqual(1); @@ -369,8 +369,8 @@ defineSuite([ it('removeInterval takes isStartIncluded and isStopIncluded into account', function() { var intervals = new TimeIntervalCollection(); - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true); - var removedInterval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), false, false); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(4), true, true); + var removedInterval = new TimeInterval(new JulianDate(1), new JulianDate(4), false, false); intervals.addInterval(interval); expect(intervals.removeInterval(removedInterval)).toEqual(true); @@ -388,24 +388,24 @@ defineSuite([ it('intersectInterval works with an empty interval', function() { var intervals = new TimeIntervalCollection(); - intervals.addInterval(new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true)); + intervals.addInterval(new TimeInterval(new JulianDate(1), new JulianDate(4), true, true)); intervals = intervals.intersectInterval(TimeInterval.EMPTY); expect(intervals.length).toEqual(0); }); it('intersectInterval works non-overlapping intervals', function() { var leftIntervals = new TimeIntervalCollection(); - leftIntervals.addInterval(new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false)); + leftIntervals.addInterval(new TimeInterval(new JulianDate(1), new JulianDate(2), true, false)); var rightIntervals = new TimeIntervalCollection(); - rightIntervals.addInterval(new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), true, true)); + rightIntervals.addInterval(new TimeInterval(new JulianDate(2), new JulianDate(3), true, true)); expect(leftIntervals.intersectInterval(rightIntervals).length).toEqual(0); }); it('intersectInterval works with intersecting intervals an no merge callback', function() { var intervals = new TimeIntervalCollection(); - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true); - var intersectInterval = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, false); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(4), true, true); + var intersectInterval = new TimeInterval(new JulianDate(2), new JulianDate(3), false, false); intervals.addInterval(interval); var intersectedIntervals = intervals.intersectInterval(intersectInterval); @@ -420,8 +420,8 @@ defineSuite([ it('intersectInterval works with intersecting intervals an a merge callback', function() { var intervals = new TimeIntervalCollection(); - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true, new TestObject(1)); - var intersectInterval = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, false, new TestObject(2)); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(4), true, true, new TestObject(1)); + var intersectInterval = new TimeInterval(new JulianDate(2), new JulianDate(3), false, false, new TestObject(2)); intervals.addInterval(interval); var intersectedIntervals = intervals.intersectInterval(intersectInterval, TestObject.equals, TestObject.merge); @@ -436,11 +436,11 @@ defineSuite([ it('intersect works with intersecting intervals an a merge callback', function() { var intervals = new TimeIntervalCollection(); - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(4), true, true, new TestObject(1)); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(4), true, true, new TestObject(1)); intervals.addInterval(interval); var intervals2 = new TimeIntervalCollection(); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, false, new TestObject(2)); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, false, new TestObject(2)); intervals2.addInterval(interval2); var intersectedIntervals = intervals.intersect(intervals2, TestObject.equals, TestObject.merge); @@ -454,9 +454,9 @@ defineSuite([ }); it('equals works without data', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, true); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true); - var interval3 = new TimeInterval(JulianDate.fromTotalDays(4), JulianDate.fromTotalDays(5), true, true); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2), true, true); + var interval2 = new TimeInterval(new JulianDate(2), new JulianDate(3), false, true); + var interval3 = new TimeInterval(new JulianDate(4), new JulianDate(5), true, true); var left = new TimeIntervalCollection(); left.addInterval(interval1); @@ -472,14 +472,14 @@ defineSuite([ it('equals works with data', function() { var left = new TimeIntervalCollection(); - left.addInterval(new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, true, {})); - left.addInterval(new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true, {})); - left.addInterval(new TimeInterval(JulianDate.fromTotalDays(4), JulianDate.fromTotalDays(5), true, true, {})); + left.addInterval(new TimeInterval(new JulianDate(1), new JulianDate(2), true, true, {})); + left.addInterval(new TimeInterval(new JulianDate(2), new JulianDate(3), false, true, {})); + left.addInterval(new TimeInterval(new JulianDate(4), new JulianDate(5), true, true, {})); var right = new TimeIntervalCollection(); - right.addInterval(new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, true, {})); - right.addInterval(new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true, {})); - right.addInterval(new TimeInterval(JulianDate.fromTotalDays(4), JulianDate.fromTotalDays(5), true, true, {})); + right.addInterval(new TimeInterval(new JulianDate(1), new JulianDate(2), true, true, {})); + right.addInterval(new TimeInterval(new JulianDate(2), new JulianDate(3), false, true, {})); + right.addInterval(new TimeInterval(new JulianDate(4), new JulianDate(5), true, true, {})); expect(left.equals(right)).toEqual(false); diff --git a/Specs/Core/TimeIntervalSpec.js b/Specs/Core/TimeIntervalSpec.js index 8de82fcab65c..e36103d311f6 100644 --- a/Specs/Core/TimeIntervalSpec.js +++ b/Specs/Core/TimeIntervalSpec.js @@ -51,67 +51,67 @@ defineSuite([ }); it('IsEmpty is false for a typical interval', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2)); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(2)); expect(interval.isEmpty).toEqual(false); }); it('IsEmpty is false for an instantaneous interval closed on both ends', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(1)); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(1)); expect(interval.isEmpty).toEqual(false); }); it('IsEmpty is true for an instantaneous interval open on both ends', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(1), false, false); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(1), false, false); expect(interval.isEmpty).toEqual(true); }); it('IsEmpty is true for an interval with stop before start', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(5), JulianDate.fromTotalDays(4)); + var interval = new TimeInterval(new JulianDate(5), new JulianDate(4)); expect(interval.isEmpty).toEqual(true); }); it('IsEmpty is true for an instantaneous interval only closed on stop end', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(5), JulianDate.fromTotalDays(5), false, true); + var interval = new TimeInterval(new JulianDate(5), new JulianDate(5), false, true); expect(interval.isEmpty).toEqual(true); }); it('IsEmpty is true for an instantaneous interval only closed on start end', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(5), JulianDate.fromTotalDays(5), true, false); + var interval = new TimeInterval(new JulianDate(5), new JulianDate(5), true, false); expect(interval.isEmpty).toEqual(true); }); it('Contains works for a typical interval.', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(2451545), JulianDate.fromTotalDays(2451546), true, true); - expect(interval1.contains(JulianDate.fromTotalDays(2451545.5))).toEqual(true); - expect(interval1.contains(JulianDate.fromTotalDays(2451546.5))).toEqual(false); + var interval1 = new TimeInterval(new JulianDate(2451545), new JulianDate(2451546), true, true); + expect(interval1.contains(new JulianDate(2451545.5))).toEqual(true); + expect(interval1.contains(new JulianDate(2451546.5))).toEqual(false); }); it('Contains works for an empty interval.', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(2451545), JulianDate.fromTotalDays(2451545), false, false); - expect(interval1.contains(JulianDate.fromTotalDays(2451545))).toEqual(false); + var interval1 = new TimeInterval(new JulianDate(2451545), new JulianDate(2451545), false, false); + expect(interval1.contains(new JulianDate(2451545))).toEqual(false); }); it('Contains returns true at start and stop times of a closed interval', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(2451545), JulianDate.fromTotalDays(2451546), true, true); - expect(interval1.contains(JulianDate.fromTotalDays(2451545))).toEqual(true); - expect(interval1.contains(JulianDate.fromTotalDays(2451546))).toEqual(true); + var interval1 = new TimeInterval(new JulianDate(2451545), new JulianDate(2451546), true, true); + expect(interval1.contains(new JulianDate(2451545))).toEqual(true); + expect(interval1.contains(new JulianDate(2451546))).toEqual(true); }); it('Contains returns false at start and stop times of an open interval', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(2451545), JulianDate.fromTotalDays(2451546), false, false); - expect(interval.contains(JulianDate.fromTotalDays(2451545))).toEqual(false); - expect(interval.contains(JulianDate.fromTotalDays(2451546))).toEqual(false); + var interval = new TimeInterval(new JulianDate(2451545), new JulianDate(2451546), false, false); + expect(interval.contains(new JulianDate(2451545))).toEqual(false); + expect(interval.contains(new JulianDate(2451546))).toEqual(false); }); it('equals and equalsEpsilon return true for identical time intervals', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2)); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2)); var interval2 = interval1.clone(); expect(interval1.equals(interval2)).toEqual(true); expect(interval1.equalsEpsilon(interval2, 0)).toEqual(true); }); it('equals and equalsEpsilon return true for identical time intervals with data', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2)); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2)); interval1.data = {}; var interval2 = interval1.clone(); interval2.data = {}; @@ -129,26 +129,26 @@ defineSuite([ it('equals and equalsEpsilon return false for non-identical time intervals', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2)); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(1.5), JulianDate.fromTotalDays(2)); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2)); + var interval2 = new TimeInterval(new JulianDate(1.5), new JulianDate(2)); expect(interval1.equals(interval2)).toEqual(false); expect(interval1.equalsEpsilon(interval2, 0)).toEqual(false); }); it('equalsEpsilon true for non-identical time intervals within threshold', function() { - var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2)); - var interval2 = new TimeInterval(JulianDate.fromTotalDays(1.5), JulianDate.fromTotalDays(2)); + var interval1 = new TimeInterval(new JulianDate(1), new JulianDate(2)); + var interval2 = new TimeInterval(new JulianDate(1.5), new JulianDate(2)); expect(interval1.equalsEpsilon(interval2, 86400)).toEqual(true); }); it('equals and equalsEpsilon return false for undefined', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(1), true, true); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(1), true, true); expect(interval.equals(undefined)).toEqual(false); expect(interval.equalsEpsilon(undefined, 1.0)).toEqual(false); }); it('static equals and equalsEpsilon return false for undefined', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(1), true, true); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(1), true, true); expect(TimeInterval.equals(undefined, interval)).toEqual(false); expect(TimeInterval.equalsEpsilon(undefined, interval, 1.0)).toEqual(false); expect(TimeInterval.equals(interval, undefined)).toEqual(false); @@ -156,44 +156,44 @@ defineSuite([ }); it('clone returns an identical interval', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false, 12); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(2), true, false, 12); expect(interval.clone()).toEqual(interval); }); it('intersect properly intersects with an exhaustive set of cases', function() { - var testParameters = [new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2.5), true, true), - new TimeInterval(JulianDate.fromTotalDays(1.5), JulianDate.fromTotalDays(2), true, true), - new TimeInterval(JulianDate.fromTotalDays(1.5), JulianDate.fromTotalDays(2), true, true), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2.5), true, true), - new TimeInterval(JulianDate.fromTotalDays(3), JulianDate.fromTotalDays(4), true, true), - new TimeInterval(JulianDate.fromTotalDays(0), JulianDate.fromTotalDays(0), false, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2.5), true, true), - new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), true, true), - new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(2.5), true, true), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, true), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), false, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), false, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), false, true), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), false, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(3), false, false), - new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(4), false, false), - new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(3), false, false), - new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(4), true, true), - new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), true, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(1), false, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2), true, true), - new TimeInterval(JulianDate.fromTotalDays(0), JulianDate.fromTotalDays(0), false, false), - new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(3), true, true), - new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), true, true), - new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), true, true), - new TimeInterval(JulianDate.fromTotalDays(3), JulianDate.fromTotalDays(2), true, true), - new TimeInterval(JulianDate.fromTotalDays(3), JulianDate.fromTotalDays(3), true, true), - new TimeInterval(JulianDate.fromTotalDays(0), JulianDate.fromTotalDays(0), false, false)]; + var testParameters = [new TimeInterval(new JulianDate(1), new JulianDate(2.5), true, true), + new TimeInterval(new JulianDate(1.5), new JulianDate(2), true, true), + new TimeInterval(new JulianDate(1.5), new JulianDate(2), true, true), + new TimeInterval(new JulianDate(1), new JulianDate(2.5), true, true), + new TimeInterval(new JulianDate(3), new JulianDate(4), true, true), + new TimeInterval(new JulianDate(0), new JulianDate(0), false, false), + new TimeInterval(new JulianDate(1), new JulianDate(2.5), true, true), + new TimeInterval(new JulianDate(2), new JulianDate(3), true, true), + new TimeInterval(new JulianDate(2), new JulianDate(2.5), true, true), + new TimeInterval(new JulianDate(1), new JulianDate(2), true, true), + new TimeInterval(new JulianDate(1), new JulianDate(2), false, false), + new TimeInterval(new JulianDate(1), new JulianDate(2), false, false), + new TimeInterval(new JulianDate(1), new JulianDate(2), true, false), + new TimeInterval(new JulianDate(1), new JulianDate(2), false, true), + new TimeInterval(new JulianDate(1), new JulianDate(2), false, false), + new TimeInterval(new JulianDate(1), new JulianDate(2), true, false), + new TimeInterval(new JulianDate(1), new JulianDate(2), true, false), + new TimeInterval(new JulianDate(1), new JulianDate(2), true, false), + new TimeInterval(new JulianDate(1), new JulianDate(3), false, false), + new TimeInterval(new JulianDate(2), new JulianDate(4), false, false), + new TimeInterval(new JulianDate(2), new JulianDate(3), false, false), + new TimeInterval(new JulianDate(1), new JulianDate(3), false, false), + new TimeInterval(new JulianDate(2), new JulianDate(4), true, true), + new TimeInterval(new JulianDate(2), new JulianDate(3), true, false), + new TimeInterval(new JulianDate(1), new JulianDate(1), false, false), + new TimeInterval(new JulianDate(1), new JulianDate(2), true, true), + new TimeInterval(new JulianDate(0), new JulianDate(0), false, false), + new TimeInterval(new JulianDate(1), new JulianDate(3), true, true), + new TimeInterval(new JulianDate(2), new JulianDate(3), true, true), + new TimeInterval(new JulianDate(2), new JulianDate(3), true, true), + new TimeInterval(new JulianDate(3), new JulianDate(2), true, true), + new TimeInterval(new JulianDate(3), new JulianDate(3), true, true), + new TimeInterval(new JulianDate(0), new JulianDate(0), false, false)]; for ( var i = 0; i < testParameters.length - 2; i = i + 3) { var first = testParameters[i]; @@ -208,13 +208,13 @@ defineSuite([ }); it('intersect with undefined results in an empty interval.', function() { - var interval = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2)); + var interval = new TimeInterval(new JulianDate(1), new JulianDate(2)); expect(interval.intersect(undefined)).toEqual(TimeInterval.EMPTY); }); it('intersect with a merge callback properly merges data.', function() { - var oneToThree = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(3), true, true, 2); - var twoToFour = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(4), true, true, 3); + var oneToThree = new TimeInterval(new JulianDate(1), new JulianDate(3), true, true, 2); + var twoToFour = new TimeInterval(new JulianDate(2), new JulianDate(4), true, true, 3); var twoToThree = oneToThree.intersect(twoToFour, mergeByAdd); expect(twoToThree.start).toEqual(twoToFour.start); expect(twoToThree.stop).toEqual(oneToThree.stop); From 25a7075aa41aaba9aaf08d0129094c08ad76a882 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Wed, 11 Jun 2014 12:03:15 -0400 Subject: [PATCH 04/11] Refactor LeapSecond to be a simply data object. 1. Removes the need for circular referneces between `LeapSecond` and `JulianDate`. 2. Moves array of leap seconds from `LeapSecond.leapSeconds` to `JulianDate.leapSeconds` --- Source/Core/EarthOrientationParameters.js | 2 +- Source/Core/JulianDate.js | 98 ++++++++--------- Source/Core/LeapSecond.js | 109 +------------------ Specs/Core/EarthOrientationParametersSpec.js | 8 +- Specs/Core/LeapSecondSpec.js | 72 ++---------- 5 files changed, 69 insertions(+), 220 deletions(-) diff --git a/Source/Core/EarthOrientationParameters.js b/Source/Core/EarthOrientationParameters.js index bc7df3a8ef2f..6d7236a8f748 100644 --- a/Source/Core/EarthOrientationParameters.js +++ b/Source/Core/EarthOrientationParameters.js @@ -288,7 +288,7 @@ define([ if (taiMinusUtc !== lastTaiMinusUtc && defined(lastTaiMinusUtc)) { // We crossed a leap second boundary, so add the leap second // if it does not already exist. - var leapSeconds = LeapSecond._leapSeconds; + var leapSeconds = JulianDate.leapSeconds; var leapSecondIndex = binarySearch(leapSeconds, date, compareLeapSecondDates); if (leapSecondIndex < 0) { var leapSecond = new LeapSecond(date, taiMinusUtc); diff --git a/Source/Core/JulianDate.js b/Source/Core/JulianDate.js index 18722fe59021..71355a470bd1 100644 --- a/Source/Core/JulianDate.js +++ b/Source/Core/JulianDate.js @@ -4,8 +4,10 @@ define([ './binarySearch', './defaultValue', './defined', + './defineProperties', './DeveloperError', './GregorianDate', + './isArray', './isLeapYear', './LeapSecond', './TimeConstants', @@ -15,8 +17,10 @@ define([ binarySearch, defaultValue, defined, + defineProperties, DeveloperError, GregorianDate, + isArray, isLeapYear, LeapSecond, TimeConstants, @@ -27,17 +31,20 @@ define([ var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; var daysInLeapFeburary = 29; + + function compareLeapSecondDates(leapSecond, dateToFind) { + return JulianDate.compare(leapSecond.julianDate, dateToFind.julianDate); + } + // we don't really need a leap second instance, anything with a julianDate property will do - var binarySearchScratchLeapSecond = { - julianDate : undefined - }; + var binarySearchScratchLeapSecond = new LeapSecond(); function convertUtcToTai(julianDate) { //Even though julianDate is in UTC, we'll treat it as TAI and //search the leap second table for it. binarySearchScratchLeapSecond.julianDate = julianDate; - var leapSeconds = LeapSecond._leapSeconds; - var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, LeapSecond.compareLeapSecondDate); + var leapSeconds = JulianDate.leapSeconds; + var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, compareLeapSecondDates); if (index < 0) { index = ~index; @@ -65,8 +72,8 @@ define([ function convertTaiToUtc(julianDate, result) { binarySearchScratchLeapSecond.julianDate = julianDate; - var leapSeconds = LeapSecond._leapSeconds; - var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, LeapSecond.compareLeapSecondDate); + var leapSeconds = JulianDate.leapSeconds; + var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, compareLeapSecondDates); if (index < 0) { index = ~index; } @@ -808,8 +815,8 @@ define([ */ JulianDate.getTaiMinusUtc = function(julianDate) { binarySearchScratchLeapSecond.julianDate = julianDate; - var leapSeconds = LeapSecond._leapSeconds; - var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, LeapSecond.compareLeapSecondDate); + var leapSeconds = JulianDate.leapSeconds; + var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, compareLeapSecondDates); if (index < 0) { index = ~index; --index; @@ -1000,49 +1007,38 @@ define([ }; /** - * Compares this date to another date. - * - * @param {JulianDate} other The other JulianDate to compare to. - * @returns {Number} A negative value if this instance is less than the other, - * a positive value if this instance is greater than the other, - * or zero if this instance and the other are equal. + * Gets or sets the list of leap seconds used throughout Cesium. + * @memberof JulianDate + * @type {LeapSecond[]} */ - JulianDate.prototype.compareTo = function(other) { - return JulianDate.compare(this, other); - }; - - //To avoid circular dependencies, we load the default list of leap seconds - //here, rather than in the LeapSecond class itself. - if (LeapSecond._leapSeconds.length === 0) { - LeapSecond._leapSeconds = [ - new LeapSecond(new JulianDate(2441317, 43210.0, TimeStandard.TAI), 10), // January 1, 1972 00:00:00 UTC - new LeapSecond(new JulianDate(2441499, 43211.0, TimeStandard.TAI), 11), // July 1, 1972 00:00:00 UTC - new LeapSecond(new JulianDate(2441683, 43212.0, TimeStandard.TAI), 12), // January 1, 1973 00:00:00 UTC - new LeapSecond(new JulianDate(2442048, 43213.0, TimeStandard.TAI), 13), // January 1, 1974 00:00:00 UTC - new LeapSecond(new JulianDate(2442413, 43214.0, TimeStandard.TAI), 14), // January 1, 1975 00:00:00 UTC - new LeapSecond(new JulianDate(2442778, 43215.0, TimeStandard.TAI), 15), // January 1, 1976 00:00:00 UTC - new LeapSecond(new JulianDate(2443144, 43216.0, TimeStandard.TAI), 16), // January 1, 1977 00:00:00 UTC - new LeapSecond(new JulianDate(2443509, 43217.0, TimeStandard.TAI), 17), // January 1, 1978 00:00:00 UTC - new LeapSecond(new JulianDate(2443874, 43218.0, TimeStandard.TAI), 18), // January 1, 1979 00:00:00 UTC - new LeapSecond(new JulianDate(2444239, 43219.0, TimeStandard.TAI), 19), // January 1, 1980 00:00:00 UTC - new LeapSecond(new JulianDate(2444786, 43220.0, TimeStandard.TAI), 20), // July 1, 1981 00:00:00 UTC - new LeapSecond(new JulianDate(2445151, 43221.0, TimeStandard.TAI), 21), // July 1, 1982 00:00:00 UTC - new LeapSecond(new JulianDate(2445516, 43222.0, TimeStandard.TAI), 22), // July 1, 1983 00:00:00 UTC - new LeapSecond(new JulianDate(2446247, 43223.0, TimeStandard.TAI), 23), // July 1, 1985 00:00:00 UTC - new LeapSecond(new JulianDate(2447161, 43224.0, TimeStandard.TAI), 24), // January 1, 1988 00:00:00 UTC - new LeapSecond(new JulianDate(2447892, 43225.0, TimeStandard.TAI), 25), // January 1, 1990 00:00:00 UTC - new LeapSecond(new JulianDate(2448257, 43226.0, TimeStandard.TAI), 26), // January 1, 1991 00:00:00 UTC - new LeapSecond(new JulianDate(2448804, 43227.0, TimeStandard.TAI), 27), // July 1, 1992 00:00:00 UTC - new LeapSecond(new JulianDate(2449169, 43228.0, TimeStandard.TAI), 28), // July 1, 1993 00:00:00 UTC - new LeapSecond(new JulianDate(2449534, 43229.0, TimeStandard.TAI), 29), // July 1, 1994 00:00:00 UTC - new LeapSecond(new JulianDate(2450083, 43230.0, TimeStandard.TAI), 30), // January 1, 1996 00:00:00 UTC - new LeapSecond(new JulianDate(2450630, 43231.0, TimeStandard.TAI), 31), // July 1, 1997 00:00:00 UTC - new LeapSecond(new JulianDate(2451179, 43232.0, TimeStandard.TAI), 32), // January 1, 1999 00:00:00 UTC - new LeapSecond(new JulianDate(2453736, 43233.0, TimeStandard.TAI), 33), // January 1, 2006 00:00:00 UTC - new LeapSecond(new JulianDate(2454832, 43234.0, TimeStandard.TAI), 34), // January 1, 2009 00:00:00 UTC - new LeapSecond(new JulianDate(2456109, 43235.0, TimeStandard.TAI), 35) // July 1, 2012 00:00:00 UTC - ]; - } + JulianDate.leapSeconds = [ + new LeapSecond(new JulianDate(2441317, 43210.0, TimeStandard.TAI), 10), // January 1, 1972 00:00:00 UTC + new LeapSecond(new JulianDate(2441499, 43211.0, TimeStandard.TAI), 11), // July 1, 1972 00:00:00 UTC + new LeapSecond(new JulianDate(2441683, 43212.0, TimeStandard.TAI), 12), // January 1, 1973 00:00:00 UTC + new LeapSecond(new JulianDate(2442048, 43213.0, TimeStandard.TAI), 13), // January 1, 1974 00:00:00 UTC + new LeapSecond(new JulianDate(2442413, 43214.0, TimeStandard.TAI), 14), // January 1, 1975 00:00:00 UTC + new LeapSecond(new JulianDate(2442778, 43215.0, TimeStandard.TAI), 15), // January 1, 1976 00:00:00 UTC + new LeapSecond(new JulianDate(2443144, 43216.0, TimeStandard.TAI), 16), // January 1, 1977 00:00:00 UTC + new LeapSecond(new JulianDate(2443509, 43217.0, TimeStandard.TAI), 17), // January 1, 1978 00:00:00 UTC + new LeapSecond(new JulianDate(2443874, 43218.0, TimeStandard.TAI), 18), // January 1, 1979 00:00:00 UTC + new LeapSecond(new JulianDate(2444239, 43219.0, TimeStandard.TAI), 19), // January 1, 1980 00:00:00 UTC + new LeapSecond(new JulianDate(2444786, 43220.0, TimeStandard.TAI), 20), // July 1, 1981 00:00:00 UTC + new LeapSecond(new JulianDate(2445151, 43221.0, TimeStandard.TAI), 21), // July 1, 1982 00:00:00 UTC + new LeapSecond(new JulianDate(2445516, 43222.0, TimeStandard.TAI), 22), // July 1, 1983 00:00:00 UTC + new LeapSecond(new JulianDate(2446247, 43223.0, TimeStandard.TAI), 23), // July 1, 1985 00:00:00 UTC + new LeapSecond(new JulianDate(2447161, 43224.0, TimeStandard.TAI), 24), // January 1, 1988 00:00:00 UTC + new LeapSecond(new JulianDate(2447892, 43225.0, TimeStandard.TAI), 25), // January 1, 1990 00:00:00 UTC + new LeapSecond(new JulianDate(2448257, 43226.0, TimeStandard.TAI), 26), // January 1, 1991 00:00:00 UTC + new LeapSecond(new JulianDate(2448804, 43227.0, TimeStandard.TAI), 27), // July 1, 1992 00:00:00 UTC + new LeapSecond(new JulianDate(2449169, 43228.0, TimeStandard.TAI), 28), // July 1, 1993 00:00:00 UTC + new LeapSecond(new JulianDate(2449534, 43229.0, TimeStandard.TAI), 29), // July 1, 1994 00:00:00 UTC + new LeapSecond(new JulianDate(2450083, 43230.0, TimeStandard.TAI), 30), // January 1, 1996 00:00:00 UTC + new LeapSecond(new JulianDate(2450630, 43231.0, TimeStandard.TAI), 31), // July 1, 1997 00:00:00 UTC + new LeapSecond(new JulianDate(2451179, 43232.0, TimeStandard.TAI), 32), // January 1, 1999 00:00:00 UTC + new LeapSecond(new JulianDate(2453736, 43233.0, TimeStandard.TAI), 33), // January 1, 2006 00:00:00 UTC + new LeapSecond(new JulianDate(2454832, 43234.0, TimeStandard.TAI), 34), // January 1, 2009 00:00:00 UTC + new LeapSecond(new JulianDate(2456109, 43235.0, TimeStandard.TAI), 35) // July 1, 2012 00:00:00 UTC + ]; return JulianDate; }); diff --git a/Source/Core/LeapSecond.js b/Source/Core/LeapSecond.js index cc3c568dc5f1..a4ff1ad870a5 100644 --- a/Source/Core/LeapSecond.js +++ b/Source/Core/LeapSecond.js @@ -1,129 +1,30 @@ /*global define*/ -define([ - './defined', - './defineProperties', - './DeveloperError', - './isArray' - ], function( - defined, - defineProperties, - DeveloperError, - isArray) { +define(function() { "use strict"; /** * Describes a single leap second, which is constructed from a {@link JulianDate} and a * numerical offset representing the number of seconds TAI is ahead of the UTC time standard. - * * @alias LeapSecond * @constructor * - * @param {JulianDate} date A Julian date representing the time of the leap second. - * @param {Number} offset The cumulative number of seconds, that TAI is ahead of UTC at provided date. - * - * @see JulianDate - * @see TimeStandard - * - * @example - * // Example 1. Construct a LeapSecond using a JulianDate - * var date = new Date('January 1, 1990 00:00:00 UTC'); - * var leapSecond = new Cesium.LeapSecond(Cesium.JulianDate.fromDate(date), 25.0); - * var offset = leapSecond.offset; // 25.0 - * - * @example - * // Example 2. Construct a LeapSecond using a date string - * var date = 'January 1, 1990 00:00:00 UTC'; - * var leapSecond = new LeapSecond(date, 25.0); + * @param {JulianDate} [date] A Julian date representing the time of the leap second. + * @param {Number} [offset] The cumulative number of seconds that TAI is ahead of UTC at the provided date. */ var LeapSecond = function(date, offset) { - //>>includeStart('debug', pragmas.debug); - if (!defined(date)) { - throw new DeveloperError('date is required.'); - } - if (offset === null || isNaN(offset)) { - throw new DeveloperError('offset is required and must be a number.'); - } - //>>includeEnd('debug'); - /** - * The Julian date at which this leap second occurs. - * + * Gets or sets the date at which this leap second occurs. * @type {JulianDate} */ this.julianDate = date; /** - * The cumulative number of seconds between the UTC and TAI time standards at the time + * Gets or sets the cumulative number of seconds between the UTC and TAI time standards at the time * of this leap second. - * * @type {Number} */ this.offset = offset; }; - defineProperties(LeapSecond, { - /** - * The list of leap seconds used throughout Cesium. - * @memberof LeapSecond - * @type {LeapSecond[]} - */ - leapSeconds: { - get: function() { - return LeapSecond._leapSeconds; - }, - set: function(leapSeconds) { - //>>includeStart('debug', pragmas.debug); - if (!isArray(leapSeconds)) { - throw new DeveloperError("leapSeconds is required and must be an array."); - } - //>>includeEnd('debug'); - - LeapSecond._leapSeconds = leapSeconds; - LeapSecond._leapSeconds.sort(LeapSecond.compareLeapSecondDate); - } - } - }); - - /** - * Checks whether two leap seconds are equivalent to each other. - * - * @param {LeapSecond} other The leap second to compare against. - * @returns {Boolean} true if the leap seconds are equal; otherwise, false. - * - * @example - * var date = new Date('January 1, 1990 00:00:00 UTC'); - * var leapSecond1 = new Cesium.LeapSecond(Cesium.JulianDate.fromDate(date), 25.0); - * var leapSecond2 = new Cesium.LeapSecond(Cesium.JulianDate.fromDate(date), 25.0); - * leapSecond1.equals(leapSecond2); // true - */ - LeapSecond.prototype.equals = function(other) { - return this.julianDate.equals(other.julianDate) && (this.offset === other.offset); - }; - - /** - * Given two leap seconds, determines which comes before the other by comparing - * their respective Julian dates. - * - * @param {LeapSecond} leapSecond1 The first leap second to be compared. - * @param {LeapSecond} leapSecond2 The second leap second to be compared. - * @returns {Number} A negative value if the first leap second is earlier than the second, - * a positive value if the first leap second is later than the second, or - * zero if the two leap seconds are equal (ignoring their offsets). - * - * @see JulianDate#lessThan - * @see JulianDate#isAfter - * - * @example - * var date = new Date('January 1, 2006 00:00:00 UTC'); - * var leapSecond1 = new Cesium.LeapSecond(Cesium.JulianDate.fromDate(date), 33.0); - * var leapSecond2 = new Cesium.LeapSecond(Cesium.JulianDate.fromDate(date), 34.0); - * Cesium.LeapSecond.compareLeapSecondDate(leapSecond1, leapSecond2); // returns 0 - */ - LeapSecond.compareLeapSecondDate = function(leapSecond1, leapSecond2) { - return leapSecond1.julianDate.compareTo(leapSecond2.julianDate); - }; - - LeapSecond._leapSeconds = []; - return LeapSecond; }); \ No newline at end of file diff --git a/Specs/Core/EarthOrientationParametersSpec.js b/Specs/Core/EarthOrientationParametersSpec.js index 5c0985dd1db9..5991518168e3 100644 --- a/Specs/Core/EarthOrientationParametersSpec.js +++ b/Specs/Core/EarthOrientationParametersSpec.js @@ -17,11 +17,11 @@ defineSuite([ var officialLeapSeconds; beforeAll(function() { - officialLeapSeconds = LeapSecond.leapSeconds.slice(0); + officialLeapSeconds = JulianDate.leapSeconds.slice(0); }); afterEach(function() { - LeapSecond.leapSeconds = officialLeapSeconds.slice(0); + JulianDate.leapSeconds = officialLeapSeconds.slice(0); }); it('adds leap seconds found in the data by default', function() { @@ -44,7 +44,7 @@ defineSuite([ }); expect(eop).not.toBeNull(); - var leapSeconds = LeapSecond.leapSeconds; + var leapSeconds = JulianDate.leapSeconds; expect(leapSeconds.length).toBe(officialLeapSeconds.length + 1); var newDate = new JulianDate(2455799.5, 34.5, TimeStandard.TAI); @@ -88,7 +88,7 @@ defineSuite([ }); expect(eop).not.toBeNull(); - var leapSeconds = LeapSecond.leapSeconds; + var leapSeconds = JulianDate.leapSeconds; expect(leapSeconds.length).toBe(officialLeapSeconds.length); }); diff --git a/Specs/Core/LeapSecondSpec.js b/Specs/Core/LeapSecondSpec.js index 4472048115ed..8c59550267eb 100644 --- a/Specs/Core/LeapSecondSpec.js +++ b/Specs/Core/LeapSecondSpec.js @@ -1,72 +1,24 @@ /*global defineSuite*/ defineSuite([ 'Core/LeapSecond', - 'Core/binarySearch', - 'Core/JulianDate', - 'Core/TimeStandard' + 'Core/JulianDate' ], function( LeapSecond, - binarySearch, - JulianDate, - TimeStandard) { + JulianDate) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('throws an exception if constructed without a julian date', function() { - expect(function() { - return new LeapSecond(); - }).toThrowDeveloperError(); + it('default constructor sets expected values', function() { + var leapSecond = new LeapSecond(); + expect(leapSecond.julianDate).toBeUndefined(); + expect(leapSecond.offset).toBeUndefined(); }); - it('throws an exception if constructed without an offset', function() { - expect(function() { - return new LeapSecond(JulianDate.now()); - }).toThrowDeveloperError(); - }); - - it('can get the TAI offset from UTC', function() { - var ls = new LeapSecond(JulianDate.now(), 1.0); - expect(ls.offset).toEqual(1.0); - }); - - it('can get the TAI offset for an index (in range)', function() { - var leapSeconds = LeapSecond.leapSeconds; - var toFind = new LeapSecond(new JulianDate(2441683, 43212.0, TimeStandard.TAI), 12.0); - var index = binarySearch(leapSeconds, toFind, LeapSecond.compareLeapSecondDate); - expect(LeapSecond.leapSeconds[index].offset).toEqual(12.0); - }); - - it('can get the Julian date for an index (in range)', function() { - var leapSeconds = LeapSecond.leapSeconds; - var toFind = new LeapSecond(new JulianDate(2441317, 43210.0, TimeStandard.TAI), 0.0); - var index = binarySearch(leapSeconds, toFind, LeapSecond.compareLeapSecondDate); - expect(leapSeconds[index].julianDate).toEqual(toFind.julianDate); - }); - - it('can check to see if leap seconds are equal', function() { - var date = new Date('January 1, 1990 00:00:00 UTC'); - var leapSecond1 = new LeapSecond(JulianDate.fromDate(date), 25.0); - var leapSecond2 = new LeapSecond(JulianDate.fromDate(date), 25.0); - var leapSecond3 = new LeapSecond(JulianDate.fromDate(date), 26.0); - expect(leapSecond1.equals(leapSecond2)).toEqual(true); - expect(leapSecond1.equals(leapSecond3)).toEqual(false); - }); - - it('can compare leap second dates (1)', function() { - var leapSecond1 = new LeapSecond(JulianDate.fromDate(new Date('July 18, 2011 12:00:00 UTC')), 0.0); - var leapSecond2 = new LeapSecond(JulianDate.fromDate(new Date('July 20, 2011 12:00:00 UTC')), 0.0); - - expect(LeapSecond.compareLeapSecondDate(leapSecond1, leapSecond2)).toBeLessThan(0); - expect(LeapSecond.compareLeapSecondDate(leapSecond2, leapSecond1)).toBeGreaterThan(0); - expect(LeapSecond.compareLeapSecondDate(leapSecond1, leapSecond1)).toEqual(0); - }); - - it('can compare leap second dates (2)', function() { - var leapSecond1 = new LeapSecond(JulianDate.fromDate(new Date('July 18, 2011 15:00:00 UTC')), 0.0); - var leapSecond2 = new LeapSecond(JulianDate.fromDate(new Date('July 18, 2011 16:00:00 UTC')), 0.0); - - expect(LeapSecond.compareLeapSecondDate(leapSecond1, leapSecond2)).toBeLessThan(0); - expect(LeapSecond.compareLeapSecondDate(leapSecond2, leapSecond1)).toBeGreaterThan(0); - expect(LeapSecond.compareLeapSecondDate(leapSecond1, leapSecond1)).toEqual(0); + it('constructor sets expected values', function() { + var date = new JulianDate(); + var offset = 12; + var leapSecond = new LeapSecond(date, offset); + expect(leapSecond.julianDate).toEqual(date); + expect(leapSecond.offset).toEqual(offset); }); }); From d57ee455a3a4502f406e67169195081dc996d807 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Wed, 11 Jun 2014 13:45:10 -0400 Subject: [PATCH 05/11] JulianDate doc cleanup. --- Source/Core/JulianDate.js | 49 ++++----------------------------------- 1 file changed, 5 insertions(+), 44 deletions(-) diff --git a/Source/Core/JulianDate.js b/Source/Core/JulianDate.js index 71355a470bd1..53bb9ffac8ad 100644 --- a/Source/Core/JulianDate.js +++ b/Source/Core/JulianDate.js @@ -180,10 +180,10 @@ define([ * @constructor * * @param {Number} julianDayNumber The Julian Day Number representing the number of whole days. Fractional days will also be handled correctly. - * @param {Number} julianSecondsOfDay The number of seconds into the current Julian Day Number. Fractional seconds, negative seconds and seconds greater than a day will be handled correctly. + * @param {Number} secondsOfDay The number of seconds into the current Julian Day Number. Fractional seconds, negative seconds and seconds greater than a day will be handled correctly. * @param {TimeStandard} [timeStandard=TimeStandard.UTC] The time standard in which the first two parameters are defined. */ - var JulianDate = function(julianDayNumber, julianSecondsOfDay, timeStandard) { + var JulianDate = function(julianDayNumber, secondsOfDay, timeStandard) { /** * Gets or sets the number of whole days. * @type {Number} @@ -197,12 +197,12 @@ define([ this.secondsOfDay = undefined; julianDayNumber = defaultValue(julianDayNumber, 0.0); - julianSecondsOfDay = defaultValue(julianSecondsOfDay, 0.0); + secondsOfDay = defaultValue(secondsOfDay, 0.0); timeStandard = defaultValue(timeStandard, TimeStandard.UTC); //If julianDayNumber is fractional, make it an integer and add the number of seconds the fraction represented. var wholeDays = julianDayNumber | 0; - var secondsOfDay = julianSecondsOfDay + (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY; + secondsOfDay = secondsOfDay + (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY; setComponents(wholeDays, secondsOfDay, this); @@ -219,9 +219,6 @@ define([ * @returns {JulianDate} The modified result parameter or a new instance if none was provided. * * @exception {DeveloperError} date must be a valid JavaScript Date. - * - * @example - * var julianDate = Cesium.JulianDate.fromDate(new Date('January 1, 2011 12:00:00 EST')); */ JulianDate.fromDate = function(date, result) { //>>includeStart('debug', pragmas.debug); @@ -249,18 +246,6 @@ define([ * @returns {JulianDate} The modified result parameter or a new instance if none was provided. * * @exception {DeveloperError} Invalid ISO 8601 date. - * - * @example - * // Construct an instance at April 24th, 2012 6:08PM UTC - * var date = Cesium.JulianDate.fromIso8601('2012-04-24T18:08Z'); - * - * @example - * // Construct an instance in local time April 24th, 2012 12:00 AM - * var date = Cesium.JulianDate.fromIso8601('2012-04-24'); - * - * @example - * // Construct an instance 5 hours behind April 24th, 2012 5:00 PM UTC - * var date = Cesium.JulianDate.fromIso8601('2012-04-24T12:00-05:00'); */ JulianDate.fromIso8601 = function(iso8601String, result) { //>>includeStart('debug', pragmas.debug); @@ -760,11 +745,6 @@ define([ * @param {JulianDate} left The first instance. * @param {JulianDate} right The second instance. * @returns {Number} The difference, in seconds, when subtracting right from left. - * - * @example - * var left = Cesium.JulianDate.fromDate(new Date('July 5, 2011 12:01:00')); - * var right = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); - * var difference = JulianDate.getSecondsDifference(left, right); // -86460.0 seconds */ JulianDate.getSecondsDifference = function(left, right) { //>>includeStart('debug', pragmas.debug); @@ -786,11 +766,6 @@ define([ * @param {JulianDate} left The first instance. * @param {JulianDate} right The second instance. * @returns {Number} The difference, in days, when subtracting right from left. - * - * @example - * var left = Cesium.JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); - * var right = Cesium.JulianDate.fromDate(new Date('July 5, 2011 14:24:00')); - * var difference = JulianDate.getDaysDifference(left, right); // 1.1 days */ JulianDate.getDaysDifference = function(left, right) { //>>includeStart('debug', pragmas.debug); @@ -811,7 +786,7 @@ define([ * Computes the number of seconds the provided instance is ahead of UTC. * * @param {JulianDate} julianDate The date. - * @returns {Number} The number of seconds the provided isntance is ahead of UTC + * @returns {Number} The number of seconds the provided instance is ahead of UTC */ JulianDate.getTaiMinusUtc = function(julianDate) { binarySearchScratchLeapSecond.julianDate = julianDate; @@ -834,13 +809,6 @@ define([ * @param {Number} seconds The number of seconds to add or subtract. * @param {JulianDate} [result] An existing instance to use for the result. * @returns {JulianDate} The modified result parameter or a new instance if none was provided. - * - * @example - * var date = new Date(); - * date.setUTCFullYear(2011, 6, 4); // July 4, 2011 @ 12:00:00 UTC - * date.setUTCHours(12, 0, 00, 0); - * var start = Cesium.JulianDate.fromDate(date); - * var end = JulianDate.addSeconds(start, 95); // July 4, 2011 @ 12:01:35 UTC */ JulianDate.addSeconds = function(julianDate, seconds, result) { //>>includeStart('debug', pragmas.debug); @@ -862,13 +830,6 @@ define([ * @param {Number} minutes The number of minutes to add or subtract. * @param {JulianDate} [result] An existing instance to use for the result. * @returns {JulianDate} The modified result parameter or a new instance if none was provided. - * - * @example - * var date = new Date(); - * date.setUTCFullYear(2011, 6, 4); // July 4, 2011 @ 12:00 UTC - * date.setUTCHours(12, 0, 0, 0); - * var start = Cesium.JulianDate.fromDate(date); - * var end = start.addMinutes(65); // July 4, 2011 @ 13:05 UTC */ JulianDate.addMinutes = function(julianDate, minutes) { //>>includeStart('debug', pragmas.debug); From b083865cc054ef9d94ba5852b784f523203a156a Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Wed, 11 Jun 2014 13:56:03 -0400 Subject: [PATCH 06/11] Swap order of parameters in JulianDate.getSecondsDifference and JulianDate.getDaysDifference --- Apps/TimelineDemo/TimelineDemo.js | 4 ++-- Source/Core/Clock.js | 2 +- Source/Core/EarthOrientationParameters.js | 2 +- Source/Core/Iau2006XysData.js | 2 +- Source/Core/JulianDate.js | 12 +++++----- Source/DynamicScene/CzmlDataSource.js | 2 +- Source/DynamicScene/DynamicPathVisualizer.js | 4 ++-- Source/DynamicScene/SampledProperty.js | 4 ++-- Source/Scene/ModelAnimationCollection.js | 2 +- Source/Widgets/Timeline/Timeline.js | 22 +++++++++---------- .../Timeline/TimelineHighlightRange.js | 4 ++-- Specs/Core/EarthOrientationParametersSpec.js | 6 ++--- Specs/Core/JulianDateSpec.js | 22 +++++++++---------- Specs/DynamicScene/CzmlDataSourceSpec.js | 2 +- 14 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Apps/TimelineDemo/TimelineDemo.js b/Apps/TimelineDemo/TimelineDemo.js index 545b46906d4c..6546198f5e67 100644 --- a/Apps/TimelineDemo/TimelineDemo.js +++ b/Apps/TimelineDemo/TimelineDemo.js @@ -95,7 +95,7 @@ define([ timeline.addTrack(new TimeInterval(startJulian, JulianDate.addSeconds(startJulian, 60 * 60)), 8, Color.RED, new Color(0.55, 0.55, 0.55, 0.25)); timeline.addTrack(new TimeInterval(JulianDate.addSeconds(endJulian, -60 * 60), endJulian), 8, Color.LIME); - var middle = JulianDate.getSecondsDifference(startJulian, endJulian) / 4; + var middle = JulianDate.getSecondsDifference(endJulian, startJulian) / 4; timeline.addTrack(new TimeInterval(JulianDate.addSeconds(startJulian, middle), JulianDate.addSeconds(startJulian, middle * 3)), 8, Color.DEEPSKYBLUE, new Color(0.55, 0.55, 0.55, 0.25)); var clockViewModel = new ClockViewModel(clock); @@ -123,7 +123,7 @@ define([ } if (startJulian && endJulian) { - if (JulianDate.getSecondsDifference(startJulian, endJulian) < 0.1) { + if (JulianDate.getSecondsDifference(endJulian, startJulian) < 0.1) { endBeforeStart.style.display = 'block'; containerElement.style.visibility = 'hidden'; } else { diff --git a/Source/Core/Clock.js b/Source/Core/Clock.js index 166c936c14bc..b54fb24de648 100644 --- a/Source/Core/Clock.js +++ b/Source/Core/Clock.js @@ -192,7 +192,7 @@ define([ currentTime = JulianDate.clone(startTime); } while (JulianDate.greaterThan(currentTime, stopTime)) { - currentTime = JulianDate.addSeconds(startTime, JulianDate.getSecondsDifference(stopTime, currentTime)); + currentTime = JulianDate.addSeconds(startTime, JulianDate.getSecondsDifference(currentTime, stopTime)); } } } diff --git a/Source/Core/EarthOrientationParameters.js b/Source/Core/EarthOrientationParameters.js index 6d7236a8f748..beb2bebd4b40 100644 --- a/Source/Core/EarthOrientationParameters.js +++ b/Source/Core/EarthOrientationParameters.js @@ -338,7 +338,7 @@ define([ return result; } - var factor = JulianDate.getSecondsDifference(beforeDate, date) / JulianDate.getSecondsDifference(beforeDate, afterDate); + var factor = JulianDate.getSecondsDifference(date, beforeDate) / JulianDate.getSecondsDifference(afterDate, beforeDate); var startBefore = before * columnCount; var startAfter = after * columnCount; diff --git a/Source/Core/Iau2006XysData.js b/Source/Core/Iau2006XysData.js index 72f97e3a83af..121854c08b67 100644 --- a/Source/Core/Iau2006XysData.js +++ b/Source/Core/Iau2006XysData.js @@ -81,7 +81,7 @@ define([ var dateTT = julianDateScratch; dateTT.dayNumber = dayTT; dateTT.secondsOfDay = secondTT; - return JulianDate.getDaysDifference(xys._sampleZeroDateTT, dateTT); + return JulianDate.getDaysDifference(dateTT, xys._sampleZeroDateTT); } /** diff --git a/Source/Core/JulianDate.js b/Source/Core/JulianDate.js index 53bb9ffac8ad..35686ebff1b0 100644 --- a/Source/Core/JulianDate.js +++ b/Source/Core/JulianDate.js @@ -60,7 +60,7 @@ define([ //However, if the difference between the UTC date being converted and the TAI //defined leap second is greater than the offset, we are off by one and need to use //the previous leap second. - var difference = JulianDate.getSecondsDifference(julianDate, leapSeconds[index].julianDate); + var difference = JulianDate.getSecondsDifference(leapSeconds[index].julianDate, julianDate); if (difference > offset) { index--; offset = leapSeconds[index].offset; @@ -89,7 +89,7 @@ define([ } //Compute the difference between the found leap second and the time we are converting. - var difference = JulianDate.getSecondsDifference(julianDate, leapSeconds[index].julianDate); + var difference = JulianDate.getSecondsDifference(leapSeconds[index].julianDate, julianDate); if (difference === 0) { //The date is in our leap second table. @@ -756,8 +756,8 @@ define([ } //>>includeEnd('debug'); - var dayDifference = (right.dayNumber - left.dayNumber) * TimeConstants.SECONDS_PER_DAY; - return (dayDifference + (right.secondsOfDay - left.secondsOfDay)); + var dayDifference = (left.dayNumber - right.dayNumber) * TimeConstants.SECONDS_PER_DAY; + return (dayDifference + (left.secondsOfDay - right.secondsOfDay)); }; /** @@ -777,8 +777,8 @@ define([ } //>>includeEnd('debug'); - var dayDifference = (right.dayNumber - left.dayNumber); - var secondDifference = (right.secondsOfDay - left.secondsOfDay) / TimeConstants.SECONDS_PER_DAY; + var dayDifference = (left.dayNumber - right.dayNumber); + var secondDifference = (left.secondsOfDay - right.secondsOfDay) / TimeConstants.SECONDS_PER_DAY; return dayDifference + secondDifference; }; diff --git a/Source/DynamicScene/CzmlDataSource.js b/Source/DynamicScene/CzmlDataSource.js index bf494caf7fbd..b24c730ebb11 100644 --- a/Source/DynamicScene/CzmlDataSource.js +++ b/Source/DynamicScene/CzmlDataSource.js @@ -1525,7 +1525,7 @@ define([ if (!availability.start.equals(Iso8601.MINIMUM_VALUE)) { var startTime = availability.start; var stopTime = availability.stop; - var totalSeconds = JulianDate.getSecondsDifference(startTime, stopTime); + var totalSeconds = JulianDate.getSecondsDifference(stopTime, startTime); var multiplier = Math.round(totalSeconds / 120.0); czmlClock = new DynamicClock(); diff --git a/Source/DynamicScene/DynamicPathVisualizer.js b/Source/DynamicScene/DynamicPathVisualizer.js index 5878c9a12b7c..2e5cac24daa5 100644 --- a/Source/DynamicScene/DynamicPathVisualizer.js +++ b/Source/DynamicScene/DynamicPathVisualizer.js @@ -84,7 +84,7 @@ define([ if (t < (len - 1)) { if (maximumStep > 0 && !sampling) { var next = times[t + 1]; - var secondsUntilNext = JulianDate.getSecondsDifference(current, next); + var secondsUntilNext = JulianDate.getSecondsDifference(next, current); sampling = secondsUntilNext > maximumStep; if (sampling) { @@ -161,7 +161,7 @@ define([ if (interval.isStopIncluded) { time = interval.stop; } else { - time = JulianDate.addSeconds(interval.start, JulianDate.getSecondsDifference(interval.start, interval.stop) / 2); + time = JulianDate.addSeconds(interval.start, JulianDate.getSecondsDifference(interval.stop, interval.start) / 2); } } var tmp = property.getValueInReferenceFrame(time, referenceFrame, result[index]); diff --git a/Source/DynamicScene/SampledProperty.js b/Source/DynamicScene/SampledProperty.js index f5891122ee24..5317eec7a994 100644 --- a/Source/DynamicScene/SampledProperty.js +++ b/Source/DynamicScene/SampledProperty.js @@ -359,7 +359,7 @@ define([ // Build the tables for (var i = 0; i < length; ++i) { - xTable[i] = JulianDate.getSecondsDifference(times[lastIndex], times[firstIndex + i]); + xTable[i] = JulianDate.getSecondsDifference(times[firstIndex + i], times[lastIndex]); } if (!defined(innerType.convertPackedArrayForInterpolation)) { @@ -378,7 +378,7 @@ define([ } // Interpolate! - var x = JulianDate.getSecondsDifference(times[lastIndex], time); + var x = JulianDate.getSecondsDifference(time, times[lastIndex]); var interpolationResult; if (inputOrder === 0 || !defined(interpolationAlgorithm.interpolate)) { interpolationResult = interpolationAlgorithm.interpolateOrderZero(x, xTable, yTable, packedInterpolationLength, this._interpolationResult); diff --git a/Source/Scene/ModelAnimationCollection.js b/Source/Scene/ModelAnimationCollection.js index 4492bf9bd7db..d41955fd56a2 100644 --- a/Source/Scene/ModelAnimationCollection.js +++ b/Source/Scene/ModelAnimationCollection.js @@ -362,7 +362,7 @@ define([ var stopTime = scheduledAnimation.stopTime; // [0.0, 1.0] normalized local animation time - var delta = (duration !== 0.0) ? (JulianDate.getSecondsDifference(startTime, sceneTime) / duration) : 0.0; + var delta = (duration !== 0.0) ? (JulianDate.getSecondsDifference(sceneTime, startTime) / duration) : 0.0; var pastStartTime = (delta >= 0.0); // Play animation if diff --git a/Source/Widgets/Timeline/Timeline.js b/Source/Widgets/Timeline/Timeline.js index 3b204b04e05a..8bc18acb3865 100644 --- a/Source/Widgets/Timeline/Timeline.js +++ b/Source/Widgets/Timeline/Timeline.js @@ -203,7 +203,7 @@ define([ }; Timeline.prototype.zoomTo = function(startJulianDate, endJulianDate) { - this._timeBarSecondsSpan = JulianDate.getSecondsDifference(startJulianDate, endJulianDate); + this._timeBarSecondsSpan = JulianDate.getSecondsDifference(endJulianDate, startJulianDate); //>>includeStart('debug', pragmas.debug); if (this._timeBarSecondsSpan <= 0) { @@ -218,9 +218,9 @@ define([ if (this._clock && (this._clock.clockRange !== ClockRange.UNBOUNDED)) { var clockStart = this._clock.startTime; var clockEnd = this._clock.stopTime; - var clockSpan = JulianDate.getSecondsDifference(clockStart, clockEnd); - var startOffset = JulianDate.getSecondsDifference(this._startJulian, clockStart); - var endOffset = JulianDate.getSecondsDifference(this._endJulian, clockEnd); + var clockSpan = JulianDate.getSecondsDifference(clockEnd, clockStart); + var startOffset = JulianDate.getSecondsDifference(clockStart, this._startJulian); + var endOffset = JulianDate.getSecondsDifference(clockEnd, this._endJulian); if (this._timeBarSecondsSpan >= clockSpan) { // if new duration longer than clock range duration, clamp to full range. @@ -231,12 +231,12 @@ define([ // if timeline start is before clock start, shift right this._endJulian = JulianDate.addSeconds(this._endJulian, startOffset); this._startJulian = clockStart; - this._timeBarSecondsSpan = JulianDate.getSecondsDifference(this._startJulian, this._endJulian); + this._timeBarSecondsSpan = JulianDate.getSecondsDifference(this._endJulian, this._startJulian); } else if (endOffset < 0) { // if timeline end is after clock end, shift left this._startJulian = JulianDate.addSeconds(this._startJulian, endOffset); this._endJulian = clockEnd; - this._timeBarSecondsSpan = JulianDate.getSecondsDifference(this._startJulian, this._endJulian); + this._timeBarSecondsSpan = JulianDate.getSecondsDifference(this._endJulian, this._startJulian); } } @@ -253,7 +253,7 @@ define([ }; Timeline.prototype.zoomFrom = function(amount) { - var centerSec = JulianDate.getSecondsDifference(this._startJulian, this._scrubJulian); + var centerSec = JulianDate.getSecondsDifference(this._scrubJulian, this._startJulian); if ((amount > 1) || (centerSec < 0) || (centerSec > this._timeBarSecondsSpan)) { centerSec = this._timeBarSecondsSpan * 0.5; } else { @@ -287,7 +287,7 @@ define([ Timeline.prototype._makeTics = function() { var timeBar = this._timeBarEle; - var seconds = JulianDate.getSecondsDifference(this._startJulian, this._scrubJulian); + var seconds = JulianDate.getSecondsDifference(this._scrubJulian, this._startJulian); var xPos = Math.round(seconds * this._topDiv.clientWidth / this._timeBarSecondsSpan); var scrubX = xPos - 8, tic; var widget = this; @@ -335,7 +335,7 @@ define([ epochJulian = JulianDate.fromIso8601(JulianDate.toDate(startJulian).toISOString().substring(0, 10) + 'T00:00:00Z'); } // startTime: Seconds offset of the left side of the timeline from epochJulian. - var startTime = JulianDate.getSecondsDifference(JulianDate.addSeconds(epochJulian, epsilonTime), this._startJulian); + var startTime = JulianDate.getSecondsDifference(this._startJulian, JulianDate.addSeconds(epochJulian, epsilonTime)); // endTime: Seconds offset of the right side of the timeline from epochJulian. var endTime = startTime + duration; this._epochJulian = epochJulian; @@ -502,7 +502,7 @@ define([ this._scrubJulian = this._clock.currentTime; var scrubElement = this._scrubElement; if (defined(this._scrubElement)) { - var seconds = JulianDate.getSecondsDifference(this._startJulian, this._scrubJulian); + var seconds = JulianDate.getSecondsDifference(this._scrubJulian, this._startJulian); var xPos = Math.round(seconds * this._topDiv.clientWidth / this._timeBarSecondsSpan); if (this._lastXPos !== xPos) { @@ -619,7 +619,7 @@ define([ e.preventDefault(); timeline._mouseMode = timelineMouseMode.touchOnly; if (len === 1) { - seconds = JulianDate.getSecondsDifference(timeline._startJulian, timeline._scrubJulian); + seconds = JulianDate.getSecondsDifference(timeline._scrubJulian, timeline._startJulian); xPos = Math.round(seconds * timeline._topDiv.clientWidth / timeline._timeBarSecondsSpan + leftX); if (Math.abs(e.touches[0].clientX - xPos) < 50) { timeline._touchMode = timelineTouchMode.scrub; diff --git a/Source/Widgets/Timeline/TimelineHighlightRange.js b/Source/Widgets/Timeline/TimelineHighlightRange.js index dd9c4c8abbe0..afe31cd03be1 100644 --- a/Source/Widgets/Timeline/TimelineHighlightRange.js +++ b/Source/Widgets/Timeline/TimelineHighlightRange.js @@ -37,9 +37,9 @@ define([ TimelineHighlightRange.prototype.render = function(renderState) { var range = ''; if (this._start && this._stop && this._color) { - var highlightStart = JulianDate.getSecondsDifference(renderState.epochJulian, this._start); + var highlightStart = JulianDate.getSecondsDifference(this._start, renderState.epochJulian); var highlightLeft = Math.round(renderState.timeBarWidth * renderState.getAlpha(highlightStart)); - var highlightStop = JulianDate.getSecondsDifference(renderState.epochJulian, this._stop); + var highlightStop = JulianDate.getSecondsDifference(this._stop, renderState.epochJulian); var highlightWidth = Math.round(renderState.timeBarWidth * renderState.getAlpha(highlightStop)) - highlightLeft; if (highlightLeft < 0) { highlightWidth += highlightLeft; diff --git a/Specs/Core/EarthOrientationParametersSpec.js b/Specs/Core/EarthOrientationParametersSpec.js index 5991518168e3..0bcb5a8ba60b 100644 --- a/Specs/Core/EarthOrientationParametersSpec.js +++ b/Specs/Core/EarthOrientationParametersSpec.js @@ -125,7 +125,7 @@ defineSuite([ var nColumns = eopDescription.data.columnNames.length; var x0 = eopDescription.data.samples[1 * nColumns + 2]; var x1 = eopDescription.data.samples[2 * nColumns + 2]; - var dt = JulianDate.getSecondsDifference(JulianDate.fromIso8601(eopDescription.data.samples[nColumns]), date) / 86400.0; + var dt = JulianDate.getSecondsDifference(date, JulianDate.fromIso8601(eopDescription.data.samples[nColumns])) / 86400.0; var expected = linearInterp(dt, x0, x1); expect(result.xPoleWander).toEqualEpsilon(expected, 1e-22); x0 = eopDescription.data.samples[1 * nColumns + 3]; @@ -179,7 +179,7 @@ defineSuite([ var x2 = eopDescription.data.samples[3*nColumns + 6]; var t0 = JulianDate.fromIso8601(eopDescription.data.samples[nColumns]); var t1 = JulianDate.fromIso8601(eopDescription.data.samples[2*nColumns]); - var dt = JulianDate.getSecondsDifference(t0, dateSlightlyBefore) / (86400.0 + 1); + var dt = JulianDate.getSecondsDifference(dateSlightlyBefore, t0) / (86400.0 + 1); // Adjust for leap second when interpolating var expectedBefore = linearInterp(dt, x0, (x1 - 1)); var resultBefore = eop.compute(dateSlightlyBefore); @@ -187,7 +187,7 @@ defineSuite([ var expectedAt = eopDescription.data.samples[2*nColumns + 6]; var resultAt = eop.compute(dateAtLeapSecond); expect(resultAt.ut1MinusUtc).toEqualEpsilon(expectedAt, 1.0e-15); - dt = JulianDate.getSecondsDifference(t1, dateSlightlyAfter) / (86400.0); + dt = JulianDate.getSecondsDifference(dateSlightlyAfter, t1) / (86400.0); var expectedAfter = linearInterp(dt, x1, x2); var resultAfter = eop.compute(dateSlightlyAfter); expect(resultAfter.ut1MinusUtc).toEqualEpsilon(expectedAfter, 1.0e-15); diff --git a/Specs/Core/JulianDateSpec.js b/Specs/Core/JulianDateSpec.js index 47adadecb440..8cac12ae2ae2 100644 --- a/Specs/Core/JulianDateSpec.js +++ b/Specs/Core/JulianDateSpec.js @@ -782,32 +782,32 @@ defineSuite([ it('getSecondsDifference works in UTC', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); var end = JulianDate.fromDate(new Date('July 5, 2011 12:01:00 UTC')); - expect(JulianDate.getSecondsDifference(start, end)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); + expect(JulianDate.getSecondsDifference(end, start)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); }); it('getSecondsDifference works in TAI', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); var end = JulianDate.fromDate(new Date('July 5, 2011 12:01:00 UTC')); - expect(JulianDate.getSecondsDifference(start, end)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); + expect(JulianDate.getSecondsDifference(end, start)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); }); it('getSecondsDifference works with mixed time standards', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00 UTC')); var end = JulianDate.fromDate(new Date('July 5, 2011 12:01:00 UTC')); - expect(JulianDate.getSecondsDifference(start, end)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); + expect(JulianDate.getSecondsDifference(end, start)).toEqualEpsilon(TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE, CesiumMath.EPSILON5); }); it('getDaysDifference works', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); var end = JulianDate.fromDate(new Date('July 5, 2011 14:24:00')); - var difference = JulianDate.getDaysDifference(start, end); + var difference = JulianDate.getDaysDifference(end, start); expect(difference).toEqual(1.1); }); it('getDaysDifference works with negative result', function() { var end = JulianDate.fromDate(new Date('July 4, 2011 12:00:00')); var start = JulianDate.fromDate(new Date('July 5, 2011 14:24:00')); - var difference = JulianDate.getDaysDifference(start, end); + var difference = JulianDate.getDaysDifference(end, start); expect(difference).toEqual(-1.1); }); @@ -821,39 +821,39 @@ defineSuite([ it('addSeconds works with fractions (1)', function() { var start = new JulianDate(2454832, 0, TimeStandard.TAI); var end = JulianDate.addSeconds(start, 1.5); - expect(JulianDate.getSecondsDifference(start, end)).toEqual(1.5); + expect(JulianDate.getSecondsDifference(end, start)).toEqual(1.5); }); it('addSeconds works with fractions (2)', function() { var start = JulianDate.fromDate(new Date('August 11 2011 6:00:00 UTC')); var end = JulianDate.addSeconds(start, 0.5); - expect(JulianDate.getSecondsDifference(start, end)).toEqual(0.5); + expect(JulianDate.getSecondsDifference(end, start)).toEqual(0.5); }); it('addSeconds works with fractions (3)', function() { var start = JulianDate.fromDate(new Date('August 11 2011 11:59:59 UTC')); var end = JulianDate.addSeconds(start, 1.25); - expect(JulianDate.getSecondsDifference(start, end)).toEqual(1.25); + expect(JulianDate.getSecondsDifference(end, start)).toEqual(1.25); }); it('addSeconds works with negative numbers', function() { var start = JulianDate.fromDate(new Date('July 4, 2011 12:01:30 UTC')); var end = JulianDate.addSeconds(start, -60.0); - expect(JulianDate.getSecondsDifference(start, end)).toEqual(-60.0); + expect(JulianDate.getSecondsDifference(end, start)).toEqual(-60.0); }); it('addSeconds works with more seconds than in a day', function() { var seconds = TimeConstants.SECONDS_PER_DAY * 7 + 15; var start = new JulianDate(2448444, 0, TimeStandard.UTC); var end = JulianDate.addSeconds(start, seconds); - expect(JulianDate.getSecondsDifference(start, end)).toEqual(seconds); + expect(JulianDate.getSecondsDifference(end, start)).toEqual(seconds); }); it('addSeconds works with negative seconds more than in a day', function() { var seconds = -TimeConstants.SECONDS_PER_DAY * 7 - 15; var start = new JulianDate(2448444, 0, TimeStandard.UTC); var end = JulianDate.addSeconds(start, seconds); - expect(JulianDate.getSecondsDifference(start, end)).toEqual(seconds); + expect(JulianDate.getSecondsDifference(end, start)).toEqual(seconds); }); it('addSeconds fails with undefined input', function() { expect(function() { diff --git a/Specs/DynamicScene/CzmlDataSourceSpec.js b/Specs/DynamicScene/CzmlDataSourceSpec.js index fb19c2712d6d..21dfee82359e 100644 --- a/Specs/DynamicScene/CzmlDataSourceSpec.js +++ b/Specs/DynamicScene/CzmlDataSourceSpec.js @@ -163,7 +163,7 @@ defineSuite([ expect(clock.currentTime).toEqual(interval.start); expect(clock.clockRange).toEqual(ClockRange.LOOP_STOP); expect(clock.clockStep).toEqual(ClockStep.SYSTEM_CLOCK_MULTIPLIER); - expect(clock.multiplier).toEqual(JulianDate.getSecondsDifference(interval.start, interval.stop) / 120.0); + expect(clock.multiplier).toEqual(JulianDate.getSecondsDifference(interval.stop, interval.start) / 120.0); }); it('processUrl loads expected data', function() { From d8dab7c57fd9af69b38ed2a596aef405ab045dbd Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Wed, 11 Jun 2014 14:37:51 -0400 Subject: [PATCH 07/11] Update changes --- CHANGES.md | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 340aef601ae5..ade0566df7a6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,7 +7,7 @@ Beta Releases ### b30 - 2014-07-01 * Breaking changes ([why so many?](https://groups.google.com/forum/#!topic/cesium-dev/Y_mG11IZD9k)) - * Replaced `CameraFlightPath.createAnimation` with `Camera.flyTo` and replaced `CameraFlightPath.createAnimationRectangle` with `Camera.flyToRectangle`. Code that looked like: + * Replaced `CameraFlightPath.createAnimation` with `Camera.flyTo` and replaced `CameraFlightPath.createAnimationRectangle` with `Camera.flyToRectangle`. Code that looked like: scene.animations.add(Cesium.CameraFlightPath.createAnimation(scene, { destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0) @@ -19,14 +19,35 @@ Beta Releases destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0) }); - * Renamed `options.endReferenceFrame` to `options.endTransform` in `Camera.flyTo` and `Camera.flyToRectangle`. - * Renamed `Simon1994PlanetaryPositions` functions `ComputeSunPositionInEarthInertialFrame` and `ComputeMoonPositionInEarthInertialFrame` to `computeSunPositionInEarthInertialFrame` and `computeMoonPositionInEarthInertialFrame`, respectively. - * Replaced `Scene.scene2D.projection` property with read-only `Scene.mapProjection`. Set this with the `mapProjection` option for the `Viewer`, `CesiumWidget`, or `Scene` constructors. - * `Scene` constructor function now takes an `options` parameter instead of individual parameters. - * Replaced `color`, `outlineColor`, and `outlineWidth` in `DynamicPath` with a `material` property. - * CZML property references now use a `#` symbol to separate identifier from property path. `objectId.position` should now be `objectId#position`. - * `CesiumWidget.showErrorPanel` now takes a `message` parameter in between the previous `title` and `error` parameters. - * `Event.removeEventListener` no longer throws `DeveloperError` if the `listener` does not exist; it now returns `false`. + * Renamed `options.endReferenceFrame` to `options.endTransform` in `Camera.flyTo` and `Camera.flyToRectangle`. + * Renamed `Simon1994PlanetaryPositions` functions `ComputeSunPositionInEarthInertialFrame` and `ComputeMoonPositionInEarthInertialFrame` to `computeSunPositionInEarthInertialFrame` and `computeMoonPositionInEarthInertialFrame`, respectively. + * Replaced `Scene.scene2D.projection` property with read-only `Scene.mapProjection`. Set this with the `mapProjection` option for the `Viewer`, `CesiumWidget`, or `Scene` constructors. + * `Scene` constructor function now takes an `options` parameter instead of individual parameters. + * Replaced `color`, `outlineColor`, and `outlineWidth` in `DynamicPath` with a `material` property. + * CZML property references now use a `#` symbol to separate identifier from property path. `objectId.position` should now be `objectId#position`. + * `CesiumWidget.showErrorPanel` now takes a `message` parameter in between the previous `title` and `error` parameters. + * `Event.removeEventListener` no longer throws `DeveloperError` if the `listener` does not exist; it now returns `false`. + * Moved `LeapScond.leapSeconds` to `JulianDate.leapSeconds`. + * Refactored `JulianDate` to be in line with other Core types. + * Most functions now take result parameters. + * Removed `JulianDate.getJulianTimeFraction` and `JulianDate.compareTo` + * `date.getJulianDayNumber()` -> `date.dayNumber` + * `date.getSecondsOfDay()` -> `secondsOfDay` + * `new JulianDate()` -> `JulianDate.now()` + * `date.getTotalDays()` -> `JulianDate.getTotalDays(date)` + * `date.getSecondsDifference(arg1, arg2)` -> `JulianDate.getSecondsDifference(arg2, arg1)` (Note, order of arguments flipped) + * `date.getDaysDifference(arg1, arg2)` -> `JulianDate.getDaysDifference(arg2, arg1)` (Note, order of arguments flipped) + * `date.getTaiMinusUtc()` -> `JulianDate.getTaiMinusUtc(date)` + * `date.getTaiMinusUtc()` -> `JulianDate.getTaiMinusUtc(date)` + * `date.getTaiMinusUtc()` -> `JulianDate.getTaiMinusUtc(date)` + * `date.addSeconds(seconds)` -> `JulianDate.addSeconds(date, seconds)` + * `date.addMinutes(minutes)` -> `JulianDate.addMinutes(date, minutes)` + * `date.addHours(hours)` -> `JulianDate.addHours(date, hours)` + * `date.addDays(days)` -> `JulianDate.addDays(date, days)` + * `date.lessThan(right)` -> `JulianDate.lessThan(left, right)` + * `date.lessThanOrEquals (right)` -> `JulianDate.lessThanOrEquals (left, right)` + * `date.greaterThan (right)` -> `JulianDate.greaterThan (left, right)` + * `date.greaterThanOrEquals (right)` -> `JulianDate.greaterThanOrEquals (left, right)` * `DynamicObject.id` can now include period characters. * `ReferenceProperty` can now handle sub-properties, for example, `myObject#billboard.scale`. * Added `Cesium.VERSION` to the combined `Cesium.js` file. From 1878766f1b9ed57f50bddc640423e0a4071d2c47 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Wed, 11 Jun 2014 15:49:54 -0400 Subject: [PATCH 08/11] Fix typos --- CHANGES.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ade0566df7a6..319b2ada9bf6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,19 +27,18 @@ Beta Releases * CZML property references now use a `#` symbol to separate identifier from property path. `objectId.position` should now be `objectId#position`. * `CesiumWidget.showErrorPanel` now takes a `message` parameter in between the previous `title` and `error` parameters. * `Event.removeEventListener` no longer throws `DeveloperError` if the `listener` does not exist; it now returns `false`. - * Moved `LeapScond.leapSeconds` to `JulianDate.leapSeconds`. + * Moved `LeapSecond.leapSeconds` to `JulianDate.leapSeconds`. * Refactored `JulianDate` to be in line with other Core types. * Most functions now take result parameters. + * The default constructor no longer creates a date at the current time, use `JulianDate.now()` instead. * Removed `JulianDate.getJulianTimeFraction` and `JulianDate.compareTo` + * `new JulianDate()` -> `JulianDate.now()` * `date.getJulianDayNumber()` -> `date.dayNumber` * `date.getSecondsOfDay()` -> `secondsOfDay` - * `new JulianDate()` -> `JulianDate.now()` * `date.getTotalDays()` -> `JulianDate.getTotalDays(date)` * `date.getSecondsDifference(arg1, arg2)` -> `JulianDate.getSecondsDifference(arg2, arg1)` (Note, order of arguments flipped) * `date.getDaysDifference(arg1, arg2)` -> `JulianDate.getDaysDifference(arg2, arg1)` (Note, order of arguments flipped) * `date.getTaiMinusUtc()` -> `JulianDate.getTaiMinusUtc(date)` - * `date.getTaiMinusUtc()` -> `JulianDate.getTaiMinusUtc(date)` - * `date.getTaiMinusUtc()` -> `JulianDate.getTaiMinusUtc(date)` * `date.addSeconds(seconds)` -> `JulianDate.addSeconds(date, seconds)` * `date.addMinutes(minutes)` -> `JulianDate.addMinutes(date, minutes)` * `date.addHours(hours)` -> `JulianDate.addHours(date, hours)` From a076b3c36d8431458388b39e8a6bae15b80a04f5 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Wed, 11 Jun 2014 16:34:08 -0400 Subject: [PATCH 09/11] Changes after review. Actually take a result parameter in function that claim to. --- Source/Core/JulianDate.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/JulianDate.js b/Source/Core/JulianDate.js index 35686ebff1b0..1d910c263be9 100644 --- a/Source/Core/JulianDate.js +++ b/Source/Core/JulianDate.js @@ -831,7 +831,7 @@ define([ * @param {JulianDate} [result] An existing instance to use for the result. * @returns {JulianDate} The modified result parameter or a new instance if none was provided. */ - JulianDate.addMinutes = function(julianDate, minutes) { + JulianDate.addMinutes = function(julianDate, minutes, result) { //>>includeStart('debug', pragmas.debug); if (!defined(julianDate)) { throw new DeveloperError('julianDate is required.'); @@ -842,7 +842,7 @@ define([ //>>includeEnd('debug'); var newSecondsOfDay = julianDate.secondsOfDay + (minutes * TimeConstants.SECONDS_PER_MINUTE); - return new JulianDate(julianDate.dayNumber, newSecondsOfDay, TimeStandard.TAI); + return setComponents(julianDate.dayNumber, newSecondsOfDay, result); }; /** @@ -853,7 +853,7 @@ define([ * @param {JulianDate} [result] An existing instance to use for the result. * @returns {JulianDate} The modified result parameter or a new instance if none was provided. */ - JulianDate.addHours = function(julianDate, hours) { + JulianDate.addHours = function(julianDate, hours, result) { //>>includeStart('debug', pragmas.debug); if (!defined(julianDate)) { throw new DeveloperError('julianDate is required.'); @@ -864,7 +864,7 @@ define([ //>>includeEnd('debug'); var newSecondsOfDay = julianDate.secondsOfDay + (hours * TimeConstants.SECONDS_PER_HOUR); - return new JulianDate(julianDate.dayNumber, newSecondsOfDay, TimeStandard.TAI); + return setComponents(julianDate.dayNumber, newSecondsOfDay, result); }; /** @@ -875,7 +875,7 @@ define([ * @param {JulianDate} [result] An existing instance to use for the result. * @returns {JulianDate} The modified result parameter or a new instance if none was provided. */ - JulianDate.addDays = function(julianDate, days) { + JulianDate.addDays = function(julianDate, days, result) { //>>includeStart('debug', pragmas.debug); if (!defined(julianDate)) { throw new DeveloperError('julianDate is required.'); @@ -886,7 +886,7 @@ define([ //>>includeEnd('debug'); var newJulianDayNumber = julianDate.dayNumber + days; - return new JulianDate(newJulianDayNumber, julianDate.secondsOfDay, TimeStandard.TAI); + return setComponents(julianDate.dayNumber, newSecondsOfDay, result); }; /** From b42ac316ad06ced98ad9d06fac41002ef90c2ac4 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Wed, 11 Jun 2014 16:35:57 -0400 Subject: [PATCH 10/11] Fix copy/paste error. --- Source/Core/JulianDate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/JulianDate.js b/Source/Core/JulianDate.js index 1d910c263be9..3f3f1b3216da 100644 --- a/Source/Core/JulianDate.js +++ b/Source/Core/JulianDate.js @@ -886,7 +886,7 @@ define([ //>>includeEnd('debug'); var newJulianDayNumber = julianDate.dayNumber + days; - return setComponents(julianDate.dayNumber, newSecondsOfDay, result); + return setComponents(newJulianDayNumber, julianDate.secondsOfDay, result); }; /** From 9894723f5b4b23eafb80e9422c7670197557193d Mon Sep 17 00:00:00 2001 From: Scott Hunter Date: Wed, 11 Jun 2014 17:53:28 -0400 Subject: [PATCH 11/11] Whitespace --- Source/Core/JulianDate.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Core/JulianDate.js b/Source/Core/JulianDate.js index 3f3f1b3216da..750f322c0e79 100644 --- a/Source/Core/JulianDate.js +++ b/Source/Core/JulianDate.js @@ -31,7 +31,6 @@ define([ var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; var daysInLeapFeburary = 29; - function compareLeapSecondDates(leapSecond, dateToFind) { return JulianDate.compare(leapSecond.julianDate, dateToFind.julianDate); }