source: trunk/lib/Date.h

Last change on this file was 1515, checked in by Peter Johansson, 9 years ago

update copyright years

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