// Helpers is a small utility library
// see https://github.com/KooiInc/JSHelpers
const log = Helpers.log2Screen;
const DATE_FRIENDLY = 'WD MM dd yyyy';
Helpers.extendDate(`EN`);
log('<h3>Interval every year until 2030/1/1, no weekends</h3><hr>')
log(recurringDates(new Date('2015/1/1'),
new Date('2030/1/1'),
1, 'FullYear', true)
.map(function(v) {
return v.format(DATE_FRIENDLY);
})
.join('<br>'));
log('<hr><h3>interval every month until 2016/1/1, weekends allowed</h3><hr>');
log(recurringDates(new Date('2015/1/1'),
new Date('2016/1/1'),
1, 'Month')
.map(function(v) {
return v.format(DATE_FRIENDLY);
})
.join('<br>'));
log('<hr><h3>interval every 2 months until 2016/1/1, weekends allowed</h3><hr>');
log(recurringDates(new Date('2015/1/1'),
new Date('2016/1/1'),
2, 'Month')
.map(function(v) {
return v.format(DATE_FRIENDLY);
})
.join('<br>'));
log('<hr><h3>interval every 20 days until 2016/1/1, no weekends</h3><hr>');
log(recurringDates(new Date('2015/1/1'),
new Date('2016/1/1'),
20, 'Date', true)
.map(function(v) {
return v.format(DATE_FRIENDLY);
})
.join('<br>'));
// create a select element from a recurrent range (every 20 days until 2015/1/1)
var selectRange = document.createElement('select');
var optionstring = '<option value="{0}">{1}</option>';
var options = [String.Format(optionstring, '-1', 'select a date')];
var range = recurringDates(new Date('2015/1/1'),
new Date('2016/1/1'),
20, 'Date', true);
while (range.length) {
const curr = range.shift();
options.push(String.Format(optionstring,
curr.format('yyyy/mm/dd hh:mi:ss'),
curr.format(DATE_FRIENDLY)));
}
selectRange.innerHTML = options.join('');
document.querySelector('#result').insertAdjacentHTML(`beforebegin`, `
${selectRange.outerHTML} <span>
from 2015/01/01 to 2016/01/01, every 20 days, no weekends</span>`);
function recurringDates(startDate, endDate, interval, intervalType, noweekends) {
intervalType =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.