Stride Reference Manual  1.0
TimeToString.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * any later version.
7  * The software is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License
12  * along with the software. If not, see <http://www.gnu.org/licenses/>.
13  *
14  * Copyright 2017, Willem L, Kuylen E, Stijven S & Broeckhove J
15  */
16 
22 #include <string>
23 #include <sstream>
24 #include <iostream>
25 #include <iomanip>
26 #include <cmath>
27 
28 namespace stride {
29 namespace util {
30 
34 struct TimeToString {
36  static std::string toColonString(std::chrono::seconds d) {
37  using namespace std;
38  using namespace std::chrono;
39 
40  ostringstream oss;
41  hours hh = duration_cast<hours>(d);
42  minutes mm = duration_cast<minutes>(d % hours(1));
43  seconds ss = duration_cast<seconds>(d % minutes(1));
44 
45  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count()
46  << ":" << setw(2) << ss.count();
47  return oss.str();
48  }
49 
51  static std::string toColonString(std::chrono::milliseconds d) {
52  using namespace std;
53  using namespace std::chrono;
54 
55  ostringstream oss;
56  hours hh = duration_cast<hours>(d);
57  minutes mm = duration_cast<minutes>(d % hours(1));
58  seconds ss = duration_cast<seconds>(d % minutes(1));
59  milliseconds milli = duration_cast<milliseconds>(d % seconds(1));
60 
61  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count()
62  << ":" << setw(2) << ss.count() << ":" << setw(3) << milli.count();
63  return oss.str();
64  }
65 
67  static std::string toColonString(std::chrono::microseconds d) {
68  using namespace std;
69  using namespace std::chrono;
70 
71  ostringstream oss;
72  hours hh = duration_cast<hours>(d);
73  minutes mm = duration_cast<minutes>(d % hours(1));
74  seconds ss = duration_cast<seconds>(d % minutes(1));
75  milliseconds milli = duration_cast<milliseconds>(d % seconds(1));
76  microseconds micro = duration_cast<microseconds>(d % milliseconds(1));
77 
78  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count()
79  << ":" << setw(2) << ss.count() << ":" << setw(3) << milli.count() << ":" << setw(3) << micro.count();
80  return oss.str();
81  }
82 
84  static std::string toColonString(std::chrono::nanoseconds d) {
85  using namespace std;
86  using namespace std::chrono;
87 
88  ostringstream oss;
89  hours hh = duration_cast<hours>(d);
90  minutes mm = duration_cast<minutes>(d % hours(1));
91  seconds ss = duration_cast<seconds>(d % minutes(1));
92  milliseconds milli = duration_cast<milliseconds>(d % seconds(1));
93  microseconds micro = duration_cast<microseconds>(d % milliseconds(1));
94  nanoseconds nano = duration_cast<nanoseconds>(d % microseconds(1));
95 
96  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count()
97  << ":" << setw(2) << ss.count() << ":" << setw(3) << milli.count() << ":" << setw(3) << micro.count()
98  << ":" << setw(3) << nano.count() << endl;
99  return oss.str();
100  }
101 };
102 
103 }
104 }
105 
Utilities to tag clocks and to reformat number of ticks to a string.
Definition: TimeToString.h:34
static std::string toColonString(std::chrono::nanoseconds d)
Produce string in hh:mm:ss:ms:mus:ns format.
Definition: TimeToString.h:84
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
static std::string toColonString(std::chrono::microseconds d)
Produce string in hh:mm:ss:ms:mus format.
Definition: TimeToString.h:67
STL namespace.
static std::string toColonString(std::chrono::seconds d)
Produce string in hh:mm:ss format.
Definition: TimeToString.h:36
static std::string toColonString(std::chrono::milliseconds d)
Produce string in hh:mm:ss:mus format.
Definition: TimeToString.h:51