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 00036 Date() 00037 : _date( 0 ) 00038 {} 00040 Date( time_t date_r ) 00041 : _date( date_r ) 00042 {} 00043 //Date( const std::string & seconds_r ) : _date( fromSECONDS (seconds_r) ) {} 00044 00046 static Date now() 00047 { return ::time( 0 ); } 00048 00049 public: 00051 operator time_t() const 00052 { return _date; } 00053 00058 Date & operator+=( const time_t rhs ) { _date += rhs; return *this; } 00059 Date & operator-=( const time_t rhs ) { _date -= rhs; return *this; } 00060 Date & operator*=( const time_t rhs ) { _date *= rhs; return *this; } 00061 Date & operator/=( const time_t rhs ) { _date /= rhs; return *this; } 00062 00063 Date & operator++(/*prefix*/) { _date += 1; return *this; } 00064 Date & operator--(/*prefix*/) { _date -= 1; return *this; } 00065 00066 Date operator++(int/*postfix*/) { return _date++; } 00067 Date operator--(int/*postfix*/) { return _date--; } 00069 00070 public: 00077 std::string form( const std::string & format_r ) const; 00078 00082 std::string asString() const 00083 { return form( "%c" ); } 00084 00088 std::string asSeconds() const 00089 { return form( "%s" ); } 00090 00091 private: 00096 time_t _date; 00097 }; 00099 00101 inline std::ostream & operator<<( std::ostream & str, const Date & obj ) 00102 { return str << obj.asString(); } 00103 00105 } // namespace zypp 00107 #endif // ZYPP_DATE_H