You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.6 KiB
65 lines
1.6 KiB
export default class Cron {
|
|
|
|
constructor(options) {
|
|
this.date_time = options['date_time'] ? options.date_time : '';
|
|
this.date = options['date'] ? options.date : '';
|
|
this.time = options['time'] ? options.time : '';
|
|
this.cron = options['cron'] ? options.cron : '';
|
|
this.year = options['year'] ? options.year : '';
|
|
}
|
|
|
|
dateToCron() {
|
|
let date;
|
|
if (this.date !== '' && this.time !== '') {
|
|
date = new Date(this.date + 'T' + this.time);
|
|
}
|
|
else if (this.date_time !== '') {
|
|
date = new Date(this.date_time);
|
|
|
|
}
|
|
if (date) {
|
|
return {
|
|
cron: `${date.getMinutes()} ${date.getHours()} ${date.getDate()} ${date.getMonth() + 1 } *`,
|
|
year: date.getFullYear()
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
cronToDate() {
|
|
let cronArray = this.cron.split(' ');
|
|
const month = (parseInt(cronArray[3])) > 9 ? parseInt(cronArray[3]) : '0' + (parseInt(cronArray[3])).toString();
|
|
const day = cronArray[2].length < 2 ? '0' + cronArray[2] : cronArray[2];
|
|
const hour = cronArray[1].length < 2 ? '0'+cronArray[1] : cronArray[1];
|
|
const minute = cronArray[0].length < 2 ? '0'+cronArray[0] : cronArray[0];
|
|
|
|
let time = `${hour}:${minute}`;
|
|
let date = `${this.year}-${month}-${day}`;
|
|
let date_time = `${this.year}-${month}-${day} ${hour}:${minute}`;
|
|
return {
|
|
time,
|
|
date,
|
|
date_time
|
|
}
|
|
}
|
|
|
|
builder() {
|
|
|
|
}
|
|
|
|
parser() {
|
|
|
|
}
|
|
|
|
next(){
|
|
|
|
}
|
|
|
|
prev() {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|