UNPKG

3.22 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.MonthAndYear = void 0;
19var dateUtils_1 = require("./dateUtils");
20var MonthAndYear = /** @class */ (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}());
66exports.MonthAndYear = MonthAndYear;
67// returns negative if left < right
68// returns positive if left > right
69// returns 0 if left === right
70function 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//# sourceMappingURL=monthAndYear.js.map
\No newline at end of file