1 /*
  2  * ThaiSolarCal.js - Represent a Thai solar calendar object.
  3  *
  4  * Copyright © 2013-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 MathUtils = require("./MathUtils.js");
 21 var Calendar = require("./Calendar.js");
 22 var GregorianCal = require("./GregorianCal.js");
 23 
 24 /**
 25  * @class
 26  * Construct a new Thai solar calendar object. This class encodes information about
 27  * a Thai solar calendar.<p>
 28  *
 29  * @param {Object=} options Options governing the construction of this instance
 30  * @constructor
 31  * @extends Calendar
 32  */
 33 var ThaiSolarCal = function(options) {
 34     this.type = "thaisolar";
 35 
 36     if (options && typeof(options.onLoad) === "function") {
 37         options.onLoad(this);
 38     }
 39 };
 40 
 41 ThaiSolarCal.prototype = new GregorianCal({noinstance: true});
 42 ThaiSolarCal.prototype.parent = GregorianCal;
 43 ThaiSolarCal.prototype.constructor = ThaiSolarCal;
 44 
 45 /**
 46  * Return true if the given year is a leap year in the Thai solar calendar.
 47  * The year parameter may be given as a number, or as a ThaiSolarDate object.
 48  * @param {number|ThaiSolarDate} year the year for which the leap year information is being sought
 49  * @return {boolean} true if the given year is a leap year
 50  */
 51 ThaiSolarCal.prototype.isLeapYear = function(year) {
 52     var y = (typeof(year) === 'number' ? year : year.getYears());
 53     y -= 543;
 54     var centuries = MathUtils.mod(y, 400);
 55     return (MathUtils.mod(y, 4) === 0 && centuries !== 100 && centuries !== 200 && centuries !== 300);
 56 };
 57 
 58 
 59 /* register this calendar for the factory method */
 60 Calendar._constructors["thaisolar"] = ThaiSolarCal;
 61 
 62 module.exports = ThaiSolarCal;
 63