Skip to content

Commit

Permalink
Fix semimonthly period
Browse files Browse the repository at this point in the history
  • Loading branch information
cemalettin-work committed Oct 30, 2020
1 parent 242d678 commit b69d819
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions client/src/periodUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ export const PERIOD_FACTORIES = {
.subtract(2 * offset, "weeks")
.endOf("week")
}),
[RECURRENCE_TYPE.SEMIMONTHLY]: (date, offset) => ({
start:
date.date() < 15
? date.clone().subtract(offset, "months").startOf("month")
: date.clone().subtract(offset, "months").startOf("month").date(15),
end:
date.date() < 15
? date.clone().subtract(offset, "months").startOf("month").date(14)
: date.clone().subtract(offset, "months").endOf("month")
}),
[RECURRENCE_TYPE.SEMIMONTHLY]: (date, offset) => {
const baseDate = date.clone().subtract(15 * offset, "days")
const isFirstHalfOfTheMonth = baseDate.date() < 16
const baseMonthStart = baseDate.clone().startOf("month")

return {
start: isFirstHalfOfTheMonth
? baseMonthStart
: baseMonthStart.clone().add(15, "days"), // start of day 16
end: isFirstHalfOfTheMonth
? baseMonthStart.clone().endOf("day").add(14, "days") // end of day 15
: baseMonthStart.clone().endOf("month")
}
},
[RECURRENCE_TYPE.MONTHLY]: (date, offset) => ({
start: date.clone().subtract(offset, "months").startOf("month"),
end: date.clone().subtract(offset, "months").endOf("month")
Expand Down

0 comments on commit b69d819

Please sign in to comment.