libcamgm
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
src
ca-mgm
Date.hpp
Go to the documentation of this file.
1
/*---------------------------------------------------------------------\
2
| |
3
| _ _ _ _ __ _ |
4
| | | | | | \_/ | / \ | | |
5
| | | | | | |_| | / /\ \ | | |
6
| | |__ | | | | | | / ____ \ | |__ |
7
| |____||_| |_| |_|/ / \ \|____| |
8
| |
9
| core library |
10
| |
11
| (C) SUSE Linux Products GmbH |
12
\----------------------------------------------------------------------/
13
14
File: Date.hpp
15
16
Author: Michael Andres
17
18
/-*/
19
#ifndef CA_MGM_DATE_HPP
20
#define CA_MGM_DATE_HPP
21
22
#include <ctime>
23
#include <iosfwd>
24
#include <string>
25
26
#include <
ca-mgm/Exception.hpp
>
27
29
namespace
ca_mgm
30
{
31
33
//
34
// CLASS NAME : Date
35
//
38
class
Date
39
{
40
friend
std::ostream &
operator<<
( std::ostream & str,
const
Date
& obj );
41
42
public
:
43
44
typedef
time_t
ValueType
;
45
47
Date
()
48
:
_date
( 0 )
49
{}
51
Date
(
ValueType
date_r )
52
:
_date
( date_r )
53
{}
55
Date
(
const
std::string & seconds_r );
56
63
Date
(
const
std::string & date_str,
const
std::string & format,
bool
utc =
false
);
64
66
static
Date
now
()
67
{ return ::time( 0 ); }
68
69
public
:
71
operator
ValueType
()
const
72
{
return
_date
; }
73
78
Date
&
operator+=
(
const
time_t rhs ) {
_date
+= rhs;
return
*
this
; }
79
Date
&
operator-=
(
const
time_t rhs ) {
_date
-= rhs;
return
*
this
; }
80
Date
&
operator*=
(
const
time_t rhs ) {
_date
*= rhs;
return
*
this
; }
81
Date
&
operator/=
(
const
time_t rhs ) {
_date
/= rhs;
return
*
this
; }
82
83
Date
&
operator++
(
/*prefix*/
) {
_date
+= 1;
return
*
this
; }
84
Date
&
operator--
(
/*prefix*/
) {
_date
-= 1;
return
*
this
; }
85
86
Date
operator++
(
int
/*postfix*/
) {
return
_date
++; }
87
Date
operator--
(
int
/*postfix*/
) {
return
_date
--; }
89
90
public
:
97
std::string
form
(
const
std::string & format_r,
bool
utc =
false
)
const
;
98
102
std::string
asString
()
const
103
{
return
form
(
"%c"
); }
104
108
std::string
asSeconds
()
const
109
{
return
form
(
"%s"
); }
110
111
private
:
116
ValueType
_date
;
117
};
119
121
inline
std::ostream &
operator<<
( std::ostream & str,
const
Date
& obj )
122
{
return
str << obj.
asString
(); }
123
125
}
// namespace ca_mgm
127
#endif // CA_MGM_DATE_HPP
Generated by
1.8.2