1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
23 ///////////////////////////////////////////////////////////////////
27 /** Store and operate on date (time_t).
31 friend std::ostream & operator<<( std::ostream & str, const Date & obj );
35 typedef time_t ValueType;
37 /** Default ctor: 0 */
41 /** Ctor taking time_t value. */
42 Date( ValueType date_r )
45 //Date( const std::string & seconds_r ) : _date( fromSECONDS (seconds_r) ) {}
47 /** Return the current time. */
49 { return ::time( 0 ); }
52 /** Conversion to time_t. */
53 operator ValueType() const
56 /** \name Arithmetic operations.
57 * \c + \c - \c * \c / are provided via conversion to time_t.
60 Date & operator+=( const time_t rhs ) { _date += rhs; return *this; }
61 Date & operator-=( const time_t rhs ) { _date -= rhs; return *this; }
62 Date & operator*=( const time_t rhs ) { _date *= rhs; return *this; }
63 Date & operator/=( const time_t rhs ) { _date /= rhs; return *this; }
65 Date & operator++(/*prefix*/) { _date += 1; return *this; }
66 Date & operator--(/*prefix*/) { _date -= 1; return *this; }
68 Date operator++(int/*postfix*/) { return _date++; }
69 Date operator--(int/*postfix*/) { return _date--; }
73 /** Return string representation according to format.
74 * \see 'man strftime' (which is used internaly) for valid
75 * conversion specifiers in format.
77 * \return An empty string on illegal format.
79 std::string form( const std::string & format_r ) const;
81 /** Default string representation of Date.
82 * The preferred date and time representation for the current locale.
84 std::string asString() const
85 { return form( "%c" ); }
87 /** Convert to string representation of calendar time in
88 * numeric form (like "1029255142").
90 std::string asSeconds() const
91 { return form( "%s" ); }
95 * The number of seconds elapsed since 00:00:00 on January 1, 1970,
96 * Coordinated Universal Time (UTC).
100 ///////////////////////////////////////////////////////////////////
102 /** \relates Date Stream output */
103 inline std::ostream & operator<<( std::ostream & str, const Date & obj )
104 { return str << obj.asString(); }
106 /////////////////////////////////////////////////////////////////
108 ///////////////////////////////////////////////////////////////////
109 #endif // ZYPP_DATE_H