From b515a2468eddd427bf0cb8fbd0efb711c3c10c4a Mon Sep 17 00:00:00 2001 From: Saeid Date: Sat, 18 Jul 2020 19:21:06 +0430 Subject: [PATCH] cron --- .../Global/utils/common/ProcessTreeArray.js | 12 ++-- resources/js/Global/utils/date/cron.js | 55 +++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 resources/js/Global/utils/date/cron.js diff --git a/resources/js/Global/utils/common/ProcessTreeArray.js b/resources/js/Global/utils/common/ProcessTreeArray.js index 6ff0134..74f09f1 100644 --- a/resources/js/Global/utils/common/ProcessTreeArray.js +++ b/resources/js/Global/utils/common/ProcessTreeArray.js @@ -48,7 +48,7 @@ const convertTreeToList = data => { }; const convertListToTree = list => { - + function recursiveFunctionToTree( list, parent_id = null ) { let object = []; for (const item of list) { @@ -72,7 +72,7 @@ const addIndexTreeToList = list => { function recursiveFunctionIndexToTree( list, parent_id = null ) { var indexTree = 1; for (const item of list) { - if (item.parent_id == parent_id) { + if (item.parent_id === parent_id) { item['indexTree'] = indexTree; indexTree++; recursiveFunctionIndexToTree(list, item.id); @@ -80,7 +80,7 @@ const addIndexTreeToList = list => { } return list; } - + return recursiveFunctionIndexToTree(list); }; const listSearchSelect = Options => { @@ -124,7 +124,7 @@ const listSearchSelect = Options => { } } if (headers.length) { - let uniqueHeaders = [...new Set(headers)]; + let uniqueHeaders = [...new Set(headers)]; var newList =[]; for (const iterator of uniqueHeaders) { newList.push({ header: iterator }); @@ -195,7 +195,7 @@ const updateTreeArray = (treeArray, update, id, listArray = null) => { let array = treeArray; for (const key in hierarchy) { if (hierarchy.hasOwnProperty(key)) { - if (key == 0) { + if (key == 0) { if (hierarchy.length - 1 == key) { update["children"] = array[hierarchy[key]]["children"]; array[hierarchy[key]] = update; @@ -268,7 +268,7 @@ const insertTreeArray = ( // }); // } // return Array.isArray(array) ? recursiveFunction(array) : maxCount; - + // }; export { diff --git a/resources/js/Global/utils/date/cron.js b/resources/js/Global/utils/date/cron.js new file mode 100644 index 0000000..d17ad1b --- /dev/null +++ b/resources/js/Global/utils/date/cron.js @@ -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() { + + } + + + +}