mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-29 11:12:23 +08:00
Merge pull request #3643 from tigerswithguitars/laterjs
Later - Define schedules and calculate future or previous schedule occurrences.
This commit is contained in:
@@ -0,0 +1,631 @@
|
||||
/// <reference path="./later.d.ts"/>
|
||||
|
||||
|
||||
module LaterTest_DefineSchedule {
|
||||
|
||||
// define a new schedule
|
||||
var textSched = later.parse.text('at 10:15am every weekday');
|
||||
var cronSched = later.parse.cron('0 0/5 14,18 * * ?');
|
||||
var recurSched = later.parse.recur().last().dayOfMonth();
|
||||
var manualSched = <Later.IScheduleData>{ schedules: [ <Later.IRecurrence>{ M: [ 3 ], D: [ 21 ] } ] };
|
||||
|
||||
// this schedule will fire on the closest weekday to the 15th
|
||||
// every month at 2:00 am except in March
|
||||
var complexSched = later.parse.recur()
|
||||
.on(15).dayOfMonth().onWeekday().on(2).hour()
|
||||
.and()
|
||||
.on(14).dayOfMonth().on(6).dayOfWeek().on(2).hour()
|
||||
.and()
|
||||
.on(16).dayOfMonth().on(2).dayOfWeek().on(2).hour()
|
||||
.except()
|
||||
.on(3).month();
|
||||
}
|
||||
|
||||
module LaterTest_ConfigureTimezone {
|
||||
|
||||
// set later to use UTC (the default)
|
||||
later.date.UTC();
|
||||
|
||||
// set later to use local time
|
||||
later.date.localTime();
|
||||
}
|
||||
|
||||
module LaterTest_TimePeriods {
|
||||
export function second() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.second.name;
|
||||
// 'second'
|
||||
|
||||
later.second.range;
|
||||
// 1
|
||||
|
||||
later.second.val(d);
|
||||
// 5
|
||||
|
||||
later.second.isValid(d, 10);
|
||||
// false
|
||||
|
||||
later.second.extent();
|
||||
// [0, 59]
|
||||
|
||||
later.second.start(d);
|
||||
// 'Fri, 22 Mar 2013 10:02:05 GMT'
|
||||
|
||||
later.second.end(d);
|
||||
// 'Fri, 22 Mar 2013 10:02:05 GMT'
|
||||
|
||||
later.second.next(d, 27);
|
||||
// 'Fri, 22 Mar 2013 10:02:27 GMT'
|
||||
|
||||
later.second.prev(d, 27);
|
||||
// 'Fri, 22 Mar 2013 10:01:27 GMT'
|
||||
}
|
||||
|
||||
export function minute() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.minute.name;
|
||||
// 'minute'
|
||||
|
||||
later.minute.range;
|
||||
// 60
|
||||
|
||||
later.minute.val(d);
|
||||
// 2
|
||||
|
||||
later.minute.isValid(d, 2);
|
||||
// true
|
||||
|
||||
later.minute.extent();
|
||||
// [0, 59]
|
||||
|
||||
later.minute.start(d);
|
||||
// 'Fri, 22 Mar 2013 10:02:00 GMT'
|
||||
|
||||
later.minute.end(d);
|
||||
// 'Fri, 22 Mar 2013 10:02:59 GMT'
|
||||
|
||||
later.minute.next(d, 27);
|
||||
// 'Fri, 22 Mar 2013 10:27:00 GMT'
|
||||
|
||||
later.minute.prev(d, 27);
|
||||
// 'Fri, 22 Mar 2013 09:27:59 GMT'
|
||||
}
|
||||
|
||||
export function hour() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.hour.name;
|
||||
// 'hour'
|
||||
|
||||
later.hour.range;
|
||||
// 3600
|
||||
|
||||
later.hour.val(d);
|
||||
// 10
|
||||
|
||||
later.hour.isValid(d, 2);
|
||||
// false
|
||||
|
||||
later.hour.extent();
|
||||
// [0, 23]
|
||||
|
||||
later.hour.start(d);
|
||||
// 'Fri, 22 Mar 2013 10:00:00 GMT'
|
||||
|
||||
later.hour.end(d);
|
||||
// 'Fri, 22 Mar 2013 10:59:59 GMT'
|
||||
|
||||
later.hour.next(d, 5);
|
||||
// 'Sat, 23 Mar 2013 05:00:00 GMT'
|
||||
|
||||
later.hour.prev(d, 21);
|
||||
// 'Thu, 21 Mar 2013 21:59:59 GMT'
|
||||
}
|
||||
|
||||
export function time() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.time.name;
|
||||
// 'time'
|
||||
|
||||
later.time.range;
|
||||
// 1
|
||||
|
||||
later.time.val(d);
|
||||
// 36125
|
||||
|
||||
later.time.isValid(d, 36125);
|
||||
// true
|
||||
|
||||
later.time.extent();
|
||||
// [0, 86399]
|
||||
|
||||
later.time.start(d);
|
||||
// 'Fri, 22 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.time.end(d);
|
||||
// 'Fri, 22 Mar 2013 23:59:59 GMT'
|
||||
|
||||
later.time.next(d, 60);
|
||||
// 'Sat, 23 Mar 2013 00:01:00 GMT'
|
||||
|
||||
later.time.prev(d, 60);
|
||||
// 'Fri, 22 Mar 2013 00:01:00 GMT'
|
||||
}
|
||||
|
||||
export function day() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.day.name;
|
||||
// 'day'
|
||||
|
||||
later.day.range;
|
||||
// 86400
|
||||
|
||||
later.day.val(d);
|
||||
// 22
|
||||
|
||||
later.day.isValid(d, 3);
|
||||
// false
|
||||
|
||||
later.day.extent(d);
|
||||
// [1, 31]
|
||||
|
||||
later.day.start(d);
|
||||
// 'Fri, 22 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.day.end(d);
|
||||
// 'Fri, 22 Mar 2013 23:59:59 GMT'
|
||||
|
||||
later.day.next(d, 11);
|
||||
// 'Thu, 11 Apr 2013 00:00:00 GMT'
|
||||
|
||||
later.day.prev(d, 2);
|
||||
// 'Sat, 02 Mar 2013 23:59:59 GMT'
|
||||
}
|
||||
|
||||
export function day_of_week() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.dayOfWeek.name;
|
||||
// 'day of week'
|
||||
|
||||
later.dayOfWeek.range;
|
||||
// 86400
|
||||
|
||||
later.dayOfWeek.val(d);
|
||||
// 6
|
||||
|
||||
later.dayOfWeek.isValid(d, 3);
|
||||
// false
|
||||
|
||||
later.dayOfWeek.extent();
|
||||
// [1, 7]
|
||||
|
||||
later.dayOfWeek.start(d);
|
||||
// 'Fri, 22 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.dayOfWeek.end(d);
|
||||
// 'Fri, 22 Mar 2013 23:59:59 GMT'
|
||||
|
||||
later.dayOfWeek.next(d, 1);
|
||||
// 'Sun, 24 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.dayOfWeek.prev(d, 5);
|
||||
// 'Thu, 21 Mar 2013 23:59:59 GMT'
|
||||
}
|
||||
|
||||
export function day_of_week_count() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.dayOfWeekCount.name;
|
||||
// 'day of week count'
|
||||
|
||||
later.dayOfWeekCount.range;
|
||||
// 604800
|
||||
|
||||
later.dayOfWeekCount.val(d);
|
||||
// 4
|
||||
|
||||
later.dayOfWeekCount.isValid(d, 4);
|
||||
// true
|
||||
|
||||
later.dayOfWeekCount.extent(d);
|
||||
// [1, 5]
|
||||
|
||||
later.dayOfWeekCount.start(d);
|
||||
// 'Fri, 22 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.dayOfWeekCount.end(d);
|
||||
// 'Thu, 28 Mar 2013 23:59:59 GMT'
|
||||
|
||||
// zero is special cased and means the last instance of
|
||||
// a day of the week in the month, instead of meaning the
|
||||
// first day of the week with the highest instance count
|
||||
// which would have been Mar 29 with value 5.
|
||||
later.dayOfWeekCount.next(d, 0);
|
||||
// 'Mon, 25 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.dayOfWeekCount.prev(d, 2);
|
||||
// 'Thu, 14 Mar 2013 23:59:59 GMT'
|
||||
}
|
||||
|
||||
export function day_of_year() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.dayOfYear.name;
|
||||
// 'day of year'
|
||||
|
||||
later.dayOfYear.range;
|
||||
// 86400
|
||||
|
||||
later.dayOfYear.val(d);
|
||||
// 81
|
||||
|
||||
later.dayOfYear.isValid(d, 4);
|
||||
// false
|
||||
|
||||
later.dayOfYear.extent(d);
|
||||
// [1, 365]
|
||||
|
||||
later.dayOfYear.start(d);
|
||||
// 'Fri, 22 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.dayOfYear.end(d);
|
||||
// 'Fri, 22 Mar 2013 23:59:59 GMT'
|
||||
|
||||
later.dayOfYear.next(d, 256);
|
||||
// 'Fri, 13 Sep 2013 00:00:00 GMT'
|
||||
|
||||
later.dayOfYear.prev(d, 44);
|
||||
// 'Wed, 13 Feb 2013 23:59:59 GMT'
|
||||
}
|
||||
|
||||
export function week_of_month() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.weekOfMonth.name;
|
||||
// 'week of month'
|
||||
|
||||
later.weekOfMonth.range;
|
||||
// 604800
|
||||
|
||||
later.weekOfMonth.val(d);
|
||||
// 4
|
||||
|
||||
later.weekOfMonth.isValid(d, 4);
|
||||
// true
|
||||
|
||||
later.weekOfMonth.extent(d);
|
||||
// [1, 6]
|
||||
|
||||
later.weekOfMonth.start(d);
|
||||
// 'Sun, 17 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.weekOfMonth.end(d);
|
||||
// 'Sat, 23 Mar 2013 23:59:59 GMT'
|
||||
|
||||
later.weekOfMonth.next(d, 1);
|
||||
// 'Mon, 01 Apr 2013 00:00:00 GMT'
|
||||
|
||||
later.weekOfMonth.prev(d, 2);
|
||||
// 'Sat, 09 Mar 2013 23:59:59 GMT'
|
||||
}
|
||||
|
||||
export function week_of_year() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.weekOfYear.name;
|
||||
// 'week of year'
|
||||
|
||||
later.weekOfYear.range;
|
||||
// 604800
|
||||
|
||||
later.weekOfYear.val(d);
|
||||
// 12
|
||||
|
||||
later.weekOfYear.isValid(d, 21);
|
||||
// false
|
||||
|
||||
later.weekOfYear.extent(d);
|
||||
// [1, 52]
|
||||
|
||||
later.weekOfYear.start(d);
|
||||
// 'Mon, 18 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.weekOfYear.end(d);
|
||||
// 'Sun, 24 Mar 2013 23:59:59 GMT'
|
||||
|
||||
later.weekOfYear.next(d, 47);
|
||||
// 'Mon, 18 Nov 2013 00:00:00 GMT'
|
||||
|
||||
later.weekOfYear.prev(d, 52);
|
||||
// 'Sun, 30 Dec 2012 23:59:59 GMT'
|
||||
}
|
||||
|
||||
export function month() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.month.name;
|
||||
// 'month'
|
||||
|
||||
later.month.range;
|
||||
// 2629740
|
||||
|
||||
later.month.val(d);
|
||||
// 3
|
||||
|
||||
later.month.isValid(d, 3);
|
||||
// true
|
||||
|
||||
later.month.extent();
|
||||
// [1, 12]
|
||||
|
||||
later.month.start(d);
|
||||
// 'Fri, 01 Mar 2013 00:00:00 GMT'
|
||||
|
||||
later.month.end(d);
|
||||
// 'Sun, 31 Mar 2013 23:59:59 GMT'
|
||||
|
||||
later.month.next(d, 11);
|
||||
// 'Fri, 01 Nov 2013 00:00:00 GMT'
|
||||
|
||||
later.month.prev(d, 2);
|
||||
// 'Thu, 28 Feb 2013 23:59:59 GMT'
|
||||
}
|
||||
|
||||
export function year() {
|
||||
var d = new Date('2013-03-22T10:02:05Z');
|
||||
|
||||
later.year.name;
|
||||
// 'year'
|
||||
|
||||
later.year.range;
|
||||
// 31556900
|
||||
|
||||
later.year.val(d);
|
||||
// 2013
|
||||
|
||||
later.year.isValid(d, 2013);
|
||||
// true
|
||||
|
||||
later.year.extent();
|
||||
// [1970, 2099]
|
||||
|
||||
later.year.start(d);
|
||||
// 'Tue, 01 Jan 2013 00:00:00 GMT'
|
||||
|
||||
later.year.end(d);
|
||||
// 'Tue, 31 Dec 2013 23:59:59 GMT'
|
||||
|
||||
later.year.next(d, 2014);
|
||||
// 'Wed, 01 Jan 2014 00:00:00 GMT'
|
||||
|
||||
later.year.prev(d, 2012);
|
||||
// 'Mon, 31 Dec 2012 23:59:59 GMT'
|
||||
}
|
||||
|
||||
export interface IPartOfDayLater extends Later.IStatic {
|
||||
partOfDay: Later.ITimePeriod;
|
||||
}
|
||||
|
||||
export function custom() {
|
||||
|
||||
var customLater = <IPartOfDayLater>later;
|
||||
|
||||
customLater.partOfDay = {
|
||||
|
||||
name: 'part of day',
|
||||
|
||||
range: later.hour.range * 6,
|
||||
|
||||
val: function(d: Date): number {
|
||||
return later.hour.val(d) < 12
|
||||
? 0
|
||||
: later.hour.val(d) < 18
|
||||
? 1
|
||||
: 2;
|
||||
},
|
||||
|
||||
isValid: function(d: Date, val: any) {
|
||||
return customLater.partOfDay.val(d) === val;
|
||||
},
|
||||
|
||||
extent: function(date?: Date) {
|
||||
return [0, 2];
|
||||
},
|
||||
|
||||
start: function(date: Date) {
|
||||
var hour = customLater.partOfDay.val(date) === 0
|
||||
? 0
|
||||
: customLater.partOfDay.val(date) === 1
|
||||
? 12
|
||||
: 18;
|
||||
|
||||
return later.date.next(
|
||||
later.year.val(date),
|
||||
later.month.val(date),
|
||||
later.day.val(date),
|
||||
hour
|
||||
);
|
||||
},
|
||||
|
||||
end: function(date: Date) {
|
||||
var hour = customLater.partOfDay.val(date) === 0
|
||||
? 11
|
||||
: customLater.partOfDay.val(date) === 1
|
||||
? 5
|
||||
: 23;
|
||||
|
||||
return later.date.prev(
|
||||
later.year.val(date),
|
||||
later.month.val(date),
|
||||
later.day.val(date),
|
||||
hour
|
||||
);
|
||||
},
|
||||
|
||||
next: function(date: Date, val: any) {
|
||||
var hour = val === 0
|
||||
? 0
|
||||
: val === 1
|
||||
? 12
|
||||
: 18;
|
||||
|
||||
return later.date.next(
|
||||
later.year.val(date),
|
||||
later.month.val(date),
|
||||
// increment the day if we already passed the desired time period
|
||||
later.day.val(date) + (hour < later.hour.val(date) ? 1 : 0),
|
||||
hour
|
||||
);
|
||||
},
|
||||
|
||||
prev: function(date: Date, val: any) {
|
||||
var hour = val === 0
|
||||
? 11
|
||||
: val === 1
|
||||
? 5
|
||||
: 23;
|
||||
|
||||
return later.date.prev(
|
||||
later.year.val(date),
|
||||
later.month.val(date),
|
||||
// decrement the day if we already passed the desired time period
|
||||
later.day.val(date) + (hour > later.hour.val(date) ? -1 : 0),
|
||||
hour
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module LaterTest_GenerateRecurences {
|
||||
|
||||
export function on_method() {
|
||||
// fires on the 2nd minute every hour
|
||||
later.parse.recur().on(2).minute();
|
||||
|
||||
// fires every day at 8am and 8pm
|
||||
later.parse.recur().on(8, 20).hour();
|
||||
|
||||
// fires every day at 8am
|
||||
later.parse.recur().on('08:00:00').time();
|
||||
}
|
||||
|
||||
export function first_method() {
|
||||
// fires on the 0th minute of every hour
|
||||
later.parse.recur().first().minute();
|
||||
}
|
||||
|
||||
export function last_method() {
|
||||
// fires on the last day of every month at 5am
|
||||
later.parse.recur().on(5).hour().last().dayOfMonth();
|
||||
}
|
||||
|
||||
export function onWeekend_method() {
|
||||
// fires on the 5th minute of every hour during Sat and Sun
|
||||
later.parse.recur().on(5).minute().onWeekend();
|
||||
}
|
||||
|
||||
export function onWeekday_method() {
|
||||
// fires on the 5th minute of every hour during Mon,Tues,Wed,Thur,Fri
|
||||
later.parse.recur().on(5).minute().onWeekday();
|
||||
}
|
||||
|
||||
export function every_method() {
|
||||
// fires on the 0th, 10th, 20th, 30th, 40th, and 50th min of every hour
|
||||
later.parse.recur().every(10).minute();
|
||||
|
||||
// fires on first second of Jan, Apr, July, Oct
|
||||
later.parse.recur().every(3).month();
|
||||
}
|
||||
|
||||
export function after_method() {
|
||||
// fires on the 55th, 56th, 57th, 58th, and 59th minute
|
||||
later.parse.recur().after(55).minute();
|
||||
|
||||
// fires at 12 noon and 6pm
|
||||
later.parse.recur().every(6).hour().after('09:00').time();
|
||||
}
|
||||
|
||||
export function before_method() {
|
||||
// fires on the first second of January and February
|
||||
later.parse.recur().before(3).month();
|
||||
|
||||
// fires at 6am every day
|
||||
later.parse.recur().every(6).hour().before('09:00').time();
|
||||
|
||||
// fires between 9am and 6pm every day
|
||||
later.parse.recur().after('09:00').time().before('18:00').time();
|
||||
later.parse.recur().after(9).hour().before(18).hour();
|
||||
}
|
||||
|
||||
export function startingOn_method() {
|
||||
// fires on the 10th, 25th, 40th, and 55th minute of every hour
|
||||
later.parse.recur().every(15).minute().startingOn(10);
|
||||
}
|
||||
|
||||
export function between_method() {
|
||||
// fires on the 10th, 25th, 40th minute of every hour
|
||||
later.parse.recur().every(15).minute().between(10, 40);
|
||||
}
|
||||
|
||||
export function and_method() {
|
||||
// fires every 2 hours on the first day of every month
|
||||
// and 8:00am and 8:00pm on the last day of every month
|
||||
var sched = later.parse.recur()
|
||||
.every(2).hour().first().dayOfMonth()
|
||||
.and()
|
||||
.on(8, 20).hour().last().dayOfMonth()
|
||||
}
|
||||
|
||||
export function except_method() {
|
||||
// fires every minute of every hour except on multiples of 2 and 3
|
||||
var sched = later.parse.recur()
|
||||
.every().minute()
|
||||
.except()
|
||||
.every(2).minute().between(2, 59)
|
||||
.and()
|
||||
.every(3).minute().between(3, 59);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module LaterTest_CalculateOccurences {
|
||||
|
||||
// Initialise next variable.
|
||||
var next: Date[] = [];
|
||||
|
||||
// calculate the next 10 occurrences of a recur schedule
|
||||
var recurSched = later.parse.recur().last().dayOfMonth();
|
||||
|
||||
next = later.schedule(recurSched).next(10);
|
||||
|
||||
// calculate the previous occurrence starting from March 21, 2013
|
||||
var cronSched = later.parse.cron('0 0/5 14,18 * * ?');
|
||||
|
||||
next = later.schedule(cronSched).prev(1, new Date(2013, 2, 21));
|
||||
}
|
||||
|
||||
module LaterTest_ExecuteCodeUsingSchedule {
|
||||
|
||||
// will fire every 5 minutes
|
||||
var textSched = later.parse.text('every 5 min');
|
||||
|
||||
// execute logTime one time on the next occurrence of the text schedule
|
||||
var timer = later.setTimeout(logTime, textSched);
|
||||
|
||||
// execute logTime for each successive occurrence of the text schedule
|
||||
var timer2 = later.setInterval(logTime, textSched);
|
||||
|
||||
// function to execute
|
||||
function logTime() {
|
||||
console.log(new Date());
|
||||
}
|
||||
|
||||
// clear the interval timer when you are done
|
||||
timer2.clear();
|
||||
}
|
||||
Vendored
+673
@@ -0,0 +1,673 @@
|
||||
// Type definitions for LaterJS
|
||||
// Project: http://bunkat.github.io/later/
|
||||
// Definitions by: Jason D Dryhurst-Smith <http://jasonds.co.uk/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module Later {
|
||||
|
||||
export interface IScheduleData {
|
||||
|
||||
/**
|
||||
* A list of recurrence information as a composite schedule.
|
||||
*/
|
||||
schedules: IRecurrence[];
|
||||
|
||||
/**
|
||||
* A list of exceptions to the composite recurrence information.
|
||||
*/
|
||||
exceptions: IRecurrence[];
|
||||
|
||||
/**
|
||||
* A code to identify any errors in the composite schedule and exceptions.
|
||||
* The number tells you the position of the error within the schedule.
|
||||
*/
|
||||
error: number;
|
||||
}
|
||||
|
||||
export interface IRecurrence {
|
||||
|
||||
/** Time in seconds from midnight.
|
||||
*/
|
||||
t?: number[];
|
||||
/** Seconds in minute.
|
||||
*/
|
||||
s?: number[];
|
||||
/** Minutes in hour.
|
||||
*/
|
||||
m?: number[];
|
||||
/** Hour in day.
|
||||
*/
|
||||
h?: number[];
|
||||
/** Day of the month.
|
||||
*/
|
||||
D?: number[];
|
||||
/** Day in week.
|
||||
*/
|
||||
dw?: number[];
|
||||
/** Nth day of the week in month.
|
||||
*/
|
||||
dc?: number[];
|
||||
/** Day in year.
|
||||
*/
|
||||
dy?: number[];
|
||||
/** Week in month.
|
||||
*/
|
||||
wm?: number[];
|
||||
/** ISO week in year.
|
||||
*/
|
||||
wy?: number[];
|
||||
/** Month in year.
|
||||
*/
|
||||
M?: number[];
|
||||
/** Year.
|
||||
*/
|
||||
Y?: number[];
|
||||
|
||||
/** After modifiers.
|
||||
*/
|
||||
t_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
s_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
m_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
h_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
D_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
dw_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
dc_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
dy_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
wm_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
wy_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
M_a?: number[];
|
||||
/** After modifiers.
|
||||
*/
|
||||
Y_a?: number[];
|
||||
|
||||
/** Before modifiers.
|
||||
*/
|
||||
t_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
s_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
m_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
h_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
D_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
dw_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
dc_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
dy_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
wm_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
wy_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
M_b?: number[];
|
||||
/** Before modifiers.
|
||||
*/
|
||||
Y_b?: number[];
|
||||
|
||||
/*
|
||||
* Custom Time Periods and Modifiers
|
||||
* For acces to custom time periods created as extension to the later static type
|
||||
* and modifiers created on the later modifier static type.
|
||||
*/
|
||||
[ timeperiodAndModifierName: string ]: number[];
|
||||
}
|
||||
|
||||
export interface IParseStatic {
|
||||
|
||||
/**
|
||||
* Create a recurrence builder for building schedule data.
|
||||
*/
|
||||
recur(): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Create schedule data by parsing a cron string
|
||||
*
|
||||
* @param {string} [input] - A string value to parse.
|
||||
*/
|
||||
cron(input?: string): IScheduleData;
|
||||
|
||||
/**
|
||||
* Create schedule data by paring a human readable string.
|
||||
*
|
||||
* @param {string} [input] - A string value to parse.
|
||||
*/
|
||||
text(input?: string): IScheduleData;
|
||||
}
|
||||
|
||||
export interface ITimer {
|
||||
|
||||
/**
|
||||
* Clear the timer and end execution.
|
||||
*/
|
||||
clear(): void;
|
||||
}
|
||||
|
||||
export interface ISchedule {
|
||||
|
||||
/**
|
||||
* Finds the next valid instance or instances of the current schedule,
|
||||
* optionally between a specified start and end date. Start date is
|
||||
* Date.now() by default, end date is unspecified. Start date must be
|
||||
* smaller than end date.
|
||||
*
|
||||
* @param {number} numberOfInst: The number of instances to return
|
||||
* @param {Date} dateFrom: The earliest a valid instance can occur
|
||||
* @param {Date} dateTo: The latest a valid instance can occur
|
||||
*/
|
||||
next(numberOfInst: number, dateFrom?: Date, dateTo?: Date): Date[];
|
||||
|
||||
/**
|
||||
* Finds the next valid range or ranges of the current schedule,
|
||||
* optionally between a specified start and end date. Start date is
|
||||
* Date.now() by default, end date is unspecified. Start date must be
|
||||
* greater than end date.
|
||||
*
|
||||
* @param {number} numberOfInst: The number of ranges to return
|
||||
* @param {Date} dateFrom: The earliest a valid range can occur
|
||||
* @param {Date} dateTo: The latest a valid range can occur
|
||||
*/
|
||||
nextRange(numberOfInst: number, dateFrom?: Date, dateTo?: Date): Date[];
|
||||
|
||||
/**
|
||||
* Finds the previous valid instance or instances of the current schedule,
|
||||
* optionally between a specified start and end date. Start date is
|
||||
* Date.now() by default, end date is unspecified. Start date must be
|
||||
* greater than end date.
|
||||
*
|
||||
* @param {number} numberOfInst: The number of instances to return
|
||||
* @param {Date} dateFrom: The earliest a valid instance can occur
|
||||
* @param {Date} dateTo: The latest a valid instance can occur
|
||||
*/
|
||||
prev(numberOfInst: number, dateFrom?: Date, dateTo?: Date): Date[];
|
||||
|
||||
/**
|
||||
* Finds the previous valid range or ranges of the current schedule,
|
||||
* optionally between a specified start and end date. Start date is
|
||||
* Date.now() by default, end date is unspecified. Start date must be
|
||||
* greater than end date.
|
||||
*
|
||||
* @param {number} numberOfInst: The number of ranges to return
|
||||
* @param {Date} dateFrom: The earliest a valid range can occur
|
||||
* @param {Date} dateTo: The latest a valid range can occur
|
||||
*/
|
||||
prevRange(numberOfInst: number, dateFrom?: Date, dateTo?: Date): Date[];
|
||||
}
|
||||
|
||||
export interface IRecurrenceBuilder extends IScheduleData {
|
||||
|
||||
/** a time period
|
||||
*/
|
||||
second(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
minute(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
hour(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
time(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
dayOfWeek(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
dayOfWeekCount(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
dayOfMonth(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
dayOfYear(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
weekOfMonth(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
weekOfYear(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
month(): IRecurrenceBuilder;
|
||||
/** a time period
|
||||
*/
|
||||
year(): IRecurrenceBuilder;
|
||||
|
||||
/** a time period
|
||||
*/
|
||||
fullDate(): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Specifies one or more specific vals of a time period information provider.
|
||||
* When used to specify a time, a string indicating the 24-hour time may be used.
|
||||
*
|
||||
* @param {number[]} values - A list of values.
|
||||
*/
|
||||
on(...values: number[]): IRecurrenceBuilder;
|
||||
/**
|
||||
* Specifies one or more specific vals of a time period information provider.
|
||||
* When used to specify a time, a string indicating the 24-hour time may be used.
|
||||
*
|
||||
* @param {string} value - A string representing your value.
|
||||
*/
|
||||
on(value: string): IRecurrenceBuilder;
|
||||
/**
|
||||
* Specifies one or more specific vals of a time period information provider.
|
||||
* When used to specify a time, a string indicating the 24-hour time may be used.
|
||||
*
|
||||
* @param {Date} date - A Date representing your value.
|
||||
*/
|
||||
on(date: Date): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Preceed a time period.
|
||||
*
|
||||
* @param {number} [value] - A number representing your value.
|
||||
*/
|
||||
every(value?: number): IRecurrenceBuilder;
|
||||
/**
|
||||
* Preceed a time period.
|
||||
*
|
||||
* @param {string} [value] - A string representing your value.
|
||||
*/
|
||||
every(value?: string): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Preceed a time period.
|
||||
*
|
||||
* @param {number} start - A number representing your start value.
|
||||
* @param {number} end - A number representing your end value.
|
||||
*/
|
||||
between(start: number, end: number): IRecurrenceBuilder;
|
||||
/**
|
||||
* Preceed a time period.
|
||||
*
|
||||
* @param {string} start - A string representing your start value.
|
||||
* @param {string} end - A string representing your end value.
|
||||
*/
|
||||
between(start: string, end: string): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* After a time period.
|
||||
*
|
||||
* @param {number} value - A number representing your value.
|
||||
*/
|
||||
after(value: number): IRecurrenceBuilder;
|
||||
/**
|
||||
* After a time period.
|
||||
*
|
||||
* @param {string} value - A string representing your value.
|
||||
*/
|
||||
after(value: string): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* After a time period.
|
||||
*
|
||||
* @param {number} value - A number representing your value.
|
||||
*/
|
||||
before(value: number): IRecurrenceBuilder;
|
||||
/**
|
||||
* After a time period.
|
||||
*
|
||||
* @param {string} value - A string representing your value.
|
||||
*/
|
||||
before(value: string): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* After a time period.
|
||||
*
|
||||
* @param {number} value - A number representing your value.
|
||||
*/
|
||||
startingOn(value: number): IRecurrenceBuilder;
|
||||
/**
|
||||
* After a time period.
|
||||
*
|
||||
* @param {string} value - A string representing your value.
|
||||
*/
|
||||
startingOn(value: string): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Equivalent to .on(min)
|
||||
*/
|
||||
first(): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Equivalent to .on(max)
|
||||
*/
|
||||
last(): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Equivalent to .on(1,7).dayOfWeek()
|
||||
*/
|
||||
onWeekend(): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Equivalent to .on(2,3,4,5,6).dayOfWeek()
|
||||
*/
|
||||
onWeekday(): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Add a new schedule value to schedules, composite schedule.
|
||||
*/
|
||||
and(): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Add exceptions.
|
||||
*/
|
||||
except(): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Custom Timeperiod Recurrences.
|
||||
* Using a key as defined by the custom period in any extension to Later.IStatic.
|
||||
*/
|
||||
customPeriod(key: string): IRecurrenceBuilder;
|
||||
|
||||
/**
|
||||
* Customise Recurrences.
|
||||
* Using a key as defined by the custom modifier in any extension to Later.IModifierStatic.
|
||||
*/
|
||||
customModifier(key: string, values: number): IRecurrenceBuilder;
|
||||
}
|
||||
|
||||
export interface IDateProvider {
|
||||
|
||||
/**
|
||||
* Set later to use UTC time.
|
||||
*/
|
||||
UTC(): void;
|
||||
|
||||
/**
|
||||
* Set later to use local time.
|
||||
*/
|
||||
localTime(): void;
|
||||
|
||||
/**
|
||||
* Builds and returns a new Date using the specified values. Date
|
||||
* returned is either using Local time or UTC based on isLocal.
|
||||
*
|
||||
* @param {number} [Y]: Four digit year
|
||||
* @param {number} [M]: Month between 1 and 12, defaults to 1
|
||||
* @param {number} [D]: Date between 1 and 31, defaults to 1
|
||||
* @param {number} [h]: Hour between 0 and 23, defaults to 0
|
||||
* @param {number} [m]: Minute between 0 and 59, defaults to 0
|
||||
* @param {number} [s]: Second between 0 and 59, defaults to 0
|
||||
*/
|
||||
next(Y?: number, M?: number, D?: number, h?: number, m?: number, s?: number): Date;
|
||||
|
||||
/**
|
||||
* Builds and returns a new Date using the specified values. Date
|
||||
* returned is either using Local time or UTC based on isLocal.
|
||||
*
|
||||
* @param {number} [Y]: Four digit year
|
||||
* @param {number} [M]: Month between 0 and 11, defaults to 11
|
||||
* @param {number} [D]: Date between 1 and 31, defaults to last day of month
|
||||
* @param {number} [h]: Hour between 0 and 23, defaults to 23
|
||||
* @param {number} [m]: Minute between 0 and 59, defaults to 59
|
||||
* @param {number} [s]: Second between 0 and 59, defaults to 59
|
||||
*/
|
||||
prev(Y?: number, M?: number, D?: number, h?: number, m?: number, s?: number): Date;
|
||||
|
||||
/**
|
||||
* Determines if a value will cause a particular constraint to rollover to the
|
||||
* next largest time period. Used primarily when a constraint has a
|
||||
* variable extent.
|
||||
*
|
||||
* @param {Date} d: Date
|
||||
* @param {number} val: Value
|
||||
* @param {IModifier} constraint: A modifier
|
||||
* @param {ITimePeriod} period: A time period
|
||||
*/
|
||||
nextRollover(d: Date, val: number, constraint: IModifier, period: ITimePeriod): Date;
|
||||
|
||||
/**
|
||||
* Determines if a value will cause a particular constraint to rollover to the
|
||||
* previous largest time period. Used primarily when a constraint has a
|
||||
* variable extent.
|
||||
*
|
||||
* @param {Date} d: Date
|
||||
* @param {number} val: Value
|
||||
* @param {IModifier} constraint: A modifier
|
||||
* @param {ITimePeriod} period: A time period
|
||||
*/
|
||||
prevRollover(d: Date, val: number, constraint: IModifier, period: ITimePeriod): Date;
|
||||
}
|
||||
|
||||
export interface ITimePeriod {
|
||||
|
||||
/**
|
||||
* The name of the time period information provider.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The rough number of seconds that are covered when moving from one instance of this time period to the next instance.
|
||||
*/
|
||||
range: number;
|
||||
|
||||
/**
|
||||
* The value of this time period for the date specified.
|
||||
*
|
||||
* @param {Date} date - The given date.
|
||||
*/
|
||||
val(date: Date): number;
|
||||
|
||||
/**
|
||||
* True if the specified value is valid for the specified date, false otherwise.
|
||||
*
|
||||
* @param {Date} date - The given date.
|
||||
* @param {any} value - The value to test for the date.
|
||||
*/
|
||||
isValid(date: Date, value: any): boolean;
|
||||
|
||||
/**
|
||||
* The minimum and maximum valid values for the time period for the specified date.
|
||||
* If the minimum value is not 0, 0 can be specified in schedules to indicate the maximum value.
|
||||
* This makes working with non - constant extents(like days in a month) easier.
|
||||
*
|
||||
* @param {Date} [date] - The given date.
|
||||
*/
|
||||
extent(date?: Date): number[];
|
||||
|
||||
/**
|
||||
* The first second in which the value is the same as the value of the specified date.
|
||||
* For example, the start of an hour would be the hour with 0 minutes and 0 seconds.
|
||||
*
|
||||
* @param {Date} date - The given date.
|
||||
*/
|
||||
start(date: Date): Date;
|
||||
|
||||
/**
|
||||
* The last second in which the value is the same as the value of the specified date.
|
||||
* For example, the end of an hour would be the hour with 59 minutes and 59 seconds.
|
||||
*
|
||||
* @param {Date} date - The given date.
|
||||
*/
|
||||
end(date: Date): Date;
|
||||
|
||||
/**
|
||||
* Returns the next date where the value is the value specified.
|
||||
* Sets the value to 1 if value specified is greater than the max allowed value.
|
||||
*
|
||||
* @param {Date} date - The given date.
|
||||
* @param {any} value - The value to test for the date.
|
||||
*/
|
||||
next(date: Date, value: any): Date;
|
||||
|
||||
/**
|
||||
* Returns the previous date where the value is the value specified.
|
||||
* Sets the value to the max allowed value if the value specified is greater than the max allowed value.
|
||||
*
|
||||
* @param {Date} date - The given date.
|
||||
* @param {any} value - The value to test for the date.
|
||||
*/
|
||||
prev(date: Date, value: any): Date;
|
||||
}
|
||||
|
||||
export interface IModifier extends ITimePeriod {
|
||||
/**
|
||||
* Creates a new modified constraint.
|
||||
*
|
||||
* @param {ITimePeriod} constraint: The constraint to be modified
|
||||
* @param {number} value: The starting value of the after constraint
|
||||
*/
|
||||
(constraint: ITimePeriod, value: number): ITimePeriod;
|
||||
}
|
||||
|
||||
export interface IModifierStatic {
|
||||
|
||||
/**
|
||||
* After Modifier
|
||||
*/
|
||||
after: IModifier;
|
||||
|
||||
/**
|
||||
* Before Modifier
|
||||
*/
|
||||
before: IModifier;
|
||||
}
|
||||
|
||||
export interface IStatic {
|
||||
|
||||
/**
|
||||
* Schedule
|
||||
* Generates instances from schedule data.
|
||||
*/
|
||||
schedule(input: any): ISchedule;
|
||||
|
||||
/**
|
||||
* Parse
|
||||
* For generating schedule data.
|
||||
*/
|
||||
parse: IParseStatic;
|
||||
|
||||
/** Date Provider
|
||||
*/
|
||||
date: IDateProvider;
|
||||
|
||||
/**
|
||||
* Set timeout on window using given recurrence next.
|
||||
*
|
||||
* @param {function} callback - A callback called after first instance of recurrence pattern.
|
||||
* @param {Later.IReccurence} - A recurrence instance.
|
||||
*/
|
||||
setTimeout(callback: () => void, time: IScheduleData): ITimer;
|
||||
/**
|
||||
* Set interval on window using given recurrence
|
||||
*
|
||||
* @param {function} callback - A callback called after each instance of recurrence pattern.
|
||||
* @param {Later.IReccurence} - A recurrence instance.
|
||||
*/
|
||||
setInterval(callback: () => void, time: IScheduleData): ITimer;
|
||||
|
||||
/**
|
||||
* time period information provider.
|
||||
*/
|
||||
time: ITimePeriod;
|
||||
/**
|
||||
* Second time period information provider.
|
||||
*/
|
||||
second: ITimePeriod;
|
||||
/**
|
||||
* Minute time period information provider.
|
||||
*/
|
||||
minute: ITimePeriod;
|
||||
/**
|
||||
* Hour time period information provider.
|
||||
*/
|
||||
hour: ITimePeriod;
|
||||
/**
|
||||
* Day time period information provider.
|
||||
*/
|
||||
day: ITimePeriod;
|
||||
/**
|
||||
* Day of week time period information provider.
|
||||
*/
|
||||
dayOfWeek: ITimePeriod;
|
||||
/**
|
||||
* Day of week in month time period information provider.
|
||||
*/
|
||||
dayOfWeekCount: ITimePeriod;
|
||||
/**
|
||||
* Day in year time period information provider.
|
||||
*/
|
||||
dayOfYear: ITimePeriod;
|
||||
/**
|
||||
* Week of mobth time period information provider.
|
||||
*/
|
||||
weekOfMonth: ITimePeriod;
|
||||
/**
|
||||
* Week of yearfrom ISO 8601 time period information provider.
|
||||
*/
|
||||
weekOfYear: ITimePeriod;
|
||||
/**
|
||||
* Month time period information provider.
|
||||
*/
|
||||
month: ITimePeriod;
|
||||
/**
|
||||
* Year time period information provider.
|
||||
*/
|
||||
year: ITimePeriod;
|
||||
|
||||
/**
|
||||
* Later Modifiers:
|
||||
*
|
||||
* This type can be easily extended to include any custom IModifiers that you desire.
|
||||
* These can then be used to create schedules of your own custom type.
|
||||
*
|
||||
* interface IGandalfsLaterModifier extends Later.IModifierStatic {
|
||||
* duringTheThirdAge: IModifier
|
||||
* }
|
||||
*
|
||||
* Be sure to use this interface when dealing with Later.modifier
|
||||
*/
|
||||
modifier: IModifierStatic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Later Module:
|
||||
*
|
||||
* Easily define complex schedules then quickly calculate future or previous schedule occurrences.
|
||||
*
|
||||
* This type can be easily extended to include any custom ITimePeriods that you desire.
|
||||
* These can then be used to create schedules of your own custom type.
|
||||
*
|
||||
* interface IGandalfsLater extends Later.IStatic {
|
||||
* agesOfMiddleEarth: ITimePeriod
|
||||
* }
|
||||
*
|
||||
* Be sure to use this interface when dealing with Later.
|
||||
*/
|
||||
declare var later: Later.IStatic;
|
||||
Reference in New Issue
Block a user