PandA-2024.02
utility.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2015-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
41 #include "utility.hpp"
42 
43 #include <chrono>
44 #include <iomanip>
45 #include <sstream>
46 
47 TimeStamp::TimeStamp() : timestamp("1970-01-01T00:00:00")
48 {
49 }
50 
51 TimeStamp::TimeStamp(const std::string& _timestamp) : timestamp(_timestamp)
52 {
53 }
54 
56 {
57  auto now = std::chrono::system_clock::now();
58  auto in_time_t = std::chrono::system_clock::to_time_t(now);
59 #if !defined(__clang__) && __GNUC__ < 5
60  char buffer[32];
61  strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S", std::localtime(&in_time_t));
62  return std::string(buffer);
63 #else
64  std::stringstream ss;
65  ss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%dT%H:%M:%S");
66  return ss.str();
67 #endif
68 }
69 
70 std::ostream& operator<<(std::ostream& os, const TimeStamp& t)
71 {
72  os << t.timestamp;
73  return os;
74 }
75 
76 bool operator<=(const TimeStamp& timestamp1, const TimeStamp& timestamp2)
77 {
78  return timestamp1.timestamp <= timestamp2.timestamp;
79 }
TimeStamp()
Empty constructor: timestamp is set to 01-01-1970 00.00.
Definition: utility.cpp:47
std::string timestamp
Definition: utility.hpp:282
friend std::ostream & operator<<(std::ostream &os, const TimeStamp &timestamp)
Friend definition of the << operator.
Definition: utility.cpp:70
static std::string GetCurrentTimeStamp()
Return a timestamp of the current time.
Definition: utility.cpp:55
This file collects some utility functions and macros.
friend bool operator<=(const TimeStamp &timestamp1, const TimeStamp &timestamp2)
Definition: utility.cpp:76
The type used for timestamp.
Definition: utility.hpp:280

Generated on Mon Feb 12 2024 13:02:56 for PandA-2024.02 by doxygen 1.8.13