Skip to content

Commit

Permalink
Merge pull request #1821 from AnalyticalGraphicsInc/refactor-julianDate
Browse files Browse the repository at this point in the history
Refactor julian date
  • Loading branch information
shunter committed Jun 11, 2014
2 parents 64df948 + 9894723 commit adfc014
Show file tree
Hide file tree
Showing 73 changed files with 1,237 additions and 1,737 deletions.
18 changes: 9 additions & 9 deletions Apps/TimelineDemo/TimelineDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(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);
animationViewModel = new AnimationViewModel(clockViewModel);
Expand All @@ -123,7 +123,7 @@ define([
}

if (startJulian && endJulian) {
if (startJulian.getSecondsDifference(endJulian) < 0.1) {
if (JulianDate.getSecondsDifference(endJulian, startJulian) < 0.1) {
endBeforeStart.style.display = 'block';
containerElement.style.visibility = 'hidden';
} else {
Expand Down Expand Up @@ -214,9 +214,9 @@ define([
dijit.byId('startTimeSel').set('value', 'T00:00:00');
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 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));
});
});
40 changes: 30 additions & 10 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -19,15 +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`.
* All `Cartesain2`, `Cartesian3` and `Cartesian4` functions that take a `result` parameter now require the parameter (except for functions starting with `from`).
* 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`.
* All `Cartesain2`, `Cartesian3` and `Cartesian4` functions that take a `result` parameter now require the parameter (except for functions starting with `from`).
* 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`
* `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.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.
Expand Down
30 changes: 15 additions & 15 deletions Source/Core/Clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,28 @@ define([
var currentTimeUndefined = !defined(currentTime);

if (startTimeUndefined && stopTimeUndefined && currentTimeUndefined) {
currentTime = new JulianDate();
currentTime = JulianDate.now();
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');
Expand Down Expand Up @@ -172,27 +172,27 @@ 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 = 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(currentTime, stopTime));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/EarthOrientationParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -338,7 +338,7 @@ define([
return result;
}

var factor = beforeDate.getSecondsDifference(date) / beforeDate.getSecondsDifference(afterDate);
var factor = JulianDate.getSecondsDifference(date, beforeDate) / JulianDate.getSecondsDifference(afterDate, beforeDate);

var startBefore = before * columnCount;
var startAfter = after * columnCount;
Expand Down
57 changes: 57 additions & 0 deletions Source/Core/GregorianDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*global define*/
define(function() {
"use strict";

/**
* 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
* @constructor
*
* @see JulianDate#toGregorianDate
*/
var GregorianDate = function(year, month, day, hour, minute, second, millisecond, isLeapSecond) {
/**
* Gets or sets the year as a whole number.
* @type {Number}
*/
this.year = year;
/**
* Gets or sets the month as a whole number with range [1, 12].
* @type {Number}
*/
this.month = month;
/**
* Gets or sets the day of the month as a whole number starting at 1.
* @type {Number}
*/
this.day = day;
/**
* Gets or sets the hour as a whole number with range [0, 23].
* @type {Number}
*/
this.hour = hour;
/**
* Gets or sets the minute of the hour as a whole number with range [0, 59].
* @type {Number}
*/
this.minute = minute;
/**
* 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;
/**
* Gets or sets the millisecond of the second as a floating point number with range [0.0, 1000.0).
* @type {Number}
*/
this.millisecond = millisecond;
/**
* Gets or sets whether this time is during a leap second.
* @type {Boolean}
*/
this.isLeapSecond = isLeapSecond;
};

return GregorianDate;
});
8 changes: 4 additions & 4 deletions Source/Core/Iau2000Orientation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ 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 = 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;
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Iau2006XysData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(dateTT, xys._sampleZeroDateTT);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/IauOrientationAxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit adfc014

Please sign in to comment.