1 /* 2 * EthiopicRataDie.js - Represent an RD date in the Ethiopic calendar 3 * 4 * Copyright © 2015, 2018, JEDLSoft 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 var EthiopicCal = require("./EthiopicCal.js"); 21 var RataDie = require("./RataDie.js"); 22 23 /** 24 * @class 25 * Construct a new Ethiopic RD date number object. The constructor parameters can 26 * contain any of the following properties: 27 * 28 * <ul> 29 * <li><i>unixtime<i> - sets the time of this instance according to the given 30 * unix time. Unix time is the number of milliseconds since midnight on Jan 1, 1970. 31 * 32 * <li><i>julianday</i> - sets the time of this instance according to the given 33 * Julian Day instance or the Julian Day given as a float 34 * 35 * <li><i>year</i> - any integer, including 0 36 * 37 * <li><i>month</i> - 1 to 12, where 1 means Maskaram, 2 means Teqemt, etc., and 13 means Paguemen 38 * 39 * <li><i>day</i> - 1 to 30 40 * 41 * <li><i>hour</i> - 0 to 23. A formatter is used to display 12 hour clocks, but this representation 42 * is always done with an unambiguous 24 hour representation 43 * 44 * <li><i>minute</i> - 0 to 59 45 * 46 * <li><i>second</i> - 0 to 59 47 * 48 * <li><i>millisecond</i> - 0 to 999 49 * 50 * <li><i>date</i> - use the given intrinsic Javascript date to initialize this one. 51 * </ul> 52 * 53 * If the constructor is called with another Ethiopic date instance instead of 54 * a parameter block, the other instance acts as a parameter block and its 55 * settings are copied into the current instance.<p> 56 * 57 * If the constructor is called with no arguments at all or if none of the 58 * properties listed above are present, then the RD is calculate based on 59 * the current date at the time of instantiation. <p> 60 * 61 * If any of the properties from <i>year</i> through <i>millisecond</i> are not 62 * specified in the params, it is assumed that they have the smallest possible 63 * value in the range for the property (zero or one).<p> 64 * 65 * 66 * @private 67 * @constructor 68 * @extends RataDie 69 * @param {Object=} params parameters that govern the settings and behaviour of this Ethiopic RD date 70 */ 71 var EthiopicRataDie = function(params) { 72 this.cal = params && params.cal || new EthiopicCal(); 73 this.rd = NaN; 74 RataDie.call(this, params); 75 }; 76 77 EthiopicRataDie.prototype = new RataDie(); 78 EthiopicRataDie.prototype.parent = RataDie; 79 EthiopicRataDie.prototype.constructor = EthiopicRataDie; 80 81 /** 82 * The difference between the zero Julian day and the first Ethiopic date 83 * of Friday, August 29, 8 CE Julian at 6:00am UTC.<p> 84 * 85 * See <a href="http://us.wow.com/wiki/Time_in_Ethiopia?s_chn=90&s_pt=aolsem&v_t=aolsem" 86 * Time in Ethiopia</a> for information about how time is handled in Ethiopia. 87 * 88 * @protected 89 * @type number 90 */ 91 EthiopicRataDie.prototype.epoch = 1724219.75; 92 93 /** 94 * Calculate the Rata Die (fixed day) number of the given date from the 95 * date components. 96 * 97 * @protected 98 * @param {Object} date the date components to calculate the RD from 99 */ 100 EthiopicRataDie.prototype._setDateComponents = function(date) { 101 var year = date.year; 102 var years = 365 * (year - 1) + Math.floor(year/4); 103 var dayInYear = (date.month-1) * 30 + date.day; 104 var rdtime = (date.hour * 3600000 + 105 date.minute * 60000 + 106 date.second * 1000 + 107 date.millisecond) / 108 86400000; 109 110 /* 111 console.log("calcRataDie: converting " + JSON.stringify(parts)); 112 console.log("getRataDie: year is " + years); 113 console.log("getRataDie: day in year is " + dayInYear); 114 console.log("getRataDie: rdtime is " + rdtime); 115 console.log("getRataDie: rd is " + (years + dayInYear + rdtime)); 116 */ 117 118 this.rd = years + dayInYear + rdtime; 119 }; 120 121 module.exports = EthiopicRataDie; 122