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-2018, 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 #pragma once
10 
11 #include <cstdint>
12 #include <string>
13 
14 /** Represents an invalid timestamp, where applicable. */
15 #define INVALID_TIMESTAMP (0)
16 
17 namespace mrpt
18 {
19 namespace system
20 {
21 /** @defgroup time_date Time and date functions (in #include
22  * <mrpt/system/datetime.h>)
23  * \ingroup mrpt_system_grp
24  * @{ */
25 
26 /** A system independent time type, it holds the the number of 100-nanosecond
27  * intervals since January 1, 1601 (UTC).
28  * \sa system::getCurrentTime, system::timeDifference, INVALID_TIMESTAMP,
29  * TTimeParts
30  */
32 
33 /** The parts of a date/time (it's like the standard 'tm' but with fractions of
34  * seconds).
35  * \sa TTimeStamp, timestampToParts, buildTimestampFromParts
36  */
37 struct TTimeParts
38 {
39  uint16_t year; /** The year */
40  uint8_t month; /** Month (1-12) */
41  uint8_t day; /** Day (1-31) */
42  uint8_t hour; /** Hour (0-23) */
43  uint8_t minute; /** Minute (0-59) */
44  double second; /** Seconds (0.0000-59.9999) */
45  uint8_t day_of_week; /** Day of week (1:Sunday, 7:Saturday) */
47 };
48 
49 /** Builds a timestamp from the parts (Parts are in UTC)
50  * \sa timestampToParts
51  */
54 
55 /** Builds a timestamp from the parts (Parts are in local time)
56  * \sa timestampToParts, buildTimestampFromParts
57  */
60 
61 /** Gets the individual parts of a date/time (days, hours, minutes, seconds) -
62  * UTC time or local time
63  * \sa buildTimestampFromParts
64  */
65 void timestampToParts(TTimeStamp t, TTimeParts& p, bool localTime = false);
66 
67 /** Returns the current (UTC) system time.
68  * \sa now,getCurrentLocalTime
69  */
71 
72 /** A shortcut for system::getCurrentTime
73  * \sa getCurrentTime, getCurrentLocalTime
74  */
76 /** Returns the current (local) time.
77  * \sa now,getCurrentTime
78  */
80 
81 /** Transform from standard "time_t" (actually a double number, it can contain
82  * fractions of seconds) to TTimeStamp.
83  * \sa timestampTotime_t
84  */
86 
87 /** Transform from standard "time_t" to TTimeStamp.
88  * \sa timestampTotime_t
89  */
91 
92 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it
93  * can contain fractions of seconds).
94  * \sa time_tToTimestamp, secondsToTimestamp
95  */
97 
98 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it
99  * can contain fractions of seconds).
100  * This function is just an (inline) alias of timestampTotime_t(), with a more
101  * significant name.
102  * \sa time_tToTimestamp, secondsToTimestamp
103  */
105 {
106  return timestampTotime_t(t);
107 }
108 
109 /** Returns the time difference from t1 to t2 (positive if t2 is posterior to
110  * t1), in seconds \sa secondsToTimestamp */
111 double timeDifference(
112  const mrpt::system::TTimeStamp t_first,
113  const mrpt::system::TTimeStamp t_later);
114 
115 /** Returns the current time, as a `double` (fractional version of time_t)
116 * instead of a `TTimeStamp`.
117 * \sa now(), timestampTotime_t() */
118 inline double now_double()
119 {
121 }
122 
123 /** Shifts a timestamp the given amount of seconds (>0: forwards in time, <0:
124  * backwards) \sa secondsToTimestamp */
126  const mrpt::system::TTimeStamp tim, const double num_seconds);
127 
128 /** Transform a time interval (in seconds) into TTimeStamp (e.g. which can be
129  * added to an existing valid timestamp)
130  * \sa timeDifference
131  */
132 mrpt::system::TTimeStamp secondsToTimestamp(const double nSeconds);
133 
134 /** Returns a formated string with the given time difference (passed as the
135  * number of seconds), as a string [H]H:MM:SS.MILISECS
136  * \sa unitsFormat
137  */
138 std::string formatTimeInterval(const double timeSeconds);
139 
140 /** Convert a timestamp into this textual form (UTC time):
141  * YEAR/MONTH/DAY,HH:MM:SS.MMM
142  * \sa dateTimeLocalToString
143  */
145 
146 /** Convert a timestamp into this textual form (in local time):
147  * YEAR/MONTH/DAY,HH:MM:SS.MMM
148  * \sa dateTimeToString
149  */
151 
152 /** Convert a timestamp into this textual form: YEAR/MONTH/DAY
153  */
155 
156 /** Returns the number of seconds ellapsed from midnight in the given timestamp
157  */
159 
160 /** Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM
161  */
163 
164 /** Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM
165  */
167  const mrpt::system::TTimeStamp t, unsigned int secondFractionDigits = 6);
168 
169 /** This function implements time interval formatting: Given a time in seconds,
170  * it will return a string describing the interval with the most appropriate
171  * unit.
172  * E.g.: 1.23 year, 3.50 days, 9.3 hours, 5.3 minutes, 3.34 sec, 178.1 ms, 87.1
173  * us.
174  * \sa unitsFormat
175  */
176 std::string intervalFormat(const double seconds);
177 
178 /** @} */
179 
180 } // End of namespace
181 } // End of namespace
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:104
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:74
double now_double()
Returns the current time, as a double (fractional version of time_t) instead of a TTimeStamp...
Definition: datetime.h:118
mrpt::system::TTimeStamp buildTimestampFromParts(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in UTC)
Definition: datetime.cpp:128
uint8_t day_of_week
Seconds (0.0000-59.9999)
Definition: datetime.h:45
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:75
double extractDayTimeFromTimestamp(const mrpt::system::TTimeStamp t)
Returns the number of seconds ellapsed from midnight in the given timestamp.
Definition: datetime.cpp:291
std::string timeToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM.
Definition: datetime.cpp:338
std::string formatTimeInterval(const double timeSeconds)
Returns a formated string with the given time difference (passed as the number of seconds)...
Definition: datetime.cpp:232
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:104
mrpt::system::TTimeStamp getCurrentLocalTime()
Returns the current (local) time.
Definition: datetime.cpp:174
unsigned char uint8_t
Definition: rptypes.h:41
int daylight_saving
Day of week (1:Sunday, 7:Saturday)
Definition: datetime.h:46
std::string dateToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form: YEAR/MONTH/DAY.
Definition: datetime.cpp:357
The parts of a date/time (it&#39;s like the standard &#39;tm&#39; but with fractions of seconds).
Definition: datetime.h:37
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:376
uint8_t day
Month (1-12)
Definition: datetime.h:41
GLsizei const GLchar ** string
Definition: glext.h:4101
double second
Minute (0-59)
Definition: datetime.h:44
mrpt::system::TTimeStamp buildTimestampFromPartsLocalTime(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in local time)
Definition: datetime.cpp:151
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:43
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:248
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:315
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:31
uint8_t month
The year.
Definition: datetime.h:40
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:199
uint8_t hour
Day (1-31)
Definition: datetime.h:42
mrpt::system::TTimeStamp secondsToTimestamp(const double nSeconds)
Transform a time interval (in seconds) into TTimeStamp (e.g.
Definition: datetime.cpp:224
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:209
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:270
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:50
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:56



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019