Leosac  0.7.0
OpenSourceAccessControl
MyTime.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "tools/MyTime.hpp"
22 #include "tools/log.hpp"
23 #include <chrono>
24 #include <iomanip>
25 #include <sstream>
26 
27 namespace Leosac
28 {
29 bool my_puttime(std::string &out, const std::tm *tt, const char *fmt)
30 { /*
31  std::stringstream ss;
32  ss << std::put_time(tt, fmt);
33  out = ss.str();
34  return true;*/
35 
36  out.resize(150);
37  if (size_t sz = strftime(&out[0], 150, fmt, tt))
38  {
39  out.resize(sz);
40  return true;
41  }
42  return false;
43 }
44 
45 std::string to_local_rfc2822(const std::chrono::system_clock::time_point &tp)
46 {
47  std::string out;
48  std::time_t tt = std::chrono::system_clock::to_time_t(tp);
49 
50  bool ret = my_puttime(out, std::localtime(&tt), "%a, %d %b %Y %T %z");
51  ASSERT_LOG(ret, "Failed to convert date to RFC2822");
52 
53  return out;
54 }
55 }
This is the header file for a generated source file, GitSHA1.cpp.
std::string to_local_rfc2822(const std::chrono::system_clock::time_point &tp)
Convert a timepoint to an RFC2822 (SMTP) date.
Definition: MyTime.cpp:45
bool my_puttime(std::string &out, const std::tm *tt, const char *fmt)
Definition: MyTime.cpp:29
Exception class for LEOSAC Project related errors.
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:190