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

Exceptions #78

Open
ZweisteinT opened this issue Jul 15, 2017 · 3 comments
Open

Exceptions #78

ZweisteinT opened this issue Jul 15, 2017 · 3 comments

Comments

@ZweisteinT
Copy link

Hi,
sadly a programmer used this library to create some dates :( His code looks like this:

Fc = moment().recur({
                            start: Hc,
                            end: Cc,
                            rules: [{
                                units: {
                                    1: !0
                                },
                                measure: "days"
                            }],
                            exceptions: Oc
                        }), _c = Fc.next(6)

Oc is an array of dates. I expected to get the next 6 days without the dates from the exceptions... however it just gives me the next 6 dates. Is this a bug or a feature?

@c-trimm
Copy link
Owner

c-trimm commented Jul 17, 2017

What format are the dates in the exception array in? If they do not contain time information set to 0:00:00, then they will not match correctly, and therefore not be considered an exception.

Note: It's not recommended to create a recurrence using that format - usually you would only do so when importing rules that were exported with the export function.

Also, we should add support for passing arrays to the except function, as well as ensuring that the isException function removes any time information from its dates before trying to match them.

@ZweisteinT
Copy link
Author

ZweisteinT commented Jul 17, 2017

Its not my code. Previous developer seems to have written the following code:

var Uc = '"' + moment(jc[Z], "DD.MM.YYYY").format("MM/DD/YYYY") + '"';
Oc.push(Uc);
Fc = moment().recur({
                            start: Hc,
                            end: Cc,
                            rules: [{
                                units: {
                                    1: !0
                                },
                                measure: "days"
                            }],
                            exceptions: Oc
})

what format is needed for exceptions?
Maybe he tried copying your example from your github start page, which is also without time:


moment().recur({
    start: "01/01/2014",
    end: "12/31/2014",
    rules: [
        { units: {  2 : true }, measure: "days" }
    ],
    exceptions: ["01/05/2014"]
});

@c-trimm
Copy link
Owner

c-trimm commented Jul 18, 2017

I apologize, it's been a little while since I've worked deeply on this project; my last comment is untrue - moment-recur is already stripping the time information away from exception dates, so that would not be the issue.

It's hard to say what your issue is without an example using some actual dates that are being passed. I've tested my example and it skips 01/05/2014 as expected, so nothing appears to be broken. I've attempted to recreate the code you provided with some actual values and run it, and it still works as expected: https://jsfiddle.net/22tq3d3r/

Also note, for Uc, there is no reason to format the moment and convert it to a string - you can simply pass the moment moment(jc[Z], "DD.MM.YYYY") inside of an array to exceptions:
exceptions: [moment(jc[Z], "DD.MM.YYYY")].

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

2 participants