Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Date.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013   File:       Date.h
00014 
00015   Author:     Michael Andres <ma@suse.de>
00016   Maintainer: Michael Andres <ma@suse.de>
00017 
00018   Purpose: Store and operate on date (time_t).
00019 
00020 /-*/
00021 #ifndef _Date_h_
00022 #define _Date_h_
00023 
00024 #include <ctime>
00025 #include <iosfwd>
00026 #include <string>
00027 
00029 //
00030 //      CLASS NAME : Date
00031 //
00035 class Date {
00036 
00037   private:
00038 
00043     time_t _date;
00044 
00045   public:
00046 
00047     // static constructors and conversion
00048 
00052     static time_t now() { return time( 0 ); }
00053 
00061     static std::string form( const std::string & format, time_t tval_r );
00062 
00067     static time_t fromSECONDS( const std::string & str_r );
00068 
00073     static std::string toSECONDS( time_t tval_r );
00074 
00075   public:
00076 
00080     Date( time_t date_r = 0 ) : _date( date_r ) {}
00081     Date( const std::string & seconds_r ) : _date( fromSECONDS (seconds_r) ) {}
00082 
00086     operator time_t() const { return _date; }
00087 
00088     Date & operator+=( const time_t rhs ) { _date += rhs; return *this; }
00089     Date & operator-=( const time_t rhs ) { _date -= rhs; return *this; }
00090     Date & operator*=( const time_t rhs ) { _date *= rhs; return *this; }
00091     Date & operator/=( const time_t rhs ) { _date /= rhs; return *this; }
00092 
00093     Date & operator++(/*prefix*/) { _date += 1; return *this; }
00094     Date & operator--(/*prefix*/) { _date -= 1; return *this; }
00095 
00096     Date operator++(int/*postfix*/) { return _date++; }
00097     Date operator--(int/*postfix*/) { return _date--; }
00098 
00102     std::string form( const std::string & format ) const { return form( format, _date ); }
00103 
00108     std::string asString() const;
00109 
00113     friend std::ostream & operator<<( std::ostream & str, const Date & obj );
00114 };
00115 
00117 
00118 #endif // _Date_h_

Generated on Thu Feb 23 23:56:10 2006 for liby2util by doxygen 1.3.6