fipa_acl  1.4
date_time.cpp
Go to the documentation of this file.
1 #include "date_time.h"
2 #include <base-logging/Logging.hpp>
3 
4 namespace fipa {
5 namespace acl {
6 
7 const std::string DateTime::defaultFormat = "%Y-%m-%dT%H:%M:%S";
8 
9 std::string DateTime::toString() const
10 {
11  char buffer[512];
12  // %Z missing so far
13  strftime(buffer,512,defaultFormat.c_str(), &dateTime);
14 
15  std::string formattedOutput;
16  if(relative != '\0')
17  {
18  formattedOutput += relative;
19  }
20  formattedOutput += std::string(buffer);
21  if(timezone != '\0')
22  {
23  formattedOutput += timezone;
24  }
25  return formattedOutput;
26 }
27 
28 base::Time DateTime::toTime() const
29 {
30  // Tell make to check whether daylight saving is in effect
31  // http://pubs.opengroup.org/onlinepubs/007904975/functions/strptime.html
32  Time timeTmp = dateTime;
33  timeTmp.tm_isdst = -1;
34  time_t time = mktime(dynamic_cast<std::tm*>(&timeTmp));
35  return base::Time::fromMilliseconds(time*static_cast<uint64_t>(base::Time::Milliseconds) + timeTmp.tm_msec);
36 }
37 
38 }
39 }
std::string toString() const
Definition: date_time.cpp:9
base::Time toTime() const
Definition: date_time.cpp:28
static const std::string defaultFormat
Definition: date_time.h:25