Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

Commit

Permalink
Fix behavior of setMonthSelectedNext function
Browse files Browse the repository at this point in the history
A bug introduced in 3f7ffba caused the function to select the current day instead of the month after the selected day.

Fixes #73
  • Loading branch information
samuelmeuli committed Apr 9, 2020
1 parent 31f2cc2 commit e954ba9
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/renderer/store/diary/actionCreators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import moment, { Moment } from "moment";
import { Moment } from "moment";

import { MAX_DATE, MIN_DATE } from "../../constants";
import { createDate, parseDate } from "../../utils/dateFormat";
Expand Down Expand Up @@ -61,7 +61,8 @@ export const setDaySelectedNext = (): ThunkActionT => (dispatch, getState): void
const { allowFutureEntries } = app;
const { dateSelected } = diary;
const nextDay = parseDate(dateSelected).add(1, "days");
if (allowFutureEntries || nextDay.isSameOrBefore(createDate(), "day")) {
const today = createDate();
if (allowFutureEntries || nextDay.isSameOrBefore(today, "day")) {
dispatch(setDateSelected(nextDay));
}
};
Expand All @@ -81,21 +82,19 @@ export const setMonthSelectedNext = (): ThunkActionT => (dispatch, getState): vo
const { app, diary } = getState();
const { allowFutureEntries } = app;
const { monthSelected } = diary;
const nextMonth = moment
.utc(monthSelected)
.add(1, "months")
.startOf("month");
const nextMonth = parseDate(monthSelected)
.startOf("month")
.add(1, "months");
const today = createDate();
if (allowFutureEntries || nextMonth.isSameOrBefore(today, "month")) {
dispatch(setDateSelected(createDate()));
dispatch(setDateSelected(nextMonth));
}
};

export const setMonthSelectedPrevious = (): ThunkActionT => (dispatch, getState): void => {
const { monthSelected } = getState().diary;
const previousMonth = moment
.utc(monthSelected)
.subtract(1, "months")
.startOf("month");
const previousMonth = parseDate(monthSelected)
.startOf("month")
.subtract(1, "months");
dispatch(setDateSelected(previousMonth));
};

0 comments on commit e954ba9

Please sign in to comment.