Main MRPT website > C++ reference for MRPT 1.5.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 <mrpt/base/link_pragmas.h>
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 
19 namespace 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  */
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  */
35  struct TTimeParts
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  /** Returns the current time, as a `double` (fractional version of time_t) instead of a `TTimeStamp`.
103  * \sa now(), timestampTotime_t() */
104  inline double now_double() {
106  }
107 
108  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
109 
110  /** Transform a time interval (in seconds) into TTimeStamp (e.g. which can be added to an existing valid timestamp)
111  * \sa timeDifference
112  */
114 
115  /** Returns a formated string with the given time difference (passed as the number of seconds), as a string [H]H:MM:SS.MILISECS
116  * \sa unitsFormat
117  */
118  std::string BASE_IMPEXP formatTimeInterval( const double timeSeconds );
119 
120  /** Convert a timestamp into this textual form (UTC time): YEAR/MONTH/DAY,HH:MM:SS.MMM
121  * \sa dateTimeLocalToString
122  */
124 
125  /** Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM
126  * \sa dateTimeToString
127  */
129 
130  /** Convert a timestamp into this textual form: YEAR/MONTH/DAY
131  */
133 
134  /** Returns the number of seconds ellapsed from midnight in the given timestamp
135  */
137 
138  /** Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM
139  */
141 
142  /** Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM
143  */
144  std::string BASE_IMPEXP timeLocalToString(const mrpt::system::TTimeStamp t, unsigned int secondFractionDigits=6);
145 
146  /** This function implements time interval formatting: Given a time in seconds, it will return a string describing the interval with the most appropriate unit.
147  * E.g.: 1.23 year, 3.50 days, 9.3 hours, 5.3 minutes, 3.34 sec, 178.1 ms, 87.1 us.
148  * \sa unitsFormat
149  */
150  std::string BASE_IMPEXP intervalFormat(const double seconds);
151 
152  /** @} */
153 
154  } // End of namespace
155 
156 } // End of namespace
157 
158 #endif
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:30
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...
Definition: datetime.cpp:101
GLdouble GLdouble t
Definition: glext.h:3610
unsigned __int16 uint16_t
Definition: rptypes.h:46
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime()
Returns the current (UTC) system time.
Definition: datetime.cpp:71
double now_double()
Returns the current time, as a double (fractional version of time_t) instead of a TTimeStamp...
Definition: datetime.h:104
mrpt::system::TTimeStamp BASE_IMPEXP 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:43
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:70
double BASE_IMPEXP extractDayTimeFromTimestamp(const mrpt::system::TTimeStamp t)
Returns the number of seconds ellapsed from midnight in the given timestamp.
Definition: datetime.cpp:299
std::string BASE_IMPEXP timeToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM.
Definition: datetime.cpp:347
std::string BASE_IMPEXP formatTimeInterval(const double timeSeconds)
Returns a formated string with the given time difference (passed as the number of seconds)...
Definition: datetime.cpp:227
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
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentLocalTime()
Returns the current (local) time.
Definition: datetime.cpp:173
unsigned char uint8_t
Definition: rptypes.h:43
int daylight_saving
Day of week (1:Sunday, 7:Saturday)
Definition: datetime.h:44
std::string BASE_IMPEXP dateToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form: YEAR/MONTH/DAY.
Definition: datetime.cpp:369
The parts of a date/time (it&#39;s like the standard &#39;tm&#39; but with fractions of seconds).
Definition: datetime.h:35
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...
Definition: datetime.cpp:391
uint8_t day
Month (1-12)
Definition: datetime.h:39
GLsizei const GLchar ** string
Definition: glext.h:3919
double second
Minute (0-59)
Definition: datetime.h:42
mrpt::system::TTimeStamp BASE_IMPEXP 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:52
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
uint8_t minute
Hour (0-23)
Definition: datetime.h:41
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.
Definition: datetime.cpp:247
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.
Definition: datetime.cpp:321
uint8_t month
The year.
Definition: datetime.h:38
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) ...
Definition: datetime.cpp:197
uint8_t hour
Day (1-31)
Definition: datetime.h:40
mrpt::system::TTimeStamp BASE_IMPEXP secondsToTimestamp(const double nSeconds)
Transform a time interval (in seconds) into TTimeStamp (e.g.
Definition: datetime.cpp:219
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...
Definition: datetime.cpp:205
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.MMM.
Definition: datetime.cpp:274
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...
Definition: datetime.cpp:48
GLfloat GLfloat p
Definition: glext.h:5587
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...
Definition: datetime.cpp:53



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020