Skip to content
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

Match function returning bad result #86

Open
Barakar opened this issue Nov 9, 2017 · 0 comments
Open

Match function returning bad result #86

Barakar opened this issue Nov 9, 2017 · 0 comments

Comments

@Barakar
Copy link

Barakar commented Nov 9, 2017

Hey!

I'm trying to create a recurrence that will handle event that for example occurs on Sunday and Monday every three weeks with this definition:

let cal = moment(new Date("11/12/2017")).recur().every(["Sunday","Monday"]).daysOfWeek().every(3).weeks();
cal = {
 "start": "2017-11-12T00:00:00.000Z",
 "rules": [
  {
   "measure": "daysOfWeek",
   "units": {
    "0": true,
    "1": true
   }
  },
  {
   "measure": "weeks",
   "units": {
    "3": true
   }
  }
 ],
 "exceptions": [],
 "units": null,
 "measure": null,
 "from": null
}

now I'm trying to run the following "matches" function:

console.log(cal.matches(new Date("12/03/2017 13:15:15"))); // true - exactly 3 weeks
console.log(cal.matches(new Date("12/04/2017 13:15:15"))); // false - 3 weeks and a day

The problem I noticed is that the diff dates logic considering only the start date and not the actual week -
also noticed that you solve this problem with days by floor the result

if (type == 'days') {
                // if we are dealing with days, we deal with whole days only.
                diff = parseInt(diff);
            }

In addition, flooring the diff of the weeks will cause other problems as following (assuming that we floor the diff) :

let cal = moment(new Date("11/12/2017")).recur().every(3).weeks(); 
console.log(cal.matches(new Date("12/03/2017 13:15:15"))); // true
console.log(cal.matches(new Date("12/04/2017 13:15:15"))); // also true :-|

Can you suggest any solution?

Thanks,
Barak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant