/src/poco/Foundation/src/Timespan.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 0 | _span(0) |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | |
35 | | Timespan::Timespan(TimeDiff microSeconds): |
36 | 40.8k | _span(microSeconds) |
37 | 40.8k | { |
38 | 40.8k | } |
39 | | |
40 | | |
41 | | Timespan::Timespan(long seconds, long microSeconds): |
42 | 0 | _span(TimeDiff(seconds)*SECONDS + microSeconds) |
43 | 0 | { |
44 | 0 | } |
45 | | |
46 | | |
47 | | Timespan::Timespan(int days, int hours, int minutes, int seconds, int microSeconds): |
48 | 0 | _span(TimeDiff(microSeconds) + TimeDiff(seconds)*SECONDS + TimeDiff(minutes)*MINUTES + TimeDiff(hours)*HOURS + TimeDiff(days)*DAYS) |
49 | 0 | { |
50 | 0 | } |
51 | | |
52 | | |
53 | | Timespan::Timespan(const Timespan& timespan): |
54 | 0 | _span(timespan._span) |
55 | 0 | { |
56 | 0 | } |
57 | | |
58 | | |
59 | | Timespan& Timespan::operator = (const Timespan& timespan) |
60 | 0 | { |
61 | 0 | _span = timespan._span; |
62 | 0 | return *this; |
63 | 0 | } |
64 | | |
65 | | |
66 | | Timespan& Timespan::operator = (TimeDiff microSeconds) |
67 | 0 | { |
68 | 0 | _span = microSeconds; |
69 | 0 | return *this; |
70 | 0 | } |
71 | | |
72 | | |
73 | | Timespan& Timespan::assign(int days, int hours, int minutes, int seconds, int microSeconds) |
74 | 0 | { |
75 | 0 | _span = TimeDiff(microSeconds) + TimeDiff(seconds)*SECONDS + TimeDiff(minutes)*MINUTES + TimeDiff(hours)*HOURS + TimeDiff(days)*DAYS; |
76 | 0 | return *this; |
77 | 0 | } |
78 | | |
79 | | |
80 | | Timespan& Timespan::assign(long seconds, long microSeconds) |
81 | 0 | { |
82 | 0 | _span = TimeDiff(seconds)*SECONDS + TimeDiff(microSeconds); |
83 | 0 | return *this; |
84 | 0 | } |
85 | | |
86 | | |
87 | | void Timespan::swap(Timespan& timespan) noexcept |
88 | 0 | { |
89 | 0 | std::swap(_span, timespan._span); |
90 | 0 | } |
91 | | |
92 | | |
93 | | Timespan Timespan::operator + (const Timespan& d) const |
94 | 0 | { |
95 | 0 | return Timespan(_span + d._span); |
96 | 0 | } |
97 | | |
98 | | |
99 | | Timespan Timespan::operator - (const Timespan& d) const |
100 | 0 | { |
101 | 0 | return Timespan(_span - d._span); |
102 | 0 | } |
103 | | |
104 | | |
105 | | Timespan& Timespan::operator += (const Timespan& d) |
106 | 0 | { |
107 | 0 | _span += d._span; |
108 | 0 | return *this; |
109 | 0 | } |
110 | | |
111 | | |
112 | | Timespan& Timespan::operator -= (const Timespan& d) |
113 | 0 | { |
114 | 0 | _span -= d._span; |
115 | 0 | return *this; |
116 | 0 | } |
117 | | |
118 | | |
119 | | Timespan Timespan::operator + (TimeDiff microSeconds) const |
120 | 0 | { |
121 | 0 | return Timespan(_span + microSeconds); |
122 | 0 | } |
123 | | |
124 | | |
125 | | Timespan Timespan::operator - (TimeDiff microSeconds) const |
126 | 0 | { |
127 | 0 | return Timespan(_span - microSeconds); |
128 | 0 | } |
129 | | |
130 | | |
131 | | Timespan& Timespan::operator += (TimeDiff microSeconds) |
132 | 0 | { |
133 | 0 | _span += microSeconds; |
134 | 0 | return *this; |
135 | 0 | } |
136 | | |
137 | | |
138 | | Timespan& Timespan::operator -= (TimeDiff microSeconds) |
139 | 0 | { |
140 | 0 | _span -= microSeconds; |
141 | 0 | return *this; |
142 | 0 | } |
143 | | |
144 | | |
145 | | } // namespace Poco |