You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know that dayjs is based on momentjs and intent to replace momentjs seamlessly without any breaking changes on their API or methods.
There is something I would like to bring up to discuss is about the implementation of isBetween plugin.
From the documentation, we know that 4th parameter use to differentiate inclusive and exclusives between two input date. And for now the default behavior is excludes start and end date which is the string of ().
But for the most of use cases, or in term of wording choices that use to interpretation upon code reviewing, for example:
dayjs().isBetween('2020-10-01', '2020-10-30')
I would take it as to check whether TODAY fall between the start date and end date.
Due to the default behavior method which will exclude the 2 input date, which make this code abit misleading in my opinion. It might be right in term of the phrase between which should check whether a date is in between this 2 date.
But for the most cases, like the one I'm stated above, as a Developer we probably would like to set a start voting date and end voting date which we will hardcoded as a CONST , and in the end we might add the 4th params for inclusive will might be a redundant step.
constSTART_DATE='2020-10-01';constEND_DATE='2020-11-31';functionisValidVoteDate(){returndayjs().isBetween(START_DATE,END_DATE);}app.post('/vote',(req,res)=>{constisValid=isValidVoteDate();// return false if today date was 2020-11-31if(!isValid)return;//...omit...//});
I'm not sure the implement inclusive as default is a better idea for this situation, so I'm here to bring out a discussion about this problem, or perhaps adding the 4th params should be done as a best practice? Maybe?
The text was updated successfully, but these errors were encountered:
I know that dayjs is based on momentjs and intent to replace momentjs seamlessly without any breaking changes on their API or methods.
There is something I would like to bring up to discuss is about the implementation of
isBetween
plugin.From the documentation, we know that 4th parameter use to differentiate inclusive and exclusives between two input date. And for now the default behavior is excludes start and end date which is the string of
()
.But for the most of use cases, or in term of wording choices that use to interpretation upon code reviewing, for example:
dayjs().isBetween('2020-10-01', '2020-10-30')
I would take it as to check whether TODAY fall between the start date and end date.
Due to the default behavior method which will exclude the 2 input date, which make this code abit misleading in my opinion. It might be right in term of the phrase
between
which should check whether a date isin between
this 2 date.But for the most cases, like the one I'm stated above, as a Developer we probably would like to set a start voting date and end voting date which we will hardcoded as a CONST , and in the end we might add the 4th params for inclusive will might be a redundant step.
I'm not sure the implement inclusive as default is a better idea for this situation, so I'm here to bring out a discussion about this problem, or perhaps adding the 4th params should be done as a best practice? Maybe?
The text was updated successfully, but these errors were encountered: