wavelength 1.0.0
Loading...
Searching...
No Matches
datetime.h
Go to the documentation of this file.
1#pragma once
2
3#include "os/binstream.h"
4#include "os/prnstream.h"
5#include "os/string.h"
6
14class DateTime {
15public:
17 DateTime() = default;
18
28 explicit DateTime(unsigned int nSeconds);
29
40 bool ReadClock();
41
51 static void PollClock();
52
63 unsigned int ToSeconds() const;
64
73 void FormatDateTime(String &text) const;
74
82 void FormatDate(String &text) const;
83
91 void FormatMonthDay(String &text) const;
92
101 void FormatShortDate(String &text) const;
102
111 bool operator<(const DateTime &other) const;
112
114 unsigned char GetSecond() const {
115 return mSecond;
116 }
117
119 void SetSecond(unsigned char nSecond) {
120 mSecond = nSecond;
121 }
122
124 unsigned char GetMinute() const {
125 return mMinute;
126 }
127
129 void SetMinute(unsigned char nMinute) {
130 mMinute = nMinute;
131 }
132
134 unsigned char GetHour() const {
135 return mHour;
136 }
137
139 void SetHour(unsigned char nHour) {
140 mHour = nHour;
141 }
142
144 unsigned char GetDay() const {
145 return mDay;
146 }
147
149 void SetDay(unsigned char nDay) {
150 mDay = nDay;
151 }
152
154 unsigned char GetMonth() const {
155 return mMonth;
156 }
157
159 void SetMonth(unsigned char nMonth) {
160 mMonth = nMonth;
161 }
162
164 unsigned char GetYear() const {
165 return mYear;
166 }
167
169 void SetYear(unsigned char nYear) {
170 mYear = nYear;
171 }
172
173private:
181 static int ReadClockTask();
182
190 static void OnClockRead(int nResult);
191
192 unsigned char mSecond;
193 unsigned char mMinute;
194 unsigned char mHour;
195 unsigned char mDay;
196 unsigned char mMonth;
197 unsigned char mYear;
198};
199
209PrnStream &operator<<(PrnStream &stream, const DateTime &date);
210
220BinStream &operator<<(BinStream &stream, const DateTime &date);
221
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Local date and time of the console clock.
Definition datetime.h:14
unsigned char GetHour() const
Definition datetime.h:134
bool operator<(const DateTime &other) const
Report whether this date is earlier than another.
void SetHour(unsigned char nHour)
Definition datetime.h:139
void SetSecond(unsigned char nSecond)
Definition datetime.h:119
bool ReadClock()
Read the console clock.
void FormatDateTime(String &text) const
Write the date and time as "MM/DD/YYYY HH:MM:SS", or "DD.MM.YYYY HH:MM:SS" in the PAL build.
static void PollClock()
Start a read of the console clock on the worker thread once 30 seconds have passed since the last rea...
unsigned char GetMinute() const
Definition datetime.h:124
DateTime(unsigned int nSeconds)
Construct a date from a count of seconds ToSeconds() reported.
unsigned char GetMonth() const
Definition datetime.h:154
void SetMonth(unsigned char nMonth)
Definition datetime.h:159
void FormatShortDate(String &text) const
Write the date as "MM/DD/YY", or "DD.MM.YY" in the PAL build, the year counted from 2000.
void SetDay(unsigned char nDay)
Definition datetime.h:149
unsigned int ToSeconds() const
Report the date as a count of seconds, with 32-day months and 384-day years from 2000.
void FormatDate(String &text) const
Write the date as "MM/DD/YYYY", or "DD.MM.YYYY" in the PAL build.
unsigned char GetDay() const
Definition datetime.h:144
void FormatMonthDay(String &text) const
Write the month and the day as "MM/DD", or "DD.MM" in the PAL build.
unsigned char GetSecond() const
Definition datetime.h:114
unsigned char GetYear() const
Definition datetime.h:164
DateTime()=default
Construct a date whose fields are not set.
void SetYear(unsigned char nYear)
Definition datetime.h:169
void SetMinute(unsigned char nMinute)
Definition datetime.h:129
Text output stream.
Definition prnstream.h:16
Growable text buffer that is also a PrnStream.
Definition string.h:19
PrnStream & operator<<(PrnStream &stream, const DateTime &date)
Write a date and time as FormatDateTime() does.
BinStream & operator>>(BinStream &stream, DateTime &date)
Read the six bytes of a date.