parent
200ffde1c5
commit
b515a2468e
@ -0,0 +1,55 @@
|
||||
export default class Cron {
|
||||
|
||||
constructor(options) {
|
||||
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() {
|
||||
if (this.date !== '' && this.time !== '') {
|
||||
let date = new Date(this.date + 'T'+ this.time);
|
||||
console.log(this.date, date, date.getMonth(), date.getDay());
|
||||
return {
|
||||
cron: `${date.getMinutes()} ${date.getHours()} ${date.getDate()} ${date.getMonth()} *`,
|
||||
year: date.getFullYear()
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
cronToDate() {
|
||||
let cronArray = this.cron.split(' ');
|
||||
const month = (parseInt(cronArray[3]) + 1) > 9 ? parseInt(cronArray[3]) + 1 : '0' + (parseInt(cronArray[3]) + 1).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}`;
|
||||
return {
|
||||
time,
|
||||
date
|
||||
}
|
||||
}
|
||||
|
||||
builder() {
|
||||
|
||||
}
|
||||
|
||||
parser() {
|
||||
|
||||
}
|
||||
|
||||
next(){
|
||||
|
||||
}
|
||||
|
||||
prev() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue