UFO: Alien Invasion
Loading...
Searching...
No Matches
DateTime.h
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23*/
24
25#pragma once
26
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;
69
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};
bool operator<(const DateTime &other) const
Decides if the left DateTime is earlier than the right one.
Definition DateTime.cpp:126
DateTime & operator+=(const DateTime &other)
Adds a DateTime (duration) to the left DateTime object.
Definition DateTime.cpp:66
bool operator>=(const DateTime &other) const
Decides if the left DateTime is later or equal to the right one.
Definition DateTime.cpp:150
static const short HOURS_PER_DAY
Definition DateTime.h:36
int second
Definition DateTime.h:68
static const short SEASONS_PER_YEAR
Definition DateTime.h:40
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
int getTimeAsSeconds() const
Return the time part of the DateTime as seconds.
Definition DateTime.cpp:54
bool operator==(const DateTime &other) const
Decides whether two DateTimes are equal.
Definition DateTime.cpp:110
void reCalculate(void)
Handle over- and underflowing date/time parts.
Definition DateTime.cpp:160
static const short SECONDS_PER_MINUTE
Definition DateTime.h:34
bool operator!=(const DateTime &other) const
Decides whether two DateTimes are different.
Definition DateTime.cpp:118
DateTime operator+(const DateTime &other) const
Calcluate the summary of two DateTime objects in a new one.
Definition DateTime.cpp:79
static const short MONTHS_PER_YEAR
Definition DateTime.h:39
static const short MINUTES_PER_HOUR
Definition DateTime.h:35
static const short SECONDS_PER_HOUR
Definition DateTime.h:42
bool operator>(const DateTime &other) const
Decides if the left DateTime is later than the right one.
Definition DateTime.cpp:142
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 int DAYS_PER_YEAR
Definition DateTime.h:37
DateTime operator-(const DateTime &other) const
Calcluate the difference of two DateTime objects in a new one.
Definition DateTime.cpp:102
DateTime & operator-=(const DateTime &other)
Substracts a DateTime (duration) from the left DateTime object.
Definition DateTime.cpp:89
int day
Definition DateTime.h:67
static constexpr float DAYS_PER_YEAR_AVG
Definition DateTime.h:38
int getDateAsDays() const
Return the date part of the DateTime as days.
Definition DateTime.cpp:46
void format(__printf__, 1, 2)))