00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_DATE_H 00013 #define ZYPP_DATE_H 00014 00015 #include <ctime> 00016 #include <iosfwd> 00017 #include <string> 00018 00020 namespace zypp 00021 { 00022 00024 // 00025 // CLASS NAME : Date 00026 // 00029 class Date 00030 { 00031 friend std::ostream & operator<<( std::ostream & str, const Date & obj ); 00032 00033 public: 00034 00035 typedef time_t ValueType; 00036 00038 Date() 00039 : _date( 0 ) 00040 {} 00042 Date( ValueType date_r ) 00043 : _date( date_r ) 00044 {} 00046 Date( const std::string & seconds_r ); 00047 00049 static Date now() 00050 { return ::time( 0 ); } 00051 00052 public: 00054 operator ValueType() const 00055 { return _date; } 00056 00061 Date & operator+=( const time_t rhs ) { _date += rhs; return *this; } 00062 Date & operator-=( const time_t rhs ) { _date -= rhs; return *this; } 00063 Date & operator*=( const time_t rhs ) { _date *= rhs; return *this; } 00064 Date & operator/=( const time_t rhs ) { _date /= rhs; return *this; } 00065 00066 Date & operator++(/*prefix*/) { _date += 1; return *this; } 00067 Date & operator--(/*prefix*/) { _date -= 1; return *this; } 00068 00069 Date operator++(int/*postfix*/) { return _date++; } 00070 Date operator--(int/*postfix*/) { return _date--; } 00072 00073 public: 00080 std::string form( const std::string & format_r ) const; 00081 00085 std::string asString() const 00086 { return form( "%c" ); } 00087 00091 std::string asSeconds() const 00092 { return form( "%s" ); } 00093 00094 private: 00099 ValueType _date; 00100 }; 00102 00104 inline std::ostream & operator<<( std::ostream & str, const Date & obj ) 00105 { return str << obj.asString(); } 00106 00108 } // namespace zypp 00110 #endif // ZYPP_DATE_H
1.5.3