source: trunk/lib/Date.h @ 978

Last change on this file since 978 was 978, checked in by Peter Johansson, 12 years ago

refs #429. Convert copyright statements to UTF-8

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1#ifndef _theplu_svndigest_date_
2#define _theplu_svndigest_date_
3
4// $Id: Date.h 978 2009-12-12 20:09:41Z peter $
5
6/*
7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
8
9  This file is part of svndigest, http://dev.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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include <ctime>
26#include <vector>
27#include <string>
28
29namespace theplu{
30namespace svndigest{
31
32  ///
33  /// Class taking care of time and date handling.
34  ///
35  class Date
36  {
37  public:
38    ///
39    /// @brief Constructor
40    ///
41    Date(void);
42
43    ///
44    /// @brief Copy Constructor
45    ///
46    Date(const Date&);
47
48    ///
49    /// @brief Constructor from svn date string
50    ///
51    /// @see svntime(std::string)
52    ///
53    Date(std::string);
54
55    ///
56    /// @return string describing distance between two dates
57    ///
58    std::string difftime(const Date& other) const;
59
60    ///
61    /// @brief sets time to gmtime
62    ///
63    void gmtime(void);
64
65    ///
66    /// @brief sets time to local time
67    ///
68    void localtime(void);
69
70    ///
71    /// \brief sets time from a svn time string
72    ///
73    /// \parameter str string in format 2006-09-09T10:55:52.132733Z
74    ///
75    void svntime(std::string str);
76
77    ///
78    /// \return seconds since 00:00:00 Jan 1 1970
79    ///
80    inline time_t seconds(void) const { return time_; }
81
82    ///
83    /// \a format sets the format of the returned string. Supported
84    /// parameters are:
85    /// %a - short string of weekday e.g. Wed
86    /// %A - long string of weekday e.g. Wednesday
87    /// %b - short string of month e.g. Apr
88    /// %B - long string of weekday e.g. April
89    /// %d - day of month integer e.g. 9
90    /// %e - day of month integer e.g. 09
91    /// %H - hours [0,23]
92    /// %I - hours [1,12]
93    /// %j - day of the year [1,366]
94    /// %m - month integer e.g. 04
95    /// %M - minutes after the hour [0,59]
96    /// %P - AM or PM
97    /// %S - seconds efter the minute [0,59]
98    /// %w - day of week [1,7] Sunday is 7
99    /// %y - year in two digits
100    /// %Y - year in four digits
101    /// %Z - timezone abbrevation
102    ///
103    /// \return date and time
104    ///
105    std::string operator()(std::string format) const;
106
107    ///
108    /// @brief assignment operator
109    ///
110    /// @return const reference to assigned Date
111    ///
112    const Date& operator=(const Date&);
113
114    ///
115    /// @return true if lhs is earlier than \a rhs
116    ///
117    inline bool operator<(const Date& rhs) const 
118    { return time_<rhs.time_; }
119
120  private:
121    time_t time_;
122  };
123
124}}
125#endif
Note: See TracBrowser for help on using the repository browser.