c-trimm / moment-recur Goto Github PK
View Code? Open in Web Editor NEWA momentjs plugin for matching and generating recurring dates.
License: The Unlicense
A momentjs plugin for matching and generating recurring dates.
License: The Unlicense
Great job, Casey. This is just what Ive been looking for. Would it be possible to add new methods such as
1 count(start,end) would return the number of occurrences within the given range
2 last() would give the last occurrence (only available when end date is specified)
3 get(start,end) would return an array containing all occurrences within the given period. I suppose this could be done already by specifying a from and end date and using the all() method?
one final thought. is it possible to turn off the console.logging of all Match results?
I would like to setup a recurring schedule of "every 2 weeks" starting on a specific date.
For example, suppose a schedule that starts on Tuesday, 2016-01-12 that should recur every Tuesday every other week. What is the next scheduled date after 2016-02-01? It should be 2016-02-09 (4 weeks after 2016-01-12). But the following code returns 2016-02-02.
var later = require("later");
var startDate = new Date("2016-01-12");
var fromDate = new Date("2016-02-01");
recur = later.parse.recur();
recur.every(2).weekOfYear().on([3]).dayOfWeek();
console.log(later.schedule(recur).next(1, fromDate));
So it seems later is always assuming the schedule starts on the 1st week of the year?
Please advise.
Thanks!
Steve
Moments is deprecating MM/DD/YYYY and other formats; details: moment/moment#1407
When passing the result of next dates occurence from .recur() moment-recur outputs date in MM/DD/YYYY which when passed back to moments is triggering the Date deprecation warning
Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.
The code I'm using to generate the next date array
var interval = moment.recur({
start: start_date,
end: end_date
}).every( recurring_frequency ).days();
var nextdates = interval.fromDate( today_date ).next(1,"L");
then this is what triggers the warning
console.log( moment(nextdates[0]).format('YYYY-MM-DD') );
Hello, I have just started using this awesome plugin to generate some date lists with specific rules.
I am not sure whether I am doing something wrong or it is a bug.
So my problem is as follows:
var recurrence; recurrence = moment("2015-01-01").recur("2016-01-01").every(1, "months"); allDates = recurrence.all("YYYY-MM-DD"); console.log(allDates);
This returns the expected results (array length is 13).
But if I changed the start and end dates to: "2016-01-01" and "2017-01-01" the returning array is empty.
I also tried other notations and Options method along with days/weeks/months/years. Same result.
So we cannot calculate the dates for next year?
Or is it caused by something else? Maybe the date format? I used this format because the MM/DD/YYYY format in the examples are giving a deprecation warning.
Thanks in advance!
Hi.
How can I install this in an angular2 app ?
I got momentjs working ( import * as moment from 'moment' ) but when I'm trying to import moment-recur (import 'moment-recur') I just get the error: Property 'recur' does not exist on type 'typeof moment'.
I installed both moment and moment-recur with npm.
I'm not 100% sure, but, I believe this line (moment-recur.js:737):
return moment.tz(this.format('YYYY-MM-DD'), 'UTC');
Is causing this warning:
Deprecation warning: value provided is not in a recognized ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
I think you want to do this:
return moment.tz(this.format('YYYY-MM-DDT00:00:00.000Z'), 'UTC');
or
return moment.tz(this.format('YYYY-MM-DD'), 'YYYY-MM-DD');
Currently the version in the bower package relies on version 2.4.0 of moment.js but they are up to 2.8.4. Can this be fixed?
v1.0.0 doesn't include the all method. Can you bump the version?
The format should be YYYY-MM-DD[T]00:00:00.000Z
otherwise the T
can be interpolated to an A
ISO 8601 defines the string representation for Repeating Intervals.
See https://en.wikipedia.org/wiki/ISO_8601
It would be super useful to be able to create a recurrence using:
moment.recur(isoString)
and to serialize it back as
moment.recur(...).toISOString()
e.g.,
moment().recur().every(1).days().toISOString() => "R/2016-08-21/P1D"
May I know why time is not supported? As I would like to do:
var recurrence = moment().recur("01/01/2014", "01/07/2014").every(15).minutes();
I would like to contribute if necessary. Thank you.
Method (literally or otherwise) to clone a moment recur object.
Is it possible with recur to get for e.g. dates on monday and tuesday every two weeks?
thanks for your help and this nice plugin for moments!
Moment-recur can't always correctly make the determination between the exceptions on the rule and that passed in if they are in different timezones.
In the current (latest) version the moment.tz
call in dateOnly
is like this (which is correct)
return moment.tz(this.format('YYYY-MM-DD'), 'UTC');
However, when you bower install you get an old version
return moment.tz(this.format("YYYY/MM/DD"), "UTC");
which will throw a deprecation warning
I am seeing weird results when starting a 1 month interval on 28th Feb. The recurrence matches any date >= 28 and <= 31. For example:
var r = moment.utc('2015-02-28T00:00:00.000Z').recur().every(1, 'month');
console.log(r.matches(moment.utc('2015-08-27T00:00:00Z'))); // false
console.log(r.matches(moment.utc('2015-08-28T00:00:00Z'))); // true
console.log(r.matches(moment.utc('2015-08-29T00:00:00Z'))); // true
console.log(r.matches(moment.utc('2015-08-30T00:00:00Z'))); // true
console.log(r.matches(moment.utc('2015-08-31T00:00:00Z'))); // true
console.log(r.matches(moment.utc('2015-09-01T00:00:00Z'))); // false
The same does not happen if the recurrence is started on 28th of a different month.
I have seen #4 but this seems like a different issue.
I find this to be a very versatile and useful moment plugin. I see Issues and PRs that have been lingering without resolution.
For those who have the ability to merge... are you still active here?
For others, have you found an alternative that meets your date recurrence needs?
Try to create a recurrence of 10th day of every other month
recurrence = moment().recur().every([10]).daysOfMonth().every(2).months();
Then do recurrence.next(5,"L"), the browser is crashed
I received the following error when trying to do this:
cal = moment.recur().every([1, 10]).daysOfMonth()
I'd like to thank you for this very helpful library - it promises to make easy work of date recurrence, so I'm really hoping you can help me get past these issues.
I am able to create a pattern for day of month at any interval:
r = moment(rr.start).recur(rr.until)
.every(rr.interval, rr.frequency)
.every(dom).dayOfMonth();
When I try to apply the same logic with the following patterns, the expected dates are not returned:
r = moment(rr.start).recur(rr.until)
.every(rr.interval, rr.frequency)
.every(rr.dow).dayOfWeek();
r = moment(rr.start).recur(rr.until)
.every(rr.interval, rr.frequency)
.every(dow).dayOfWeek()
.every(wom).weeksOfMonthByDay();
Please let me know if you require further information to investigate this matter.
I look forward to your reply.
Best!
I like this lib very much!
...but, I also would like to set recurring events for:
or maybe some of these can be done already but I haven't found out how ?
i saw in docs .save() function i understand thats the way to store but, to use only that then i cant do query in db side i would require to grab them all put in js and the do query so can you suggest anything?
Hi!
I guess this is intentional, but it should probably either be changed (could issue pull request) or pointed out in the README.
recurrence = moment("01/01/2014").recur().every(2).days();
recurrence.endDate("01/05/2014");
//is ["01/03/2014", "01/05/2014", "01/07/2014"], but expected ["01/03/2014", "01/05/2014"]
nextDates = recurrence.next(3, "L");
What do you think?
All best,
Matthias
I'm using this library, and for the most part it's working good. It looks like maintenance is lagging though. Wondering who is running this now, and maybe should see about moving it to the https://github.com/moment owner?
I see 6 month old issues and it's falling behind moment JS in general.
Let's say I have rule that says:
Every 20th day of the month that is Monday and I want recur to have start only and to automatically set end date so there would be 10 occurrences of event.
Is it possible?
Using moment.js 2.10.6, deprecation messages are displayed using an example from the README.md. Specifically:
recurrence = moment("2014/01/01").recur().every(2).days();
Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to moment/moment#1407 for more info.
Error
at Function.createFromInputFallback (https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js:746:36)
at configFromString (https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js:826:32)
at configFromInput (https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js:1353:13)
at prepareConfig (https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js:1340:13)
at createFromConfig (https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js:1307:44)
at createLocalOrUTC (https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js:1385:16)
at local__createLocal (https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js:1389:16)
at utils_hooks__hooks (https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js:16:29)
at eval (eval at evaluate (unknown source), :1:14)
at Object.InjectedScript._evaluateOn (:904:55)
In Google Calendar, when you start a recurrence with let's say the 5th monday of a month, on the next month if there is only 4 mondays it will match the last one. I would expect this library to do the same.
Here's a test case scenario:
moment({ date: 31, month: 2, year: 2014 }) // 5th monday of march 2014
.recur()
.every(1).daysOfWeek() // monday
.every(4) // fifth monday
.weeksOfMonthByDay()
.matches(moment({ date: 31, month: 7, year: 2015 })) // aug 31st 2015, 5th monday
// returns true
moment({ date: 31, month: 2, year: 2014 }) // 5th monday of march 2014
.recur()
.every(1).daysOfWeek() // monday
.every(4).weeksOfMonthByDay() // fifth monday
.matches(moment({ date: 24, month: 10, year: 2014 })) // nov 24th 2014, 4th monday
// returns false
Thank you
Hi,
there is an failure in the interval...
if i have a start date i.e. 2014-01-31 and an interval of 1 month
the next date is the 2014-03-31 so its not 1 month as except... its 2 month interval...
the correct interval must return the last day of the month if the next month will have a lower count of days...
Do you have any plans on this?
moment-recur to rrule and back
When to update the 1.0.4 version to the npm?
Can I do this with recur:
"every first/second/fourth/last monday every two months"?
Eg
moment().recur().setRecurStart('<week ago>')
Thanks a lot.
ps. AMAZING library.
Is it possible to set rule like 100th day of the year
?
When I want to match a day with e.g. the last day of a month that has only 30 days, the method "matches" will return a false "true"
const rc = moment("2017-04-30").recur().every(1,"months");
console.log(rc.matches("05/30/2017")); //true
console.log(rc.matches("05/31/2017")); //true
Is this a bug? Or am I doing something wrong here? This is only happening, if the recurring start date is the last of a 30 day month or if we choose the last of February and match it with any other day of the month higher than 28.
Hello,
The code below from examples produces "Deprecation warning: months accessor is deprecated. Use month instead."
var valentines = moment().recur("2014-01-01", "2014-05-05").
every(14).daysOfMonth().every("Februray").monthsOfYear();
console.log(util.inspect(valentines.next(3, 'L')));
Best Regards,
Hello,
I have a problem initializing moment-recur.
TypeError: Object Wed Jan 01 2014 00:00:00 GMT+0100 has no method 'utcOffset'
at Moment.moment.fn.dateOnly (.../node_modules/moment-recur/moment-recur.js:745:81)
Maybe this is just a version mismatch (I still have a .zone() method available) ?
Versions used (in my package.json) :
"moment": "~2.5.1",
"moment-recur": "^1.0.5"
Please let me know if I did something wrong.
Update :
Running npm install --dev && gulp test gives the following output
$ gulp test
[12:23:53] Using gulpfile ...moment-recur/gulpfile.js
[12:23:53] Starting 'test'...
WARN [watcher]: Pattern "...moment-recur/bower_components/moment/moment.js" does not match any file.
WARN [watcher]: Pattern "...moment-recur/bower_components/moment-timezone/builds/moment-timezone-with-data.js" does not match any file.
INFO [karma]: Karma v0.12.35 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
WARN [web-server]: 404: /favicon.ico
INFO [Chromium 41.0.2272 (Ubuntu 0.0.0)]: Connected on socket MHC2liVo15IFgc3EzIJc with id 50993294
Chromium 41.0.2272 (Ubuntu 0.0.0) ERROR
Uncaught Error: Can't find moment
at ...node_modules/moment-recur/moment-recur.js:15
[12:24:08] 'test' errored after 14 s
[12:24:08] Error: 1
at formatError (/usr/local/lib/node_modules/gulp/bin/gulp.js:169:10)
at Gulp.<anonymous> (/usr/local/lib/node_modules/gulp/bin/gulp.js:195:15)
at Gulp.emit (events.js:107:17)
at Gulp.Orchestrator._emitTaskDone (...moment-recur/node_modules/gulp/node_modules/orchestrator/index.js:264:8)
at ...node_modules/moment-recur/node_modules/gulp/node_modules/orchestrator/index.js:275:23
at finish (...moment-recur/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
at cb (...node_modules/moment-recur/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:29:3)
at removeAllListeners (...moment-recur/node_modules/karma/lib/server.js:218:7)
at Server.<anonymous> (...node_modules/moment-recur/node_modules/karma/lib/server.js:229:9)
at Server.g (events.js:199:16)
It doesn't work with the way I'm trying to install this (in a docker container - bower can't be run as root and the docker container only has root). Why does it need bower?
I am trying to change daysOfWeek rules. The source data I am working with uses 1-7.
But it's unclear how I can make this change. This is what I have so far, but the documentation is lacking details.
moment().recur({
rules: [
{ units: { low: 1, high: 7 }, measure: "daysOfWeek" }
]
});
This repository seems to be defunct but this plugin is very useful. Since @c-trimm has not touched it in 6 months I have made some updates and moved it to: https://github.com/bramski/moment-recur-js
@c-trimm If you want to continue working and updating this project please let me know! I'm taking ownership because I need this plugin to work and move forward with moment.
The version downloaded from NPM uses a non-ISO date (YYYY/MM/DD) at
https://github.com/c-trimm/moment-recur/blob/master/moment-recur.js#L737
This causes the moment warning: "Deprecation warning: value provided is not in a recognized ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments"
master
has the correct format of YYYY-MM-DD.
From the README.md I used this example:
// Create a recurrence
recurrence = moment("01/01/2014").recur().every(2).days();
// Generate the next three dates as moments
// Outputs: [moment("01/03/2014"), moment("01/05/2014"), moment("01/07/2014")]
nextDates = recurrence.next(3);
My outputs are:
// Outputs: [moment("01/02/2014"), moment("01/04/2014"), moment("01/06/2014")]
Hi,
Great library!
I was wondering how a use case like this could be realised:
Say you have an event that is happening weekly. Now you want to view a specific day (in a calendar day view maybe) and see which events are happening on that day.
Or you want to list all events happening in the future.
As a dirty fix for now I fetch all events, generate the occurrences and then filter down. This works with a few events in a databse but obviously not with more.
Any ideas on that?
David
I am trying to get an occurrence that starts say now, and occurs every two weeks on a Monday.
moment().recur().every('Monday').dayOfWeek().every(2).weeks().next(1,"L")
This crashes my app and I can't figure out a way of achieving what I want.
I'm not sure exactly which moment-recur method gives this warning, however:
Deprecation warning: moment().add(period, number) is deprecated. Please use moment().add(number, period).
The JS specifically, example.html
https://bitbucket.org/gso/eonjs/
Why when I install the moment-recur I need install bower plugins?
Can you please include a minified version in the bower package as well as the expanded version
It seems remiss not to support parsing ISO8601 recurring intervals like R/2015-01-14/P2W
.
Love this library, thank you!
I have a case (which I'm not sure would be overly specific to me), where I need to be able to set a start date for an interval, setup necessary recurrence and then get the "next x" dates. I don't want to specify the end date (though we do take this value from the user, but it could be wrong, and the number of dates is always "correct").
For simplicity, let's say I want to do a weekly recurrence (in truth I can do weekly, fortnightly or monthly).
var startDate = "2015-02-25";
var intervals = moment(startDate).recur().every(1).week();
intervals.except(self.tournament().params.DatesNotPlayed());
I then run the following and store the resulting array somewhere for use later:
var allDates = intervals.next(numberOfRounds);
The result will be x dates where x is numberOfRounds
. It DOESN'T include the start date, though, and I want it to.
I've tried using the .all() function but of course then I can't control how many dates I get, and if I use a user-defined "end" date, it may not end up in enough dates being generated.
A spanner in the works (I just realised I'm not doing this yet!) is that I still have to also implement it including the "day of week" to recur on, so e.g. every Wednesday weekly, every Wednesday fortnightly, or every Wednesday monthly. I'm imagining i would do this by first manipulating my start date to be the next Wednesday (or whatever day) after the given start date inclusive.
Is there any way of doing what I need to do now, or if not do you have any reason for it not being there? I can try to come up with a solution for it if you like, if you'd like to see it in there.
How do I generate a rule the returns every 2nd fridays?
moment("2017-05-01").recur("2017-05-31").every("friday").daysOfWeek().every(2).weeks();
produces no dates. Shouldn't it return May 5th and May 19th?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.