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 /** Ctor taking time_t value as string. */
46 Date( const std::string & seconds_r );
48 /** Return the current time. */
50 { return ::time( 0 ); }
53 /** Conversion to time_t. */
54 operator ValueType() const
57 /** \name Arithmetic operations.
58 * \c + \c - \c * \c / are provided via conversion to time_t.
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; }
64 Date & operator/=( const time_t rhs ) { _date /= rhs; return *this; }
66 Date & operator++(/*prefix*/) { _date += 1; return *this; }
67 Date & operator--(/*prefix*/) { _date -= 1; return *this; }
69 Date operator++(int/*postfix*/) { return _date++; }
70 Date operator--(int/*postfix*/) { return _date--; }
74 /** Return string representation according to format.
75 * \see 'man strftime' (which is used internaly) for valid
76 * conversion specifiers in format.
78 * \return An empty string on illegal format.
80 std::string form( const std::string & format_r ) const;
82 /** Default string representation of Date.
83 * The preferred date and time representation for the current locale.
85 std::string asString() const
86 { return form( "%c" ); }
88 /** Convert to string representation of calendar time in
89 * numeric form (like "1029255142").
91 std::string asSeconds() const
92 { return form( "%s" ); }
96 * The number of seconds elapsed since 00:00:00 on January 1, 1970,
97 * Coordinated Universal Time (UTC).
101 ///////////////////////////////////////////////////////////////////
103 /** \relates Date Stream output */
104 inline std::ostream & operator<<( std::ostream & str, const Date & obj )
105 { return str << obj.asString(); }
107 /////////////////////////////////////////////////////////////////
109 ///////////////////////////////////////////////////////////////////
110 #endif // ZYPP_DATE_H