/* * IslamicRataDie.js - Represent an RD date in the Islamic calendar * * Copyright © 2012-2015, JEDLSoft * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * limitations under the License. */ /* !depends IslamicCal.js RataDie.js */ var RataDie = require("./RataDie.js"); var IslamicCal = require("./IslamicCal.js"); /** * @class * Construct a new Islamic RD date number object. The constructor parameters can * contain any of the following properties: * *
* * If the constructor is called with no arguments at all or if none of the * properties listed above are present, then the RD is calculate based on * the current date at the time of instantiation.
* * If any of the properties from year through millisecond are not * specified in the params, it is assumed that they have the smallest possible * value in the range for the property (zero or one).
* * * @private * @constructor * @extends RataDie * @param {Object=} params parameters that govern the settings and behaviour of this Islamic RD date */ var IslamicRataDie = function(params) { this.cal = params && params.cal || new IslamicCal(); this.rd = undefined; RataDie.call(this, params); }; IslamicRataDie.prototype = new RataDie(); IslamicRataDie.prototype.parent = RataDie; IslamicRataDie.prototype.constructor = IslamicRataDie; /** * The difference between a zero Julian day and the first Islamic date * of Friday, July 16, 622 CE Julian. * @private * @const * @type number */ IslamicRataDie.prototype.epoch = 1948439.5; /** * Calculate the Rata Die (fixed day) number of the given date from the * date components. * * @protected * @param {Object} date the date components to calculate the RD from */ IslamicRataDie.prototype._setDateComponents = function(date) { var days = (date.year - 1) * 354 + Math.ceil(29.5 * (date.month - 1)) + date.day + Math.floor((3 + 11 * date.year) / 30) - 1; var time = (date.hour * 3600000 + date.minute * 60000 + date.second * 1000 + date.millisecond) / 86400000; //console.log("getRataDie: converting " + JSON.stringify(date)); //console.log("getRataDie: days is " + days); //console.log("getRataDie: time is " + time); //console.log("getRataDie: rd is " + (days + time)); this.rd = days + time; }; module.exports = IslamicRataDie;