@iro/calendar
Version:
lunar is a calendar library for Solar and Chinese Lunar.
68 lines • 2.18 kB
JavaScript
import { SolarUtil } from './SolarUtil';
import { Solar } from './Solar';
import { SolarWeek } from './SolarWeek';
var SolarMonth = (function () {
function SolarMonth(year, month) {
this._year = year;
this._month = month;
}
SolarMonth.fromYm = function (year, month) {
return new SolarMonth(year, month);
};
SolarMonth.fromDate = function (date) {
return SolarMonth.fromYm(date.getFullYear(), date.getMonth() + 1);
};
SolarMonth.prototype.getYear = function () {
return this._year;
};
SolarMonth.prototype.getMonth = function () {
return this._month;
};
SolarMonth.prototype.next = function (months) {
var n = months < 0 ? -1 : 1;
var m = Math.abs(months);
var y = this._year + Math.floor(m / 12) * n;
m = this._month + m % 12 * n;
if (m > 12) {
m -= 12;
y++;
}
else if (m < 1) {
m += 12;
y--;
}
return SolarMonth.fromYm(y, m);
};
SolarMonth.prototype.getDays = function () {
var l = [];
var d = Solar.fromYmd(this._year, this._month, 1);
l.push(d);
var days = SolarUtil.getDaysOfMonth(this._year, this._month);
for (var i = 1; i < days; i++) {
l.push(d.next(i));
}
return l;
};
SolarMonth.prototype.getWeeks = function (start) {
var l = [];
var week = SolarWeek.fromYmd(this._year, this._month, 1, start);
while (true) {
l.push(week);
week = week.next(1, false);
var firstDay = week.getFirstDay();
if (firstDay.getYear() > this._year || firstDay.getMonth() > this._month) {
break;
}
}
return l;
};
SolarMonth.prototype.toString = function () {
return "".concat(this.getYear(), "-").concat(this.getMonth());
};
SolarMonth.prototype.toFullString = function () {
return "".concat(this.getYear(), "\u5E74").concat(this.getMonth(), "\u6708");
};
return SolarMonth;
}());
export { SolarMonth };
//# sourceMappingURL=SolarMonth.js.map