libzypp
11.13.5
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Date.h
Go to the documentation of this file.
1
/*---------------------------------------------------------------------\
2
| ____ _ __ __ ___ |
3
| |__ / \ / / . \ . \ |
4
| / / \ V /| _/ _/ |
5
| / /__ | | | | | | |
6
| /_____||_| |_| |_| |
7
| |
8
\---------------------------------------------------------------------*/
12
#ifndef ZYPP_DATE_H
13
#define ZYPP_DATE_H
14
15
#include <ctime>
16
#include <iosfwd>
17
#include <string>
18
19
#include "
zypp/base/Exception.h
"
20
22
namespace
zypp
23
{
24
26
//
27
// CLASS NAME : Date
28
//
31
class
Date
32
{
33
friend
std::ostream &
operator<<
( std::ostream & str,
const
Date
& obj );
34
35
public
:
36
37
typedef
time_t
ValueType
;
38
39
static
const
ValueType
second
= 1;
40
static
const
ValueType
minute
= 60;
41
static
const
ValueType
hour
= 3600;
42
static
const
ValueType
day
= 86400;
43
static
const
ValueType
month28
= 2419200;
44
static
const
ValueType
month29
= 2505600;
45
static
const
ValueType
month30
= 2592000;
46
static
const
ValueType
month31
= 2678400;
47
static
const
ValueType
month
=
month30
;
48
static
const
ValueType
year365
= 31536000;
49
static
const
ValueType
year366
= 31622400;
50
static
const
ValueType
year
=
year365
;
51
52
enum
TimeBase
{
TB_LOCALTIME
,
TB_UTC
};
53
55
Date
()
56
:
_date
( 0 )
57
{}
59
Date
(
ValueType
date_r )
60
:
_date
( date_r )
61
{}
63
Date
(
const
std::string & seconds_r );
64
71
Date
(
const
std::string & date_str,
const
std::string & format );
73
Date
(
const
std::string & date_str,
const
std::string & format,
TimeBase
base_r );
74
76
static
Date
now
()
77
{ return ::time( 0 ); }
78
79
public
:
81
operator
ValueType
()
const
82
{
return
_date
; }
83
88
Date
&
operator+=
(
const
time_t rhs ) {
_date
+= rhs;
return
*
this
; }
89
Date
&
operator-=
(
const
time_t rhs ) {
_date
-= rhs;
return
*
this
; }
90
Date
&
operator*=
(
const
time_t rhs ) {
_date
*= rhs;
return
*
this
; }
91
Date
&
operator/=
(
const
time_t rhs ) {
_date
/= rhs;
return
*
this
; }
92
93
Date
&
operator++
(
/*prefix*/
) {
_date
+= 1;
return
*
this
; }
94
Date
&
operator--
(
/*prefix*/
) {
_date
-= 1;
return
*
this
; }
95
96
Date
operator++
(
int
/*postfix*/
) {
return
_date
++; }
97
Date
operator--
(
int
/*postfix*/
) {
return
_date
--; }
99
100
public
:
107
std::string
form
(
const
std::string & format_r )
const
108
{
return
form
( format_r,
TB_LOCALTIME
); }
110
std::string
form
(
const
std::string & format_r,
TimeBase
base_r )
const
;
111
115
std::string
asString
()
const
116
{
return
form
(
"%c"
); }
117
121
std::string
asSeconds
()
const
122
{
return
form
(
"%s"
); }
123
124
private
:
129
ValueType
_date
;
130
};
132
134
inline
std::ostream &
operator<<
( std::ostream & str,
const
Date
& obj )
135
{
return
str << obj.
asString
(); }
136
137
class
DateFormatException
:
public
Exception
138
{
139
public
:
140
DateFormatException
(
const
std::string &
msg
) :
Exception
( msg )
141
{}
142
};
143
145
}
// namespace zypp
147
#endif // ZYPP_DATE_H
zypp
Date.h
Generated by
1.8.1