00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 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 /** @name Time and date functions 00041 @{ */ 00042 00043 /** A system independent time type, it holds the the number of 100-nanosecond intervals since January 1, 1601 (UTC). 00044 * \sa system::getCurrentTime, system::timeDifference, INVALID_TIMESTAMP, TTimeParts 00045 */ 00046 typedef uint64_t TTimeStamp; 00047 00048 /** The parts of a date/time (it's like the standard 'tm' but with fractions of seconds). 00049 * \sa TTimeStamp, timestampToParts, buildTimestampFromParts 00050 */ 00051 struct TTimeParts 00052 { 00053 uint16_t year; /** The year */ 00054 uint8_t month; /** Month (1-12) */ 00055 uint8_t day; /** Day (1-31) */ 00056 uint8_t hour; /** Hour (0-23) */ 00057 uint8_t minute; /** Minute (0-59) */ 00058 double second; /** Seconds (0.0000-59.9999) */ 00059 uint8_t day_of_week; /** Day of week (1:Sunday, 7:Saturday) */ 00060 int daylight_saving; 00061 }; 00062 00063 /** Builds a timestamp from the parts (Parts are in UTC) 00064 * \sa timestampToParts 00065 */ 00066 mrpt::system::TTimeStamp BASE_IMPEXP buildTimestampFromParts( const mrpt::system::TTimeParts &p ); 00067 00068 /** Builds a timestamp from the parts (Parts are in local time) 00069 * \sa timestampToParts, buildTimestampFromParts 00070 */ 00071 mrpt::system::TTimeStamp BASE_IMPEXP buildTimestampFromPartsLocalTime( const mrpt::system::TTimeParts &p ); 00072 00073 /** Gets the individual parts of a date/time (days, hours, minutes, seconds) - UTC time or local time 00074 * \sa buildTimestampFromParts 00075 */ 00076 void BASE_IMPEXP timestampToParts( TTimeStamp t, TTimeParts &p, bool localTime = false ); 00077 00078 /** Returns the current (UTC) system time. 00079 * \sa now,getCurrentLocalTime 00080 */ 00081 mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime( ); 00082 00083 /** A shortcut for system::getCurrentTime 00084 * \sa getCurrentTime, getCurrentLocalTime 00085 */ 00086 inline mrpt::system::TTimeStamp now() { 00087 return getCurrentTime(); 00088 } 00089 00090 /** Returns the current (local) time. 00091 * \sa now,getCurrentTime 00092 */ 00093 mrpt::system::TTimeStamp BASE_IMPEXP getCurrentLocalTime( ); 00094 00095 /** Transform from standard "time_t" (actually a double number, it can contain fractions of seconds) to TTimeStamp. 00096 * \sa timestampTotime_t 00097 */ 00098 mrpt::system::TTimeStamp BASE_IMPEXP time_tToTimestamp( const double &t ); 00099 00100 /** Transform from standard "time_t" to TTimeStamp. 00101 * \sa timestampTotime_t 00102 */ 00103 mrpt::system::TTimeStamp BASE_IMPEXP time_tToTimestamp( const time_t &t ); 00104 00105 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of seconds). 00106 * \sa time_tToTimestamp, secondsToTimestamp 00107 */ 00108 double BASE_IMPEXP timestampTotime_t( const mrpt::system::TTimeStamp &t ); 00109 00110 /** Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of seconds). 00111 * This function is just an (inline) alias of timestampTotime_t(), with a more significant name. 00112 * \sa time_tToTimestamp, secondsToTimestamp 00113 */ 00114 inline double timestampToDouble( const mrpt::system::TTimeStamp &t ) { return timestampTotime_t(t); } 00115 00116 /** Retuns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds. 00117 * \sa secondsToTimestamp 00118 */ 00119 double BASE_IMPEXP timeDifference( const mrpt::system::TTimeStamp &t_first, const mrpt::system::TTimeStamp &t_later ); 00120 00121 /** Transform a time interval (in seconds) into TTimeStamp (e.g. which can be added to an existing valid timestamp) 00122 * \sa timeDifference 00123 */ 00124 mrpt::system::TTimeStamp BASE_IMPEXP secondsToTimestamp( const double &nSeconds ); 00125 00126 /** Returns a formated string with the given time difference (passed as the number of seconds), as a string [H]H:MM:SS.MILISECS 00127 * \sa unitsFormat 00128 */ 00129 std::string BASE_IMPEXP formatTimeInterval( const double &timeSeconds ); 00130 00131 /** Convert a timestamp into this textual form (UTC time): YEAR/MONTH/DAY,HH:MM:SS.MMM 00132 * \sa dateTimeLocalToString 00133 */ 00134 std::string BASE_IMPEXP dateTimeToString(const mrpt::system::TTimeStamp &t); 00135 00136 /** Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM 00137 * \sa dateTimeToString 00138 */ 00139 std::string BASE_IMPEXP dateTimeLocalToString(const mrpt::system::TTimeStamp &t); 00140 00141 /** Convert a timestamp into this textual form: YEAR/MONTH/DAY 00142 */ 00143 std::string BASE_IMPEXP dateToString(const mrpt::system::TTimeStamp &t); 00144 00145 /** Returns the number of seconds ellapsed from midnight in the given timestamp 00146 */ 00147 double BASE_IMPEXP extractDayTimeFromTimestamp(const mrpt::system::TTimeStamp &t); 00148 00149 /** Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM 00150 */ 00151 std::string BASE_IMPEXP timeToString(const mrpt::system::TTimeStamp &t); 00152 00153 /** Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM 00154 */ 00155 std::string BASE_IMPEXP timeLocalToString(const mrpt::system::TTimeStamp &t, unsigned int secondFractionDigits=6); 00156 00157 /** This function implements time interval formatting: Given a time in seconds, it will return a string describing the interval with the most appropriate unit. 00158 * E.g.: 1.23 year, 3.50 days, 9.3 hours, 5.3 minutes, 3.34 sec, 178.1 ms, 87.1 us. 00159 * \sa unitsFormat 00160 */ 00161 std::string BASE_IMPEXP intervalFormat(const double seconds); 00162 00163 /** @} */ 00164 00165 } // End of namespace 00166 00167 } // End of namespace 00168 00169 #endif
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011 |