| 1 | // | 
|---|
| 2 | // Timespan.cpp | 
|---|
| 3 | // | 
|---|
| 4 | // Library: Foundation | 
|---|
| 5 | // Package: DateTime | 
|---|
| 6 | // Module:  Timespan | 
|---|
| 7 | // | 
|---|
| 8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. | 
|---|
| 9 | // and Contributors. | 
|---|
| 10 | // | 
|---|
| 11 | // SPDX-License-Identifier:	BSL-1.0 | 
|---|
| 12 | // | 
|---|
| 13 |  | 
|---|
| 14 |  | 
|---|
| 15 | #include "Poco/Timespan.h" | 
|---|
| 16 | #include <algorithm> | 
|---|
| 17 |  | 
|---|
| 18 |  | 
|---|
| 19 | namespace Poco { | 
|---|
| 20 |  | 
|---|
| 21 |  | 
|---|
| 22 | const Timespan::TimeDiff Timespan::MILLISECONDS = 1000; | 
|---|
| 23 | const Timespan::TimeDiff Timespan::SECONDS      = 1000*Timespan::MILLISECONDS; | 
|---|
| 24 | const Timespan::TimeDiff Timespan::MINUTES      =   60*Timespan::SECONDS; | 
|---|
| 25 | const Timespan::TimeDiff Timespan::HOURS        =   60*Timespan::MINUTES; | 
|---|
| 26 | const Timespan::TimeDiff Timespan::DAYS         =   24*Timespan::HOURS; | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | Timespan::Timespan(): | 
|---|
| 30 | _span(0) | 
|---|
| 31 | { | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | Timespan::Timespan(TimeDiff microSeconds): | 
|---|
| 36 | _span(microSeconds) | 
|---|
| 37 | { | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | Timespan::Timespan(long otherSeconds, long otherMicroSeconds): | 
|---|
| 42 | _span(TimeDiff(otherSeconds)*SECONDS + otherMicroSeconds) | 
|---|
| 43 | { | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 |  | 
|---|
| 47 | Timespan::Timespan(int otherDays, int otherHours, int otherMinutes, int otherSeconds, int otherMicroSeconds): | 
|---|
| 48 | _span(TimeDiff(otherMicroSeconds) + TimeDiff(otherSeconds)*SECONDS + TimeDiff(otherMinutes)*MINUTES + TimeDiff(otherHours)*HOURS + TimeDiff(otherDays)*DAYS) | 
|---|
| 49 | { | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | Timespan::Timespan(const Timespan& timespan): | 
|---|
| 54 | _span(timespan._span) | 
|---|
| 55 | { | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 |  | 
|---|
| 59 | Timespan& Timespan::operator = (const Timespan& timespan) | 
|---|
| 60 | { | 
|---|
| 61 | _span = timespan._span; | 
|---|
| 62 | return *this; | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 |  | 
|---|
| 66 | Timespan& Timespan::operator = (TimeDiff microSeconds) | 
|---|
| 67 | { | 
|---|
| 68 | _span = microSeconds; | 
|---|
| 69 | return *this; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 |  | 
|---|
| 73 | Timespan& Timespan::assign(int otherDays, int otherHours, int otherMinutes, int otherSeconds, int otherMicroSeconds) | 
|---|
| 74 | { | 
|---|
| 75 | _span = TimeDiff(otherMicroSeconds) + TimeDiff(otherSeconds)*SECONDS + TimeDiff(otherMinutes)*MINUTES + TimeDiff(otherHours)*HOURS + TimeDiff(otherDays)*DAYS; | 
|---|
| 76 | return *this; | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 |  | 
|---|
| 80 | Timespan& Timespan::assign(long otherSeconds, long otherMicroSeconds) | 
|---|
| 81 | { | 
|---|
| 82 | _span = TimeDiff(otherSeconds)*SECONDS + TimeDiff(otherMicroSeconds); | 
|---|
| 83 | return *this; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 |  | 
|---|
| 87 | void Timespan::swap(Timespan& timespan) | 
|---|
| 88 | { | 
|---|
| 89 | std::swap(_span, timespan._span); | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 | Timespan Timespan::operator + (const Timespan& d) const | 
|---|
| 94 | { | 
|---|
| 95 | return Timespan(_span + d._span); | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 |  | 
|---|
| 99 | Timespan Timespan::operator - (const Timespan& d) const | 
|---|
| 100 | { | 
|---|
| 101 | return Timespan(_span - d._span); | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 |  | 
|---|
| 105 | Timespan& Timespan::operator += (const Timespan& d) | 
|---|
| 106 | { | 
|---|
| 107 | _span += d._span; | 
|---|
| 108 | return *this; | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 | Timespan& Timespan::operator -= (const Timespan& d) | 
|---|
| 113 | { | 
|---|
| 114 | _span -= d._span; | 
|---|
| 115 | return *this; | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 |  | 
|---|
| 119 | Timespan Timespan::operator + (TimeDiff microSeconds) const | 
|---|
| 120 | { | 
|---|
| 121 | return Timespan(_span + microSeconds); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 |  | 
|---|
| 125 | Timespan Timespan::operator - (TimeDiff microSeconds) const | 
|---|
| 126 | { | 
|---|
| 127 | return Timespan(_span - microSeconds); | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | Timespan& Timespan::operator += (TimeDiff microSeconds) | 
|---|
| 132 | { | 
|---|
| 133 | _span += microSeconds; | 
|---|
| 134 | return *this; | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 |  | 
|---|
| 138 | Timespan& Timespan::operator -= (TimeDiff microSeconds) | 
|---|
| 139 | { | 
|---|
| 140 | _span -= microSeconds; | 
|---|
| 141 | return *this; | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 |  | 
|---|
| 145 | } // namespace Poco | 
|---|
| 146 |  | 
|---|