UFO: Alien Invasion
Doxygen documentation generating
DateTime.h
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2023 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24 
25 #pragma once
26 
30 class DateTime
31 {
32  public:
33  /* basic time constants */
34  static const short SECONDS_PER_MINUTE = 60;
35  static const short MINUTES_PER_HOUR = 60;
36  static const short HOURS_PER_DAY = 24;
37  static const int DAYS_PER_YEAR = 365;
38  static constexpr float DAYS_PER_YEAR_AVG = 365.25f;
39  static const short MONTHS_PER_YEAR = 12;
40  static const short SEASONS_PER_YEAR = 4;
41  /* computed time constants*/
44 
45  /* constructors */
46  DateTime(int day = 0, int second = 0);
47 
48  /* public methods */
49  int getDateAsDays() const;
50  int getTimeAsSeconds() const;
51 
52  /* operators */
53  DateTime& operator+=(const DateTime& other);
54  DateTime operator+(const DateTime& other) const;
55  DateTime& operator-=(const DateTime& other);
56  DateTime operator-(const DateTime& other) const;
57 
58  bool operator==(const DateTime& other) const;
59  bool operator!=(const DateTime& other) const;
60  bool operator<(const DateTime& other) const;
61  bool operator<=(const DateTime& other) const;
62  bool operator>(const DateTime& other) const;
63  bool operator>=(const DateTime& other) const;
64 
65  protected:
66  /* internal data */
67  int day;
68  int second;
70  /* private methods */
71  void reCalculate(void);
72 #if 0
73  /* public methods */
74  void getDateParts(int* year, short* month, short* day, short* hour, short* minute, short* second) const;
75  int getYear(void) const;
76  int getMonth(void) const;
77  int getDay(void) const;
78  int getHour(void) const;
79  int getMinute(void) const;
80  int getSecond(void) const;
81 
82  const char* asString(const char* format) const;
83 #endif
84 };
static constexpr float DAYS_PER_YEAR_AVG
Definition: DateTime.h:38
Class describing a point of time.
Definition: DateTime.h:30
static const short MONTHS_PER_YEAR
Definition: DateTime.h:39
DateTime & operator-=(const DateTime &other)
Substracts a DateTime (duration) from the left DateTime object.
Definition: DateTime.cpp:89
DateTime operator-(const DateTime &other) const
Calcluate the difference of two DateTime objects in a new one.
Definition: DateTime.cpp:102
bool operator==(const DateTime &other) const
Decides whether two DateTimes are equal.
Definition: DateTime.cpp:110
DateTime(int day=0, int second=0)
Construct for DateTime class from date as days and time as seconds.
Definition: DateTime.cpp:34
static const int SECONDS_PER_DAY
Definition: DateTime.h:43
bool operator>(const DateTime &other) const
Decides if the left DateTime is later than the right one.
Definition: DateTime.cpp:142
static const int DAYS_PER_YEAR
Definition: DateTime.h:37
bool operator<=(const DateTime &other) const
Decides if the left DateTime is earlier or equal to the right one.
Definition: DateTime.cpp:134
static const short SEASONS_PER_YEAR
Definition: DateTime.h:40
int getTimeAsSeconds() const
Return the time part of the DateTime as seconds.
Definition: DateTime.cpp:54
DateTime & operator+=(const DateTime &other)
Adds a DateTime (duration) to the left DateTime object.
Definition: DateTime.cpp:66
void reCalculate(void)
Handle over- and underflowing date/time parts.
Definition: DateTime.cpp:160
int getDateAsDays() const
Return the date part of the DateTime as days.
Definition: DateTime.cpp:46
bool operator>=(const DateTime &other) const
Decides if the left DateTime is later or equal to the right one.
Definition: DateTime.cpp:150
int second
Definition: DateTime.h:68
DateTime operator+(const DateTime &other) const
Calcluate the summary of two DateTime objects in a new one.
Definition: DateTime.cpp:79
static const short SECONDS_PER_MINUTE
Definition: DateTime.h:34
static const short SECONDS_PER_HOUR
Definition: DateTime.h:42
static const short MINUTES_PER_HOUR
Definition: DateTime.h:35
int day
Definition: DateTime.h:67
bool operator<(const DateTime &other) const
Decides if the left DateTime is earlier than the right one.
Definition: DateTime.cpp:126
static const short HOURS_PER_DAY
Definition: DateTime.h:36
void format(__printf__, 1, 2)))
bool operator!=(const DateTime &other) const
Decides whether two DateTimes are different.
Definition: DateTime.cpp:118