1 /*
2 Copyright 2015 Carnegie Mellon University
3 
4 This material is based upon work funded and supported by Department of Homeland Security under Contract No. FA8721-05-C-0003 with Carnegie Mellon University for the operation of the Software Engineering Institute, a federally funded research and development center sponsored by the United States Department of Defense.
5 
6 Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of Department of Homeland Security or the United States Department of Defense.
7 
8 NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN “AS-IS” BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
9 
10 This material has been approved for public release and unlimited distribution.
11 
12 CERT® is a registered mark of Carnegie Mellon University.
13 */
14 #include "dates.h"
15 
NextDate(string date)16 string NextDate( string date )
17 {
18 	string time = " 00:00:01";
19 	string datetime = date+time;
20 	struct tm tm;
21 	time_t epoch;
22 	if ( strptime(datetime.c_str(), "%Y%m%d %H:%M:%S", &tm) != NULL ) {
23 		epoch = mktime(&tm);
24 	}
25 	else  {
26 		cout << "Can not parse:  " << date << "\n";
27 		exit(-1);
28 	}
29 
30 	epoch += 86401;
31 	struct tm *nextday;
32 	nextday  = localtime(&epoch);
33 	char buffer[16];
34 	strftime(buffer, 16, "%Y%m%d", nextday);
35 	string tmp = buffer;
36 	return tmp.substr(0, 8);
37 }
38 
getYear(string date)39 string getYear( string date)
40 {
41 	return date.substr(0,4);
42 }
43 
getMonth(string date)44 string getMonth( string date)
45 {
46 	return date.substr(4,2);
47 }
48