1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.MonthAndYear = void 0;
|
19 | var dateUtils_1 = require("./dateUtils");
|
20 | var MonthAndYear = (function () {
|
21 | function MonthAndYear(month, year) {
|
22 | if (month !== null && year !== null) {
|
23 | this.date = new Date(year, month);
|
24 | }
|
25 | else {
|
26 | this.date = new Date();
|
27 | }
|
28 | }
|
29 | MonthAndYear.fromDate = function (date) {
|
30 | return date == null ? undefined : new MonthAndYear(date.getMonth(), date.getFullYear());
|
31 | };
|
32 | MonthAndYear.prototype.clone = function () {
|
33 | return new MonthAndYear(this.getMonth(), this.getYear());
|
34 | };
|
35 | MonthAndYear.prototype.getFullDate = function () {
|
36 | return this.date;
|
37 | };
|
38 | MonthAndYear.prototype.getMonth = function () {
|
39 | return this.date.getMonth();
|
40 | };
|
41 | MonthAndYear.prototype.getYear = function () {
|
42 | return this.date.getFullYear();
|
43 | };
|
44 | MonthAndYear.prototype.getPreviousMonth = function () {
|
45 | var previousMonthDate = (0, dateUtils_1.getDatePreviousMonth)(this.date);
|
46 | return new MonthAndYear(previousMonthDate.getMonth(), previousMonthDate.getFullYear());
|
47 | };
|
48 | MonthAndYear.prototype.getNextMonth = function () {
|
49 | var nextMonthDate = (0, dateUtils_1.getDateNextMonth)(this.date);
|
50 | return new MonthAndYear(nextMonthDate.getMonth(), nextMonthDate.getFullYear());
|
51 | };
|
52 | MonthAndYear.prototype.isBefore = function (monthAndYear) {
|
53 | return compareMonthAndYear(this, monthAndYear) < 0;
|
54 | };
|
55 | MonthAndYear.prototype.isAfter = function (monthAndYear) {
|
56 | return compareMonthAndYear(this, monthAndYear) > 0;
|
57 | };
|
58 | MonthAndYear.prototype.isSame = function (monthAndYear) {
|
59 | return compareMonthAndYear(this, monthAndYear) === 0;
|
60 | };
|
61 | MonthAndYear.prototype.isSameMonth = function (monthAndYear) {
|
62 | return this.getMonth() === monthAndYear.getMonth();
|
63 | };
|
64 | return MonthAndYear;
|
65 | }());
|
66 | exports.MonthAndYear = MonthAndYear;
|
67 |
|
68 |
|
69 |
|
70 | function compareMonthAndYear(firstMonthAndYear, secondMonthAndYear) {
|
71 | var firstMonth = firstMonthAndYear.getMonth();
|
72 | var firstYear = firstMonthAndYear.getYear();
|
73 | var secondMonth = secondMonthAndYear.getMonth();
|
74 | var secondYear = secondMonthAndYear.getYear();
|
75 | if (firstYear === secondYear) {
|
76 | return firstMonth - secondMonth;
|
77 | }
|
78 | else {
|
79 | return firstYear - secondYear;
|
80 | }
|
81 | }
|
82 |
|
\ | No newline at end of file |