aboutsummaryrefslogtreecommitdiff
path: root/src/time.cpp
diff options
context:
space:
mode:
authorSanJacobs2022-04-19 00:21:04 +0200
committerSanJacobs2022-04-19 00:21:04 +0200
commit89ffc2637b6b8e33f55728e0132d62749c53ec1d (patch)
tree492d6602da604ce599a8941efa63557c112fe0c7 /src/time.cpp
parent181442ab4256f3c12ef0a62ed44e6e9fd0f58095 (diff)
downloadsatscalc-89ffc2637b6b8e33f55728e0132d62749c53ec1d.tar.gz
satscalc-89ffc2637b6b8e33f55728e0132d62749c53ec1d.tar.bz2
satscalc-89ffc2637b6b8e33f55728e0132d62749c53ec1d.zip
Tested and bugfixed delta-generation
I also added a beautiful operator<< overloading for deltas, I think it is very pretty.
Diffstat (limited to 'src/time.cpp')
-rwxr-xr-xsrc/time.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/time.cpp b/src/time.cpp
index 29af5be..78f2a53 100755
--- a/src/time.cpp
+++ b/src/time.cpp
@@ -60,20 +60,30 @@ delta moment::operator-(const moment& other) const {
while(decumulator.year - benchmark.year > 1 ||
decumulator.month - benchmark.month > 1 ||
decumulator.day - benchmark.day > 1) {
- wind(decumulator, 0, 0, 1);
+ wind(decumulator, 0, 0, -1);
accumulator.days++;
}
while(decumulator.hours - benchmark.hours > 1) {
- wind(decumulator, 0, 1, 0);
+ wind(decumulator, 0, -1, 0);
accumulator.hours++;
}
while(decumulator != benchmark) {
- wind(decumulator, 1, 0, 0);
- accumulator.minutes++;
+ wind(decumulator, -1, 0, 0);
+ accumulator.minutes = accumulator.minutes+1;
+ }
+ while(accumulator.minutes > 59) {
+ accumulator.minutes -= 60;
+ accumulator.hours++;
}
return accumulator;
}
+std::ostream& operator<<(std::ostream& stream, const delta& other) {
+ if(other.days) stream << other.days << " days, ";
+ if(other.hours) stream << other.hours << " hours, ";
+ if(other.minutes) stream << other.minutes << " minutes.";
+ return stream;
+}
//