Source/Gorgon/Time.h

Tue, 06 Jul 2021 10:22:49 +0300

author
cemkalyoncu
date
Tue, 06 Jul 2021 10:22:49 +0300
branch
4.x-dev
changeset 1701
b168349a931d
parent 1606
eacec6b0aecc
permissions
-rw-r--r--

* Image/Bitmap rotate

764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
1 ///@file Time.h contains time related functions and classes
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
2
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
3 #pragma once
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
4
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
5 #include <string>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
6 #include <sstream>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
7 #include <iomanip>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
8 #include <stdexcept>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
9
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
10 namespace Gorgon {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
11 /// This module contains time related information.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
12 namespace Time {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
13
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
14 /// Initializes Time module.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
15 void Initialize();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
16
810
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
17 class Date;
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
18
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
19 /// Returns the current date. Should not be used for
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
20 /// performance calculations, its not guaranteed to be precise.
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
21 Date GetDate();
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
22
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
23 /// This class represents a specific date including time information.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
24 /// Can be obtained using GetDateTime function. An Empty month marks the
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
25 /// time as unset.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
26 class Date {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
27 public:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
28 /// Days of week. Starts from sunday
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
29 enum WeekdayType {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
30 Sunday=0,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
31 Monday,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
32 Tuesday,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
33 Wednesday,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
34 Thursday,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
35 Friday,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
36 Saturday
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
37 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
38
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
39 /// Months, january is 1.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
40 enum MonthType {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
41 Empty=0,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
42 Jan = 1,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
43 Feb,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
44 Mar,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
45 Apr,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
46 May,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
47 Jun,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
48 Jul,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
49 Agu,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
50 Sep,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
51 Oct,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
52 Nov,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
53 Dec
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
54 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
55
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
56 /// Default constructor, zero initializes the class, making it
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
57 /// an unset time.
1606
eacec6b0aecc * System time to Date
cemkalyoncu
parents: 1481
diff changeset
58 Date() : Year(0), Month(Empty), Day(0), Hour(0), Minute(0),
839
ddfaef71313f * Current state of the graphics module is done
cemkalyoncu
parents: 830
diff changeset
59 Second(0), Millisecond(0), Weekday(Sunday), Timezone(LocalTimezone())
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
60 { }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
61
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
62 /// Creates a new date object from the given ISO-8601 date string. @see Parse
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
63 /// @throw std::runtime_error if the string is malformed or data is not valid
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
64 Date(const std::string &isodate) { if(!Parse(isodate)) throw std::runtime_error("Invalid date"); }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
65
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
66 /// Reads a new date object from a binary stream. @see Save for details.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
67 /// @throw std::runtime_error if checksum is wrong or data is not valid
1606
eacec6b0aecc * System time to Date
cemkalyoncu
parents: 1481
diff changeset
68 explicit Date(std::istream &source) { if(!Load(source)) throw std::runtime_error("Invalid date"); }
eacec6b0aecc * System time to Date
cemkalyoncu
parents: 1481
diff changeset
69
eacec6b0aecc * System time to Date
cemkalyoncu
parents: 1481
diff changeset
70 Date(time_t systemtime);
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
71
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
72 /// Writes date object to a binary stream. Format is given below.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
73 /// numbers after names are number of bytes.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
74 /// @verbatim
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
75 /// <year:2><month:1><day:1><hour:1><minute:1><millis:2><timezone:2><checksum:1>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
76 /// @endverbatim
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
77 /// checksum is the sum of all numbers in base 256.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
78 /// @return true if successful. An empty date will be saved correctly.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
79 bool Save(std::ostream &target);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
80
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
81 /// Loads date object from a binary stream. @see Save for details.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
82 /// @return true if successful.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
83 bool Load(std::istream &source);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
84
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
85 /// Creates a new date object from the given ISO-8601 date string.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
86 /// Requires full information. Following format is recognized:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
87 /// [YYYY]-[MM]-[DD]T[HH]:[mm]:[SS](+/-)[TT][tt]
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
88 /// * YYYY: 4 digit year
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
89 /// * MM : 2 digit month
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
90 /// * DD : 2 digit day
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
91 /// * HH : 2 digit hour
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
92 /// * mm : 2 digit minute
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
93 /// * SS : 2 digit second
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
94 /// * TT : 2 digit timezone hour
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
95 /// * tt : 2 digit timezone minute
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
96 /// Timezone is optional, if omitted default is system timezone. It can also be
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
97 /// specified as Z meaning UTC.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
98 /// @return true if successful.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
99 bool Parse(std::string isodate);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
100
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
101 /// ISO compliant date format. Contains only date
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
102 std::string ISODate() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
103
1202
6f95367fd155 * ISODateTime can now work without a timezone
cemkalyoncu
parents: 839
diff changeset
104 /// ISO compliant date/time. This format should be used to serialize as text.
6f95367fd155 * ISODateTime can now work without a timezone
cemkalyoncu
parents: 839
diff changeset
105 std::string ISODateTime(bool timezone = true) const;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
106
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
107 /// Returns currently stored month's name in English. Month 0 is valid
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
108 /// and returns "".
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
109 /// @throw std::logic_error (debug only) if month is invalid.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
110 const std::string &MonthName_En() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
111
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
112 /// Returns currently stored month's int name in English. Month 0
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
113 /// is valid and returns "".
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
114 /// @throw std::logic_error (debug only) if month is invalid.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
115 const std::string &ShortMonthName_En() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
116
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
117 /// Returns currently stored week day's name in English.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
118 /// @throw std::logic_error (debug only) if weekday is invalid.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
119 const std::string &WeekdayName_En() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
120
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
121 /// Returns currently stored week day's int name in English.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
122 /// @throw std::logic_error (debug only) if weekday is invalid.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
123 const std::string &ShortWeekdayName_En() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
124
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
125 /// Returns stored date in `day monthname year, weekday` format with
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
126 /// English names for month and weekday.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
127 std::string Date_En() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
128
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
129 /// Returns stored date in `day intmonthname year` format with
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
130 /// English names for month.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
131 std::string ShortDate_En() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
132
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
133 /// Returns stored time in `hour:minute:second` format.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
134 std::string Time() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
135
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
136 /// Returns stored time in `hour:minute` format.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
137 std::string ShortTime() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
138
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
139 /// Returns stored timezone. Format depends on the actual timezone.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
140 /// If the timezone offset contains only hours, the format is
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
141 /// `GMT+H` or `GMT-H`. If there is minute offset, timezone is returned
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
142 /// in `GMT+H:MM` or `GMT-H:MM` format. H is the hour without any
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
143 /// leading zeroes, MM is the minute in two digit format.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
144 std::string Timezone_GMT() const;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
145
1606
eacec6b0aecc * System time to Date
cemkalyoncu
parents: 1481
diff changeset
146 time_t SystemTime() const;
eacec6b0aecc * System time to Date
cemkalyoncu
parents: 1481
diff changeset
147
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
148 /// Returns the system timezone in minutes. Might be negative.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
149 static int LocalTimezone();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
150
830
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
151 /// Adds specified amount of years to the date
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
152 void AddYears(int years);
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
153
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
154 /// Adds specified amount of months to the date
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
155 void AddMonths(int months);
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
156
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
157 /// Adds specified amount of days to the date
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
158 void AddDays(int days);
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
159
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
160 /// Adds specified amount of hours to the date
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
161 void AddHours(int hours);
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
162
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
163 /// Adds specified amount of minutes to the date
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
164 void AddMinutes(int minutes);
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
165
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
166 /// Adds specified amount of seconds to the date
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
167 void AddSeconds(int seconds);
dc937409ad24 * Partial design document
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 810
diff changeset
168
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
169 /// Checks whether the stored time is actually set.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
170 bool IsSet() const {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
171 return Month==Empty;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
172 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
173
810
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
174 /// Returns current time
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
175 static Date Now() {
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
176 return GetDate();
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
177 }
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
178
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
179 /// Gives the difference between two dates.
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
180 double operator - (const Date &other);
36c313140b84 * Logger module
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
181
1472
3ab474a95f5a *Comparision operator overload added to Time class.
Luca
parents: 1202
diff changeset
182 /// Compares 2 dates
3ab474a95f5a *Comparision operator overload added to Time class.
Luca
parents: 1202
diff changeset
183 bool operator == (const Date &other) const;
3ab474a95f5a *Comparision operator overload added to Time class.
Luca
parents: 1202
diff changeset
184
3ab474a95f5a *Comparision operator overload added to Time class.
Luca
parents: 1202
diff changeset
185 /// Unsets the stored time
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
186 void Unset() {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
187 Year=0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
188 Month=Empty;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
189 Day=0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
190 Weekday=Sunday;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
191 Hour=0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
192 Minute=0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
193 Second=0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
194 Millisecond=0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
195 Timezone=0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
196 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
197
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
198 /// Determines the weekday from the stored date.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
199 /// @return true if successful
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
200 bool DetermineWeekday();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
201
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
202 /// Full year
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
203 unsigned int Year;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
204
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
205 /// Month starts from jan = 1
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
206 MonthType Month;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
207
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
208 /// Day in month
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
209 unsigned int Day;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
210
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
211 /// Hour in 24 hour format
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
212 unsigned int Hour;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
213
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
214 /// Minute
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
215 unsigned int Minute;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
216
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
217 /// Second
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
218 unsigned int Second;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
219
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
220 /// This value is from the last second tick.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
221 unsigned int Millisecond;
1606
eacec6b0aecc * System time to Date
cemkalyoncu
parents: 1481
diff changeset
222
eacec6b0aecc * System time to Date
cemkalyoncu
parents: 1481
diff changeset
223 /// Day of the week, starts from sunday = 0
eacec6b0aecc * System time to Date
cemkalyoncu
parents: 1481
diff changeset
224 WeekdayType Weekday;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
225
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
226 /// Timezone in minutes, can be negative. Note that some time zones
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
227 /// has minute offset.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
228 int Timezone;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
229 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
230
1473
71d5c7c0628b *Outstream non member function fix.
Luca Tonini
parents: 1472
diff changeset
231 /// Output stream operator overload
1476
e9317f02166d #139: Keyboard handling
cemkalyoncu
parents: 1474
diff changeset
232 inline std::ostream &operator << (std::ostream &out, const Date &date) {
1481
00c4b8cec518 * Date stream out fix
cemkalyoncu
parents: 1476
diff changeset
233 out<<date.ISODateTime(true);
00c4b8cec518 * Date stream out fix
cemkalyoncu
parents: 1476
diff changeset
234
1473
71d5c7c0628b *Outstream non member function fix.
Luca Tonini
parents: 1472
diff changeset
235 return out;
71d5c7c0628b *Outstream non member function fix.
Luca Tonini
parents: 1472
diff changeset
236 }
71d5c7c0628b *Outstream non member function fix.
Luca Tonini
parents: 1472
diff changeset
237
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
238 /// Returns current time in milliseconds.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
239 /// @warning FrameStart should be used unless exact time is required.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
240 /// This function works slower and changes during a frame, which may
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
241 /// cause synchronization issues.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
242 unsigned long GetTime();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
243
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
244
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
245 ///@cond INTERNAL
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
246 namespace internal {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
247 extern unsigned long framestart;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
248 extern unsigned long deltatime;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
249 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
250 ///@endcond
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
251
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
252
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
253 /// Returns start time of the current frame in milliseconds. This function
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
254 /// should be used for animations and effects as it is constant throughout
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
255 /// a frame.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
256 inline unsigned long FrameStart() {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
257 return internal::framestart;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
258 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
259
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
260 /// Returns the time passed since the last frame. This value is updated
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
261 /// at the start of the frame.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
262 inline unsigned long DeltaTime() {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
263 return internal::deltatime;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
264 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
265
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
266
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
267 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
268 }

mercurial