Date.h

Go to the documentation of this file.
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     {}
00045     //Date( const std::string & seconds_r ) : _date( fromSECONDS (seconds_r) ) {}
00046 
00048     static Date now()
00049     { return ::time( 0 ); }
00050 
00051   public:
00053     operator ValueType() const
00054     { return _date; }
00055 
00060     Date & operator+=( const time_t rhs ) { _date += rhs; return *this; }
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 
00065     Date & operator++(/*prefix*/) { _date += 1; return *this; }
00066     Date & operator--(/*prefix*/) { _date -= 1; return *this; }
00067 
00068     Date operator++(int/*postfix*/) { return _date++; }
00069     Date operator--(int/*postfix*/) { return _date--; }
00071 
00072   public:
00079     std::string form( const std::string & format_r ) const;
00080 
00084     std::string asString() const
00085     { return form( "%c" ); }
00086 
00090     std::string asSeconds() const
00091     { return form( "%s" ); }
00092 
00093   private:
00098     ValueType _date;
00099   };
00101 
00103   inline std::ostream & operator<<( std::ostream & str, const Date & obj )
00104   { return str << obj.asString(); }
00105 
00107 } // namespace zypp
00109 #endif // ZYPP_DATE_H

Generated on Tue Nov 28 16:49:29 2006 for zypp by  doxygen 1.5.0