aboutsummaryrefslogtreecommitdiff
path: root/C++/Time Header.wiki
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-09-06 12:24:03 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-09-06 12:24:03 +0200
commit95bfddc4329119535cf2fb47bef3c1b87f61e411 (patch)
tree69c5b24bfe8fb7028450aaed7f0abf38f40329da /C++/Time Header.wiki
parentons 31 aug 2022 17:37:49 CEST (diff)
downloadwiki-public-95bfddc4329119535cf2fb47bef3c1b87f61e411.tar.gz
wiki-public-95bfddc4329119535cf2fb47bef3c1b87f61e411.tar.xz
tis 6 sep 2022 12:24:03 CEST
Diffstat (limited to '')
-rw-r--r--C++/Time Header.wiki54
1 files changed, 54 insertions, 0 deletions
diff --git a/C++/Time Header.wiki b/C++/Time Header.wiki
new file mode 100644
index 0000000..abc1b12
--- /dev/null
+++ b/C++/Time Header.wiki
@@ -0,0 +1,54 @@
+= Time Header =
+
+A silly header which allows timestamps to be written in english.
+
+{{{c++
+#pragma once
+
+#include <ostream>
+
+enum timetype {
+ _day, _hour, _minute, _second
+};
+
+class Time {
+private:
+
+ int _days = 0;
+ int _hours = 0;
+ int _minutes = 0;
+ int _seconds = 0;
+
+public:
+ Time() { };
+ Time(int n, timetype type);
+
+ int to_seconds() const;
+
+ friend std::ostream& operator<<(std::ostream&, const Time&);
+ friend Time operator * (int, Time);
+
+ Time operator + (const Time&);
+ Time operator , (const Time& t) { return *this + t; }
+ Time operator && (const Time& t) { return *this + t; }
+};
+
+#define days * Time(1, _day)
+#define day days
+#define hours * Time(1, _hour)
+#define hour hours
+#define minutes * Time(1, _minute)
+#define minute minutes
+#define seconds * Time(1, _second)
+#define second seconds
+
+int main() {
+ std::cout
+ << 5 days << std::endl
+ << 7 minutes << std::endl
+ << (5 days and 3 seconds) << std::endl
+ << (7 days, 7 minutes and 3 seconds) << std::endl
+ << (9 hours and 1 second) << std::endl
+ ;
+}
+}}}