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