forked from Yamini2391/VaccinationRegistartionSystem
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dateutil.h
117 lines (111 loc) · 1.86 KB
/
dateutil.h
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Members -
* 2328 - Shruti Datar
* 2329 - Samruddhi Deode
* 2332 - Nisha Deshmukh
* 2336 - Yamini Dongaonkar
*/
/*
* dateutil.h
*
* Created on: 11-May-2021
*
* Includes some helpers for handling dates.
* Used in Admin class in admin.h, in the run_process function
*/
#ifndef DATEUTIL_H_
#define DATEUTIL_H_
#include <string>
using namespace std;
bool isLeap(int yr)
{
/*
* Returns true if the year is a leap year
*/
return yr % 4 == 0 && yr % 100 != 0;
}
string date_string(int day, int month, int year)
{
/*
* Returns the string form of a date
*/
return to_string(day) + "/" + to_string(month) + "/" + to_string(year);
}
string get_next_date(int day, int month, int year)
{
/*
* Returns the next date in string form, given input
* today's day, month and year
*/
int new_day, new_month, new_year;
enum months
{
Jan = 1,
Feb,
Mar,
Apr,
May,
Jun,
Jul,
Aug,
Sep,
Oct,
Nov,
Dec
};
bool ordinary = false;
new_year = year;
switch (day)
{
case 28:
if (month == Feb && !isLeap(year)) // 28th Feb, non leap year
{
new_month = Mar;
new_day = 1;
}
else
ordinary = true;
break;
case 29:
if (month == Feb) // 29th Feb, leap year
{
new_month = Mar;
new_day = 1;
}
else
ordinary = true;
break;
case 30:
if (month == Apr || month == Jun || month == Sep || month == Nov) // 30 day months
{
new_month = month + 1;
new_day = 1;
}
else
ordinary = true;
break;
case 31:
if (month == Dec) // 31st Dec
{
new_month = Jan;
new_year++;
new_day = 1;
}
else // Other 31 day months
{
new_month = month + 1;
new_day = 1;
}
break;
default:
ordinary = true;
break;
}
if (ordinary) // Month does not change; day is incremented by 1
{
new_month = month;
new_day = day + 1;
}
return date_string(new_day, new_month, new_year);
}
#endif /* DATEUTIL_H_ */