00001 #ifndef PSTIME_TIMEFORMAT_H 00002 #define PSTIME_TIMEFORMAT_H 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: TimeFormat.h 1844 2011-05-07 01:51:13Z salnikov $ 00007 // 00008 // Description: 00009 // Class TimeFormat. 00010 // 00011 //------------------------------------------------------------------------ 00012 00013 //----------------- 00014 // C/C++ Headers -- 00015 //----------------- 00016 #include <string> 00017 #include <iosfwd> 00018 00019 //---------------------- 00020 // Base Class Headers -- 00021 //---------------------- 00022 00023 //------------------------------- 00024 // Collaborating Class Headers -- 00025 //------------------------------- 00026 #include "PSTime/Time.h" 00027 00028 //------------------------------------ 00029 // Collaborating Class Declarations -- 00030 //------------------------------------ 00031 00032 // --------------------- 00033 // -- Class Interface -- 00034 // --------------------- 00035 00036 namespace PSTime { 00037 00038 /** 00039 * @brief Namespace with utility methods to deal with the presentation of the times/dates. 00040 * 00041 * This software was developed for the LUSI project. If you use all or 00042 * part of it, please give an appropriate acknowledgment. 00043 * 00044 * @version \$Id: TimeFormat.h 1844 2011-05-07 01:51:13Z salnikov $ 00045 * 00046 * @author Andrei Salnikov 00047 */ 00048 00049 namespace TimeFormat { 00050 00051 /** 00052 * @brief Parse the time string and return time. 00053 * 00054 * Accepts the time stamp in format: 00055 * @li <date>, or 00056 * @li <date> <time>[.<fraction-of-sec>][<zone>], or 00057 * @li <date>T<time>[.<fraction-of-sec>][<zone>] 00058 * 00059 * where 00060 * @li <date> should be in format YYYY-MM-DD, YYYYMMDD, YYYY-MM, YYYYMM, or YYYY, if 00061 * month or day is missing they are assumed to be 1; 00062 * @li <time> should be in format HH:MM:SS, HHMMSS, HH:MM, HHMM, HH, if minutes or 00063 * seconds are missing they are assumed to be 0; 00064 * @li <fraction-of-sec> may have up to 9 digits for nsec; if this field is missing, 00065 * it is assumed equal to 0, fraction require seconds to be specified; 00066 * @li <zone> should be Z for UTC or in format <sign + or ->HH[:MM] or <sign + or ->HHMM 00067 * if this field is missing time is assumed to be in local time zone. 00068 * 00069 * @throw TimeParseException 00070 */ 00071 Time parseTime( const std::string& timeStr ); 00072 00073 /** 00074 * @brief Convert time to string according to format. 00075 * 00076 * Following format codes are understood: 00077 * 00078 * @li @c %d The day of the month as a decimal number (range 01 to 31). 00079 * @li @c %.Nf Fractional seconds, will print dot followed by @c N digits. 00080 * @li @c %f Equivalent to %.9f 00081 * @li @c %F Equivalent to %Y-%m-%d (the ISO 8601 date format). 00082 * @li @c %H The hour as a decimal number using a 24-hour clock (range 00 to 23). 00083 * @li @c %m The month as a decimal number (range 01 to 12). 00084 * @li @c %M The minute as a decimal number (range 00 to 59). 00085 * @li @c %s The number of seconds since the Epoch, i.e., since 1970-01-01 00:00:00 UTC. 00086 * @li @c %S The second as a decimal number (range 00 to 60). 00087 * @li @c %T The time in 24-hour notation (%H:%M:%S). 00088 * @li @c %Y The year as a decimal number including the century. 00089 * @li @c %z 'Z' if time is printed in UTC zone, or offset from UTC to local time. 00090 * @li @c %% A literal percent character. 00091 * 00092 * Any unrecognized characters not in the above set are copied to output string intact. 00093 * 00094 * @param[in] time Time object 00095 * @param[in] afmt Format string 00096 * @param[in] zone Time zone specification 00097 */ 00098 std::string format ( const Time& time, const std::string& afmt, Time::Zone zone ); 00099 00100 /// Format to standard stream object instead of string, same parametes as for previous method. 00101 void format ( std::ostream& str, const Time& time, const std::string& afmt, Time::Zone zone ); 00102 00103 } // namespace TimeFormat 00104 00105 } // namespace PSTime 00106 00107 #endif // PSTIME_TIMEFORMAT_H