Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
13#include <mrpt/utils/mrpt_stdint.h> // compiler-independent version of "stdint.h"
14#include <string>
15
16/** Represents an invalid timestamp, where applicable. */
17#define INVALID_TIMESTAMP (0)
18
19namespace mrpt
20{
21 namespace system
22 {
23 /** @defgroup time_date Time and date functions (in #include <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 intervals since January 1, 1601 (UTC).
28 * \sa system::getCurrentTime, system::timeDifference, INVALID_TIMESTAMP, TTimeParts
29 */
30 typedef uint64_t TTimeStamp;
31
32 /** The parts of a date/time (it's like the standard 'tm' but with fractions of seconds).
33 * \sa TTimeStamp, timestampToParts, buildTimestampFromParts
34 */
36 {
37 uint16_t year; /** The year */
38 uint8_t month; /** Month (1-12) */
39 uint8_t day; /** Day (1-31) */
40 uint8_t hour; /** Hour (0-23) */
41 uint8_t minute; /** Minute (0-59) */
42 double second; /** Seconds (0.0000-59.9999) */
43 uint8_t day_of_week; /** Day of week (1:Sunday, 7:Saturday) */
45 };
46
47 /** Builds a timestamp from the parts (Parts are in UTC)
48 * \sa timestampToParts
49 */
51
52 /** Builds a timestamp from the parts (Parts are in local time)
53 * \sa timestampToParts, buildTimestampFromParts
54 */
56
57 /** Gets the individual parts of a date/time (days, hours, minutes, seconds) - UTC time or local time
58 * \sa buildTimestampFromParts
59 */
60 void BASE_IMPEXP timestampToParts( TTimeStamp t, TTimeParts &p, bool localTime = false );
61
62 /** Returns the current (UTC) system time.
63 * \sa now,getCurrentLocalTime
64 */
66
67 /** A shortcut for system::getCurrentTime
68 * \sa getCurrentTime, getCurrentLocalTime
69 */
71 return getCurrentTime();
72 }
73
74 /** Returns the current (local) time.
75 * \sa now,getCurrentTime
76 */
78
79 /** Transform from standard "time_t" (actually a double number, it can contain fractions of seconds) to TTimeStamp.
80 * \sa timestampTotime_t
81 */
83
84 /** Transform from standard "time_t" to TTimeStamp.
85 * \sa timestampTotime_t
86 */
88
89 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of seconds).
90 * \sa time_tToTimestamp, secondsToTimestamp
91 */
93
94 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of seconds).
95 * This function is just an (inline) alias of timestampTotime_t(), with a more significant name.
96 * \sa time_tToTimestamp, secondsToTimestamp
97 */
98 inline double timestampToDouble( const mrpt::system::TTimeStamp &t ) { return timestampTotime_t(t); }
99
100 double BASE_IMPEXP 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 \sa secondsToTimestamp
101
102 mrpt::system::TTimeStamp BASE_IMPEXP timestampAdd( const mrpt::system::TTimeStamp &tim, const double num_seconds); //!< Shifts a timestamp the given amount of seconds (>0: forwards in time, <0: backwards) \sa secondsToTimestamp
103
104 /** Transform a time interval (in seconds) into TTimeStamp (e.g. which can be added to an existing valid timestamp)
105 * \sa timeDifference
106 */
108
109 /** Returns a formated string with the given time difference (passed as the number of seconds), as a string [H]H:MM:SS.MILISECS
110 * \sa unitsFormat
111 */
112 std::string BASE_IMPEXP formatTimeInterval( const double &timeSeconds );
113
114 /** Convert a timestamp into this textual form (UTC time): YEAR/MONTH/DAY,HH:MM:SS.MMM
115 * \sa dateTimeLocalToString
116 */
118
119 /** Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM
120 * \sa dateTimeToString
121 */
123
124 /** Convert a timestamp into this textual form: YEAR/MONTH/DAY
125 */
127
128 /** Returns the number of seconds ellapsed from midnight in the given timestamp
129 */
131
132 /** Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM
133 */
135
136 /** Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM
137 */
138 std::string BASE_IMPEXP timeLocalToString(const mrpt::system::TTimeStamp &t, unsigned int secondFractionDigits=6);
139
140 /** This function implements time interval formatting: Given a time in seconds, it will return a string describing the interval with the most appropriate unit.
141 * E.g.: 1.23 year, 3.50 days, 9.3 hours, 5.3 minutes, 3.34 sec, 178.1 ms, 87.1 us.
142 * \sa unitsFormat
143 */
144 std::string BASE_IMPEXP intervalFormat(const double seconds);
145
146 /** @} */
147
148 } // End of namespace
149
150} // End of namespace
151
152#endif
EIGEN_STRONG_INLINE const AdjointReturnType t() const
Transpose.
double BASE_IMPEXP 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.
double BASE_IMPEXP timestampTotime_t(const mrpt::system::TTimeStamp &t)
Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of...
std::string BASE_IMPEXP formatTimeInterval(const double &timeSeconds)
Returns a formated string with the given time difference (passed as the number of seconds),...
std::string BASE_IMPEXP intervalFormat(const double seconds)
This function implements time interval formatting: Given a time in seconds, it will return a string d...
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentLocalTime()
Returns the current (local) time.
std::string BASE_IMPEXP timeLocalToString(const mrpt::system::TTimeStamp &t, unsigned int secondFractionDigits=6)
Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM.
std::string BASE_IMPEXP dateTimeLocalToString(const mrpt::system::TTimeStamp &t)
Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS....
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:30
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:98
std::string BASE_IMPEXP dateToString(const mrpt::system::TTimeStamp &t)
Convert a timestamp into this textual form: YEAR/MONTH/DAY.
std::string BASE_IMPEXP dateTimeToString(const mrpt::system::TTimeStamp &t)
Convert a timestamp into this textual form (UTC time): YEAR/MONTH/DAY,HH:MM:SS.MMM.
mrpt::system::TTimeStamp BASE_IMPEXP time_tToTimestamp(const double &t)
Transform from standard "time_t" (actually a double number, it can contain fractions of seconds) to T...
mrpt::system::TTimeStamp BASE_IMPEXP secondsToTimestamp(const double &nSeconds)
Transform a time interval (in seconds) into TTimeStamp (e.g.
double BASE_IMPEXP extractDayTimeFromTimestamp(const mrpt::system::TTimeStamp &t)
Returns the number of seconds ellapsed from midnight in the given timestamp.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:70
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime()
Returns the current (UTC) system time.
std::string BASE_IMPEXP timeToString(const mrpt::system::TTimeStamp &t)
Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM.
mrpt::system::TTimeStamp BASE_IMPEXP buildTimestampFromPartsLocalTime(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in local time)
mrpt::system::TTimeStamp BASE_IMPEXP buildTimestampFromParts(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in UTC)
void BASE_IMPEXP 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.
mrpt::system::TTimeStamp BASE_IMPEXP timestampAdd(const mrpt::system::TTimeStamp &tim, const double num_seconds)
Shifts a timestamp the given amount of seconds (>0: forwards in time, <0: backwards)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
The parts of a date/time (it's like the standard 'tm' but with fractions of seconds).
Definition: datetime.h:36
uint8_t day_of_week
Seconds (0.0000-59.9999)
Definition: datetime.h:43
uint8_t hour
Day (1-31)
Definition: datetime.h:40
int daylight_saving
Day of week (1:Sunday, 7:Saturday)
Definition: datetime.h:44
uint8_t day
Month (1-12)
Definition: datetime.h:39
uint8_t minute
Hour (0-23)
Definition: datetime.h:41
uint8_t month
The year.
Definition: datetime.h:38
double second
Minute (0-59)
Definition: datetime.h:42



Page generated by Doxygen 1.9.2 for MRPT 1.4.0 SVN: at Mon Sep 20 00:47:55 UTC 2021