-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
92 lines (78 loc) · 1.96 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Check if date is possible
*
* Example:
* 30/02/2020 // not possible
* 20/02/2020 // is possible
*
*
* @param int day
* @param int month
* @param int year
* @return string
*/
function isPossibleDate(day, month, year) {
let date = new Date(year, month, 0);
let numberDay = date.getDate();
if (day > numberDay) {
day = day - numberDay;
month += 1;
}
if (month > 12) {
month = 1
year += 1
}
return day + "/" + month + "/" + year;
}
// Example:
//console.log(isPossibleDate((30+5), 12, 2020));
//output: 4/1/2021
module.exports = {
/**
* Generate of Date
*
* @param { int } day
* @param { int } month
* @param { int } year
* @param { int } looping
* @return { array }
*/
generateDate: function (day, month, year, looping) {
let arrDate = [];
for (i = looping; i > 0 && i <= looping; i -= 1) {
month++
if (month > 12) {
month = 1
year += 1
}
arrDate.push(isPossibleDate(day, month, year))
}
return arrDate
},
// Example:
//console.log(generateDate(30, 12, 2020, 2));
//output: Array [ "30/1/2021", "2/3/2021"]
/**
* Generate of parcel
*
* @param { array } arrDate
* @param { string } valueParcel
* @return { array }
*/
generateParcel: function (arrDate, valueParcel) {
let parcel = []
for (let i = 0; i < arrDate.length; i++) {
parcel.push({
index: i,
value: valueParcel,
date: arrDate[i],
status: 'Em aberto'
})
}
return parcel
},
// Example:
// let arrDate = generateDate(30, 12, 2020, 1)
// let parcel = generateParcel(arrDate, "20,59");
// output: Array [ Object { indice: 0, data: "20,59", data: "30/1/2021", status: "Em aberto" } ]
}