-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdate.cpp
67 lines (64 loc) · 1.37 KB
/
date.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
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
#include<string>
#include "date.h"
#include<iostream>
#include<vector>
#include<cstring>
date::date(std::string s)
{
unsigned yeart = 0,montht = 0,dayt = 0;
unsigned temp, temp2, temp3;
std::string::size_type si,sitemp;
static std::vector<std::string> Vmonth{"jan","feb","mar","apr","may","jun","jul","aug","sept","oct","nov","dec"};
static std::string num("1234567890");
for(char &c : s)
c = tolower(c);
for(std::string::size_type i = 0; i < Vmonth.size(); ++i)
{
if(s.find(Vmonth[i]) != std::string::npos)
montht = i+1;
}
if((si = s.find_first_of(num)) != std::string::npos)
{
s = s.substr(si);
temp = stoi(s, &si);
s = s.substr(si);
if(temp > 31)
yeart = temp;
else if(montht == 0)
montht = temp;
else
dayt = temp;
if((si = s.find_first_of(num)) != std::string::npos)
{
s = s.substr(si);
temp = stoi(s, &si);
s = s.substr(si);
if(temp > 31)
yeart = temp;
else if(montht == 0)
montht = temp;
else
dayt = temp;
if((si = s.find_first_of(num)) != std::string::npos)
{
s = s.substr(si);
temp = stoi(s, &si);
s = s.substr(si);
if(temp > 31)
yeart = temp;
else if(montht == 0)
montht = temp;
else
dayt = temp;
}
}
}
year = yeart;
month =montht;
day = dayt;
}
std::ostream & date::show(std::ostream &os) const
{
os << year << " " << month << " " << day;
return os;
}