From 89ffc2637b6b8e33f55728e0132d62749c53ec1d Mon Sep 17 00:00:00 2001 From: SanJacobs Date: Tue, 19 Apr 2022 00:21:04 +0200 Subject: Tested and bugfixed delta-generation I also added a beautiful operator<< overloading for deltas, I think it is very pretty. --- src/time.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/time.cpp') 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; +} // -- cgit v1.2.1