source: trunk/lib/Date.h @ 519

Last change on this file since 519 was 519, checked in by Jari Häkkinen, 13 years ago

trac moved to new location.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1#ifndef _theplu_svndigest_date_
2#define _theplu_svndigest_date_
3
4// $Id: Date.h 519 2007-12-23 20:14:50Z jari $
5
6/*
7  Copyright (C) 2007 Peter Johansson
8
9  This file is part of svndigest, http://trac.thep.lu.se/svndigest
10
11  svndigest is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 2 of the License, or
14  (at your option) any later version.
15
16  svndigest is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include <ctime>
28#include <vector>
29#include <string>
30
31namespace theplu{
32namespace svndigest{
33
34  ///
35  /// Class taking care of time and date handling.
36  ///
37  class Date
38  {
39  public:
40    ///
41    /// @brief Constructor
42    ///
43    Date(void);
44
45    ///
46    /// @brief Copy Constructor
47    ///
48    Date(const Date&);
49
50    ///
51    /// @brief Constructor from svn date string
52    ///
53    /// @see svntime(std::string)
54    ///
55    Date(std::string);
56
57    ///
58    /// @return string describing distance between two dates
59    ///
60    std::string difftime(const Date& other) const;
61
62    ///
63    /// @brief sets time to gmtime
64    ///
65    void gmtime(void);
66
67    ///
68    /// @brief sets time to local time
69    ///
70    void localtime(void);
71
72    ///
73    /// \brief sets time from a svn time string
74    ///
75    /// \parameter str string in format 2006-09-09T10:55:52.132733Z
76    ///
77    void svntime(std::string str);
78
79    ///
80    /// \return seconds since 00:00:00 Jan 1 1970
81    ///
82    inline time_t seconds(void) const { return time_; }
83
84    ///
85    /// \a format sets the format of the returned string. Supported
86    /// parameters are:
87    /// %a - short string of weekday e.g. Wed
88    /// %A - long string of weekday e.g. Wednesday
89    /// %b - short string of month e.g. Apr
90    /// %B - long string of weekday e.g. April
91    /// %d - day of month integer e.g. 9
92    /// %e - day of month integer e.g. 09
93    /// %H - hours [0,23]
94    /// %I - hours [1,12]
95    /// %j - day of the year [1,366]
96    /// %m - month integer e.g. 04
97    /// %M - minutes after the hour [0,59]
98    /// %P - AM or PM
99    /// %S - seconds efter the minute [0,59]
100    /// %w - day of week [1,7] Sunday is 7
101    /// %y - year in two digits
102    /// %Y - year in four digits
103    /// %Z - timezone abbrevation
104    ///
105    /// \return date and time
106    ///
107    std::string operator()(std::string format) const;
108
109    ///
110    /// @brief assignment operator
111    ///
112    /// @return const reference to assigned Date
113    ///
114    const Date& operator=(const Date&);
115
116    ///
117    /// @return true if lhs is earlier than \a rhs
118    ///
119    inline bool operator<(const Date& rhs) const 
120    { return time_<rhs.time_; }
121
122  private:
123    time_t time_;
124  };
125
126}}
127#endif
Note: See TracBrowser for help on using the repository browser.