-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.js
53 lines (27 loc) · 1.17 KB
/
library.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
var input = "9 1 2016\n6 6 2015";
function libraryFine(string) {
var a = string.split("\n");
a[0] = a[0].split(' ');
a[1] = a[1].split(' ');
var returnedDate = new Date(parseInt(a[0][2]), parseInt(a[0][1]) - 1, parseInt(a[0][0]));
var dueDate = new Date(parseInt(a[1][2]), parseInt(a[1][1]) - 1, parseInt(a[1][0]));
var fine = 0;
if(returnedDate > dueDate) {
fine = calculateFine(dueDate, returnedDate);
}
console.log(fine);
}
function calculateFine(dueDate, returnedDate) {
var fine = 0;
console.log( dueDate.getDate() );
console.log( returnedDate.getDate() );
if(returnedDate.getFullYear() > dueDate.getFullYear()) {
fine = 10000;
} else if (returnedDate.getMonth() > dueDate.getMonth()) {
fine = (returnedDate.getMonth() - dueDate.getMonth()) * 500;
} else if (returnedDate.getDate() > dueDate.getDate()) {
fine = (returnedDate.getDate() - dueDate.getDate()) * 15;
}
return fine;
}
// new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);