Skip to content

Commit

Permalink
#3068: Revert dictionary changes, hard code ref monday into Js
Browse files Browse the repository at this point in the history
Also revert isoWeek changes to weekly period, that might break old records
  • Loading branch information
cemalettin-work committed Nov 9, 2020
1 parent 3827d5d commit ed9e4c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
9 changes: 0 additions & 9 deletions anet-dictionary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,8 @@ dictionary:
label: daily
weekly:
label: weekly
# start of the week Monday(true) or Sunday(false) ?
startsWithMonday: true
biweekly:
label: biweekly
# There are two possible ways to arrange biweekly periods
# For example, if 1 Jan is Monday:
# First way: (1 Jan - 14 Jan) => (15 Jan - 28 Jan)
# Second way: (8 Jan - 21 Jan ) => (22 Jan - 4 Feb)
# So you need to pick one of two mondays in a biweekly period, depending on your use case, pick a monday which suits your schedule
# Periods will be arranged based on that monday
referenceMonday: "2020-06-01"
semimonthly:
label: semimonthly
monthly:
Expand Down
19 changes: 7 additions & 12 deletions client/src/periodUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import moment from "moment"
import PropTypes from "prop-types"
import React from "react"
import { momentObj } from "react-moment-proptypes"
import Settings from "settings"

export const RECURRENCE_TYPE = {
ONCE: "once",
Expand All @@ -22,31 +21,27 @@ const PERIOD_FORMAT = {
START_LONG: "D MMMM YYYY",
END_LONG: "D MMMM YYYY"
}
const weeksStartsWithMonday =
Settings.fields.task.customFields.assessments.objectFields.recurrence.choices
.weekly.startsWithMonday

const weekType = weeksStartsWithMonday ? "isoWeek" : "week"
const weekType = "isoWeek"

const refMondayForBiweekly =
Settings.fields.task.customFields.assessments.objectFields.recurrence.choices
.biweekly.referenceMonday
const refMondayForBiweekly = "2021-01-04" // lets select 1st monday of 2021

export const PERIOD_FACTORIES = {
[RECURRENCE_TYPE.DAILY]: (date, offset) => ({
start: date.clone().subtract(offset, "days").startOf("day"),
end: date.clone().subtract(offset, "days").endOf("day")
}),
[RECURRENCE_TYPE.WEEKLY]: (date, offset) => ({
start: date.clone().subtract(offset, "weeks").startOf(weekType),
end: date.clone().subtract(offset, "weeks").endOf(weekType)
start: date.clone().subtract(offset, "weeks").startOf("week"),
end: date.clone().subtract(offset, "weeks").endOf("week")
}),
[RECURRENCE_TYPE.BIWEEKLY]: (date, offset) => {
const refMonday = moment(refMondayForBiweekly)
// every biweekly period's start is even number of weeks apart from reference monday
const refMonday = moment(refMondayForBiweekly).startOf(weekType)
const curWeekMonday = date.startOf(weekType)

const diffInWeeks = refMonday.diff(curWeekMonday, "weeks")
// current biweekly period's start has to be even number of weeks apart from origin
// current biweekly period's start has to be even number of weeks apart from reference monday
const curBiweeklyStart =
diffInWeeks % 2 === 0
? curWeekMonday
Expand Down

0 comments on commit ed9e4c6

Please sign in to comment.