Main MRPT website > C++ reference for MRPT 1.9.9
datetime.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef MRPT_SYSTEM_DATETIME_H
10 #define MRPT_SYSTEM_DATETIME_H
11 
12 #include <cstdint>
13 #include <string>
14 
15 /** Represents an invalid timestamp, where applicable. */
16 #define INVALID_TIMESTAMP (0)
17 
18 namespace mrpt
19 {
20 namespace system
21 {
22 /** @defgroup time_date Time and date functions (in #include
23  * <mrpt/system/datetime.h>)
24  * \ingroup mrpt_base_grp
25  * @{ */
26 
27 /** A system independent time type, it holds the the number of 100-nanosecond
28  * intervals since January 1, 1601 (UTC).
29  * \sa system::getCurrentTime, system::timeDifference, INVALID_TIMESTAMP,
30  * TTimeParts
31  */
33 
34 /** The parts of a date/time (it's like the standard 'tm' but with fractions of
35  * seconds).
36  * \sa TTimeStamp, timestampToParts, buildTimestampFromParts
37  */
38 struct TTimeParts
39 {
40  uint16_t year; /** The year */
41  uint8_t month; /** Month (1-12) */
42  uint8_t day; /** Day (1-31) */
43  uint8_t hour; /** Hour (0-23) */
44  uint8_t minute; /** Minute (0-59) */
45  double second; /** Seconds (0.0000-59.9999) */
46  uint8_t day_of_week; /** Day of week (1:Sunday, 7:Saturday) */
48 };
49 
50 /** Builds a timestamp from the parts (Parts are in UTC)
51  * \sa timestampToParts
52  */
55 
56 /** Builds a timestamp from the parts (Parts are in local time)
57  * \sa timestampToParts, buildTimestampFromParts
58  */
61 
62 /** Gets the individual parts of a date/time (days, hours, minutes, seconds) -
63  * UTC time or local time
64  * \sa buildTimestampFromParts
65  */
66 void timestampToParts(TTimeStamp t, TTimeParts& p, bool localTime = false);
67 
68 /** Returns the current (UTC) system time.
69  * \sa now,getCurrentLocalTime
70  */
72 
73 /** A shortcut for system::getCurrentTime
74  * \sa getCurrentTime, getCurrentLocalTime
75  */
77 /** Returns the current (local) time.
78  * \sa now,getCurrentTime
79  */
81 
82 /** Transform from standard "time_t" (actually a double number, it can contain
83  * fractions of seconds) to TTimeStamp.
84  * \sa timestampTotime_t
85  */
87 
88 /** Transform from standard "time_t" to TTimeStamp.
89  * \sa timestampTotime_t
90  */
92 
93 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it
94  * can contain fractions of seconds).
95  * \sa time_tToTimestamp, secondsToTimestamp
96  */
98 
99 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it
100  * can contain fractions of seconds).
101  * This function is just an (inline) alias of timestampTotime_t(), with a more
102  * significant name.
103  * \sa time_tToTimestamp, secondsToTimestamp
104  */
106 {
107  return timestampTotime_t(t);
108 }
109 
110 /** Returns the time difference from t1 to t2 (positive if t2 is posterior to
111  * t1), in seconds \sa secondsToTimestamp */
112 double timeDifference(
113  const mrpt::system::TTimeStamp t_first,
114  const mrpt::system::TTimeStamp t_later);
115 
116 /** Returns the current time, as a `double` (fractional version of time_t)
117 * instead of a `TTimeStamp`.
118 * \sa now(), timestampTotime_t() */
119 inline double now_double()
120 {
122 }
123 
124 /** Shifts a timestamp the given amount of seconds (>0: forwards in time, <0:
125  * backwards) \sa secondsToTimestamp */
127  const mrpt::system::TTimeStamp tim, const double num_seconds);
128 
129 /** Transform a time interval (in seconds) into TTimeStamp (e.g. which can be
130  * added to an existing valid timestamp)
131  * \sa timeDifference
132  */
133 mrpt::system::TTimeStamp secondsToTimestamp(const double nSeconds);
134 
135 /** Returns a formated string with the given time difference (passed as the
136  * number of seconds), as a string [H]H:MM:SS.MILISECS
137  * \sa unitsFormat
138  */
139 std::string formatTimeInterval(const double timeSeconds);
140 
141 /** Convert a timestamp into this textual form (UTC time):
142  * YEAR/MONTH/DAY,HH:MM:SS.MMM
143  * \sa dateTimeLocalToString
144  */
146 
147 /** Convert a timestamp into this textual form (in local time):
148  * YEAR/MONTH/DAY,HH:MM:SS.MMM
149  * \sa dateTimeToString
150  */
152 
153 /** Convert a timestamp into this textual form: YEAR/MONTH/DAY
154  */
156 
157 /** Returns the number of seconds ellapsed from midnight in the given timestamp
158  */
160 
161 /** Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM
162  */
164 
165 /** Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM
166  */
168  const mrpt::system::TTimeStamp t, unsigned int secondFractionDigits = 6);
169 
170 /** This function implements time interval formatting: Given a time in seconds,
171  * it will return a string describing the interval with the most appropriate
172  * unit.
173  * E.g.: 1.23 year, 3.50 days, 9.3 hours, 5.3 minutes, 3.34 sec, 178.1 ms, 87.1
174  * us.
175  * \sa unitsFormat
176  */
177 std::string intervalFormat(const double seconds);
178 
179 /** @} */
180 
181 } // End of namespace
182 } // End of namespace
183 
184 #endif
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:32
void timestampToParts(TTimeStamp t, TTimeParts &p, bool localTime=false)
Gets the individual parts of a date/time (days, hours, minutes, seconds) - UTC time or local time...
Definition: datetime.cpp:103
GLdouble GLdouble t
Definition: glext.h:3689
unsigned __int16 uint16_t
Definition: rptypes.h:44
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
Definition: datetime.cpp:73
double now_double()
Returns the current time, as a double (fractional version of time_t) instead of a TTimeStamp...
Definition: datetime.h:119
mrpt::system::TTimeStamp buildTimestampFromParts(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in UTC)
Definition: datetime.cpp:127
uint8_t day_of_week
Seconds (0.0000-59.9999)
Definition: datetime.h:46
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:76
double extractDayTimeFromTimestamp(const mrpt::system::TTimeStamp t)
Returns the number of seconds ellapsed from midnight in the given timestamp.
Definition: datetime.cpp:290
std::string timeToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM.
Definition: datetime.cpp:337
std::string formatTimeInterval(const double timeSeconds)
Returns a formated string with the given time difference (passed as the number of seconds)...
Definition: datetime.cpp:231
double timestampToDouble(const mrpt::system::TTimeStamp t)
Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of...
Definition: datetime.h:105
mrpt::system::TTimeStamp getCurrentLocalTime()
Returns the current (local) time.
Definition: datetime.cpp:173
unsigned char uint8_t
Definition: rptypes.h:41
int daylight_saving
Day of week (1:Sunday, 7:Saturday)
Definition: datetime.h:47
std::string dateToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form: YEAR/MONTH/DAY.
Definition: datetime.cpp:356
The parts of a date/time (it&#39;s like the standard &#39;tm&#39; but with fractions of seconds).
Definition: datetime.h:38
std::string intervalFormat(const double seconds)
This function implements time interval formatting: Given a time in seconds, it will return a string d...
Definition: datetime.cpp:375
uint8_t day
Month (1-12)
Definition: datetime.h:42
GLsizei const GLchar ** string
Definition: glext.h:4101
double second
Minute (0-59)
Definition: datetime.h:45
mrpt::system::TTimeStamp buildTimestampFromPartsLocalTime(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in local time)
Definition: datetime.cpp:150
unsigned __int64 uint64_t
Definition: rptypes.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
uint8_t minute
Hour (0-23)
Definition: datetime.h:44
std::string dateTimeToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (UTC time): YEAR/MONTH/DAY,HH:MM:SS.MMM.
Definition: datetime.cpp:247
std::string timeLocalToString(const mrpt::system::TTimeStamp t, unsigned int secondFractionDigits=6)
Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM.
Definition: datetime.cpp:314
uint8_t month
The year.
Definition: datetime.h:41
mrpt::system::TTimeStamp timestampAdd(const mrpt::system::TTimeStamp tim, const double num_seconds)
Shifts a timestamp the given amount of seconds (>0: forwards in time, <0: backwards) ...
Definition: datetime.cpp:198
uint8_t hour
Day (1-31)
Definition: datetime.h:43
mrpt::system::TTimeStamp secondsToTimestamp(const double nSeconds)
Transform a time interval (in seconds) into TTimeStamp (e.g.
Definition: datetime.cpp:223
double timeDifference(const mrpt::system::TTimeStamp t_first, const mrpt::system::TTimeStamp t_later)
Returns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds...
Definition: datetime.cpp:208
std::string dateTimeLocalToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM.
Definition: datetime.cpp:269
mrpt::system::TTimeStamp time_tToTimestamp(const double t)
Transform from standard "time_t" (actually a double number, it can contain fractions of seconds) to T...
Definition: datetime.cpp:49
GLfloat GLfloat p
Definition: glext.h:6305
double timestampTotime_t(const mrpt::system::TTimeStamp t)
Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of...
Definition: datetime.cpp:55



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019