-
Notifications
You must be signed in to change notification settings - Fork 0
/
finecal.cpp
42 lines (37 loc) · 1019 Bytes
/
finecal.cpp
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
#include "finecal.h"
#include <QDate>
FineCal::FineCal()
{
}
/*
* Format of the date should be:
* yyyy-MM-dd
*/
double FineCal::calculate(QString due, QString date_in)
{
QDate d1 = QDate::fromString(due, "yyyy-MM-dd");
if(date_in.isNull() || date_in.isEmpty() || date_in == "NULL"){
QDate today = QDate::currentDate();
if(today.daysTo(d1) < 0){ // need pay fine
return d1.daysTo(today) * 0.25;
}else{
return 0;
}
}
QDate d2 = QDate::fromString(date_in, "yyyy-MM-dd");
if(d2.daysTo(d1) < 0){ // need pay fine
return (d1.daysTo(d2) * 0.25);
}else{ // no fine
return 0;
}
}
double FineCal::timeTravel(QString due, QString date_in)
{
QDate d1 = QDate::fromString(due, "yyyy-MM-dd");
QDate d2 = QDate::fromString(date_in, "yyyy-MM-dd");
if(d2.daysTo(d1) < 0){ // need pay fine, travel to future
return (d1.daysTo(d2) * 0.25);
}else{ // no fine, travel to past
return 0;
}
}