-
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathcookie_date.cpp
More file actions
74 lines (61 loc) · 2.1 KB
/
cookie_date.cpp
File metadata and controls
74 lines (61 loc) · 2.1 KB
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
/**
* File: cookie_date.cpp
* Author: Giuseppe Persico
*/
#include "cookie_date.h"
using std::out_of_range;
using std::ostringstream;
// Implementation of constructor with parameters.
curl::cookie_date::cookie_date(const unsigned int week_day, const unsigned int day,
const unsigned int month, const unsigned int year) NOEXCEPT {
this->set_week_day(week_day)->set_day(day)->set_month(month)->set_year(year);
}
// Implementation of set_week_day method.
curl::cookie_date *curl::cookie_date::set_week_day(const unsigned int weekDay) NOEXCEPT {
try {
this->week_day = details::weekdayNames.at(weekDay);
} catch (const out_of_range &) {
this->week_day = "Mon";
}
return this;
}
// Implementation of set_day method.
curl::cookie_date *curl::cookie_date::set_day(const unsigned int cookieDay) NOEXCEPT {
this->day = (cookieDay < 1 or cookieDay > 31) ? 1 : cookieDay;
return this;
}
// Implementation of set_month method.
curl::cookie_date *curl::cookie_date::set_month(const unsigned int cookieMonth) {
try {
this->month = details::monthsNames.at(cookieMonth);
} catch (const out_of_range &) {
this->month = "Jan";
}
return this;
}
// Implementation of set_year method.
curl::cookie_date *curl::cookie_date::set_year(const unsigned int cookieYear) NOEXCEPT {
this->year = (cookieYear < 1970 ) ? 1970 : cookieYear;
return this;
}
std::string curl::cookie_date::get_week_day() const NOEXCEPT {
return this->week_day;
}
// Implementation of get_day method.
unsigned int curl::cookie_date::get_day() const NOEXCEPT {
return this->day;
}
// Implementation of get_month method.
std::string curl::cookie_date::get_month() const NOEXCEPT {
return this->month;
}
// Implementation of get_year method.
unsigned int curl::cookie_date::get_year() const NOEXCEPT {
return this->year;
}
// Implementation of get_formatted method.
std::string curl::cookie_date::get_formatted() NOEXCEPT {
ostringstream stream;
stream<<this->week_day<<", "<<this->day<<"-"<<this->month<<"-"<<this->year;
return stream.str();
}