aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-04-24 11:59:50 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-04-24 11:59:50 +0200
commit0cf2beb05e9dc4098252dafa1b053d83f801fef2 (patch)
treec2148932304631b81143bb5aff1a4c737b4a3fa0
parentmån 24 apr 2023 11:58:16 CEST (diff)
downloadwiki-public-0cf2beb05e9dc4098252dafa1b053d83f801fef2.tar.gz
wiki-public-0cf2beb05e9dc4098252dafa1b053d83f801fef2.tar.xz
Supplement missing parts of C++ time header.
-rw-r--r--C++/Time Header.wiki43
1 files changed, 43 insertions, 0 deletions
diff --git a/C++/Time Header.wiki b/C++/Time Header.wiki
index abc1b12..11ace13 100644
--- a/C++/Time Header.wiki
+++ b/C++/Time Header.wiki
@@ -42,6 +42,49 @@ public:
#define seconds * Time(1, _second)
#define second seconds
+Time::Time(int n, timetype type) {
+ switch (type) {
+ case _day: this->_days = n; break;
+ case _hour: this->_hours = n; break;
+ case _minute: this->_minutes = n; break; break;
+ case _second: this->_seconds = n; break; break;
+ }
+}
+
+Time operator * (int s, Time t) {
+ Time u;
+ u._days = t._days * s;
+ u._hours = t._hours * s;
+ u._minutes = t._minutes * s;
+ u._seconds = t._seconds * s;
+ return u;
+}
+
+Time Time::operator + (const Time& t) {
+ Time u;
+ u._days = this->_days + t._days ;
+ u._hours = this->_hours + t._hours ;
+ u._minutes = this->_minutes + t._minutes;
+ u._seconds = this->_seconds + t._seconds;
+ return u;
+}
+
+int Time::to_seconds() const {
+ return
+ 60 * 60 * 24 * this->_days +
+ 60 * 60 * this->_hours +
+ 60 * this->_minutes +
+ this->_seconds;
+}
+
+
+std::ostream& operator<<(std::ostream& out, const Time& time) {
+ out << time.to_seconds() << " seconds";
+ return out;
+}
+
+/* -------------------------------------------------- */
+
int main() {
std::cout
<< 5 days << std::endl