-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wholeMonths interval to weeksOfMonthByDay #46
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,12 @@ | |
} | ||
} | ||
|
||
if (measure !== 'wholeMonths') { | ||
measure = measure.toLowerCase(); | ||
} | ||
|
||
return { | ||
measure: measure.toLowerCase(), | ||
measure: measure, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd really like to know why this was |
||
units: units | ||
}; | ||
} | ||
|
@@ -37,10 +41,20 @@ | |
// Get the difference between the start date and the provided date, | ||
// using the required measure based on the type of rule' | ||
var diff = null; | ||
|
||
// if the type is wholeMonths use the whole month | ||
if( date.isBefore(start) ) { | ||
diff = start.diff(date, type, true); | ||
if( type == 'wholeMonths' ) { | ||
diff = start.diff(date, 'month'); | ||
} else { | ||
diff = start.diff(date, type, true); | ||
} | ||
} else { | ||
diff = date.diff(start, type, true); | ||
if( type == 'wholeMonths' ) { | ||
diff = date.diff(start, 'month'); | ||
} else { | ||
diff = date.diff(start, type, true); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be a function. You've repeated yourself twice. |
||
} | ||
if( type == 'days') { | ||
// if we are dealing with days, we deal with whole days only. | ||
|
@@ -184,6 +198,7 @@ | |
"days": "interval", | ||
"weeks": "interval", | ||
"months": "interval", | ||
"wholeMonths": "interval", | ||
"years": "interval", | ||
"daysOfWeek": "calendar", | ||
"daysOfMonth": "calendar", | ||
|
@@ -198,6 +213,7 @@ | |
"days": "day", | ||
"weeks": "week", | ||
"months": "month", | ||
"wholeMonths": "wholeMonth", | ||
"years": "year", | ||
"daysOfWeek": "dayOfWeek", | ||
"daysOfMonth": "dayOfMonth", | ||
|
@@ -252,6 +268,10 @@ | |
if (rule.measure === 'weeksOfMonthByDay' && !this.hasRule('daysOfWeek')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we also have measure |
||
throw Error("weeksOfMonthByDay must be combined with daysOfWeek"); | ||
} | ||
|
||
if (rule.measure === 'wholeMonths' && (!this.hasRule('daysOfWeek') || !this.hasRule('weeksOfMonthByDay'))) { | ||
throw Error("wholeMonths must be combined with weeksOfMonthByDay and daysOfWeek"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the stuff in line 252 needs to go into some kind of validator function. This function itself is very overstuffed. |
||
|
||
// Remove existing rule based on measure | ||
for (var i = 0; i < this.rules.length; i++) { | ||
|
@@ -380,6 +400,9 @@ | |
|
||
case "month": | ||
return "months"; | ||
|
||
case "wholeMonth": | ||
return "wholeMonths"; | ||
|
||
case "year": | ||
return "years"; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indentation seems wrong.