Main MRPT website > C++ reference
MRPT logo
datetime.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef  MRPT_SYSTEM_DATETIME_H
00029 #define  MRPT_SYSTEM_DATETIME_H
00030 
00031 #include <mrpt/utils/utils_defs.h>
00032 
00033 /** Represents an invalid timestamp, where applicable. */
00034 #define INVALID_TIMESTAMP (0)
00035 
00036 namespace mrpt
00037 {
00038         namespace system
00039         {
00040                 /** @defgroup time_date Time and date functions
00041                   * \ingroup mrpt_base_grp
00042                   * @{ */
00043 
00044                 /** A system independent time type, it holds the the number of 100-nanosecond intervals since January 1, 1601 (UTC).
00045                  * \sa system::getCurrentTime, system::timeDifference, INVALID_TIMESTAMP, TTimeParts
00046                  */
00047                 typedef uint64_t TTimeStamp;
00048 
00049                 /** The parts of a date/time (it's like the standard 'tm' but with fractions of seconds).
00050                  * \sa TTimeStamp, timestampToParts, buildTimestampFromParts
00051                  */
00052                 struct TTimeParts
00053                 {
00054                         uint16_t        year;   /** The year */
00055                         uint8_t         month;  /** Month (1-12) */
00056                         uint8_t         day;    /** Day (1-31) */
00057                         uint8_t         hour;   /** Hour (0-23) */
00058                         uint8_t         minute; /** Minute (0-59) */
00059                         double          second; /** Seconds (0.0000-59.9999) */
00060                         uint8_t         day_of_week; /** Day of week (1:Sunday, 7:Saturday) */
00061                         int                     daylight_saving;
00062                 };
00063 
00064                 /** Builds a timestamp from the parts (Parts are in UTC)
00065                   * \sa timestampToParts
00066                   */
00067                 mrpt::system::TTimeStamp BASE_IMPEXP buildTimestampFromParts( const mrpt::system::TTimeParts &p );
00068 
00069                 /** Builds a timestamp from the parts (Parts are in local time)
00070                   * \sa timestampToParts, buildTimestampFromParts
00071                   */
00072                 mrpt::system::TTimeStamp BASE_IMPEXP buildTimestampFromPartsLocalTime( const mrpt::system::TTimeParts &p );
00073 
00074                 /** Gets the individual parts of a date/time (days, hours, minutes, seconds) - UTC time or local time
00075                   * \sa buildTimestampFromParts
00076                   */
00077                 void BASE_IMPEXP timestampToParts( TTimeStamp t, TTimeParts &p, bool localTime = false );
00078 
00079                 /** Returns the current (UTC) system time.
00080                   * \sa now,getCurrentLocalTime
00081                   */
00082                 mrpt::system::TTimeStamp  BASE_IMPEXP getCurrentTime( );
00083 
00084                 /** A shortcut for system::getCurrentTime
00085                   * \sa getCurrentTime, getCurrentLocalTime
00086                  */
00087                 inline mrpt::system::TTimeStamp now() {
00088                         return getCurrentTime();
00089                 }
00090 
00091                 /** Returns the current (local) time.
00092                   * \sa now,getCurrentTime
00093                   */
00094                 mrpt::system::TTimeStamp  BASE_IMPEXP getCurrentLocalTime( );
00095 
00096                 /** Transform from standard "time_t" (actually a double number, it can contain fractions of seconds) to TTimeStamp.
00097                   * \sa timestampTotime_t
00098                   */
00099                 mrpt::system::TTimeStamp  BASE_IMPEXP time_tToTimestamp( const double &t );
00100 
00101                 /** Transform from standard "time_t" to TTimeStamp.
00102                   * \sa timestampTotime_t
00103                   */
00104                 mrpt::system::TTimeStamp  BASE_IMPEXP time_tToTimestamp( const time_t &t );
00105 
00106                 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of seconds).
00107                   * \sa time_tToTimestamp, secondsToTimestamp
00108                   */
00109                 double BASE_IMPEXP timestampTotime_t( const mrpt::system::TTimeStamp  &t );
00110 
00111                 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of seconds).
00112                   * This function is just an (inline) alias of timestampTotime_t(), with a more significant name.
00113                   * \sa time_tToTimestamp, secondsToTimestamp
00114                   */
00115                 inline double timestampToDouble( const mrpt::system::TTimeStamp  &t ) { return timestampTotime_t(t); }
00116 
00117                 /** Retuns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds.
00118                   * \sa secondsToTimestamp
00119                   */
00120                 double BASE_IMPEXP timeDifference( const mrpt::system::TTimeStamp &t_first, const mrpt::system::TTimeStamp &t_later );
00121 
00122                 /** Transform a time interval (in seconds) into TTimeStamp (e.g. which can be added to an existing valid timestamp)
00123                   * \sa timeDifference
00124                   */
00125                 mrpt::system::TTimeStamp BASE_IMPEXP secondsToTimestamp( const double &nSeconds );
00126 
00127                 /** Returns a formated string with the given time difference (passed as the number of seconds), as a string [H]H:MM:SS.MILISECS
00128                   * \sa unitsFormat
00129                   */
00130                 std::string BASE_IMPEXP formatTimeInterval( const double &timeSeconds );
00131 
00132                 /** Convert a timestamp into this textual form (UTC time): YEAR/MONTH/DAY,HH:MM:SS.MMM
00133                   * \sa dateTimeLocalToString
00134                   */
00135                 std::string  BASE_IMPEXP dateTimeToString(const mrpt::system::TTimeStamp &t);
00136 
00137                 /** Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM
00138                   * \sa dateTimeToString
00139                   */
00140                 std::string  BASE_IMPEXP dateTimeLocalToString(const mrpt::system::TTimeStamp &t);
00141 
00142                 /** Convert a timestamp into this textual form: YEAR/MONTH/DAY
00143                  */
00144                 std::string  BASE_IMPEXP dateToString(const mrpt::system::TTimeStamp &t);
00145 
00146                 /** Returns the number of seconds ellapsed from midnight in the given timestamp
00147                  */
00148                 double  BASE_IMPEXP extractDayTimeFromTimestamp(const mrpt::system::TTimeStamp &t);
00149 
00150                 /** Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM
00151                  */
00152                 std::string  BASE_IMPEXP timeToString(const mrpt::system::TTimeStamp &t);
00153 
00154                 /** Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM
00155                  */
00156                 std::string  BASE_IMPEXP timeLocalToString(const mrpt::system::TTimeStamp &t, unsigned int secondFractionDigits=6);
00157 
00158                 /** This function implements time interval formatting: Given a time in seconds, it will return a string describing the interval with the most appropriate unit.
00159                  * E.g.: 1.23 year, 3.50 days, 9.3 hours, 5.3 minutes, 3.34 sec, 178.1 ms,  87.1 us.
00160                  * \sa unitsFormat
00161                  */
00162                 std::string BASE_IMPEXP intervalFormat(const double seconds);
00163 
00164                 /** @} */
00165 
00166         } // End of namespace
00167 
00168 } // End of namespace
00169 
00170 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011