Skip to content

Commit 6df049a

Browse files
committed
Make coverity happy with negative years
commit_hash:ea8eb1df0c2c653fe0948b0550ebedc25cdf03c0
1 parent 49b05ea commit 6df049a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

yql/essentials/minikql/datetime/datetime.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,12 @@ bool DoAddMonths(TStorage& storage, i64 months, const NUdf::IDateBuilder& builde
170170
storage.Year--;
171171
newMonth += 12;
172172
}
173-
if (storage.Year == 0) {
174-
storage.Year += months > 0 ? 1 : -1;
173+
// The minimal year value for TTMStorage is 1970, but the
174+
// check below makes coverity happy.
175+
if constexpr (!std::is_same_v<TStorage, TTMStorage>) {
176+
if (storage.Year == 0) {
177+
storage.Year += months > 0 ? 1 : -1;
178+
}
175179
}
176180
storage.Month = newMonth;
177181
bool isLeap = NKikimr::NMiniKQL::IsLeapYear(storage.Year);
@@ -183,8 +187,12 @@ bool DoAddMonths(TStorage& storage, i64 months, const NUdf::IDateBuilder& builde
183187
template<typename TStorage>
184188
bool DoAddYears(TStorage& storage, i64 years, const NUdf::IDateBuilder& builder) {
185189
storage.Year += years;
186-
if (storage.Year == 0) {
187-
storage.Year += years > 0 ? 1 : -1;
190+
// The minimal year value for TTMStorage is 1970, but the
191+
// check below makes coverity happy.
192+
if constexpr (!std::is_same_v<TStorage, TTMStorage>) {
193+
if (storage.Year == 0) {
194+
storage.Year += years > 0 ? 1 : -1;
195+
}
188196
}
189197
if (storage.Month == 2 && storage.Day == 29) {
190198
bool isLeap = NKikimr::NMiniKQL::IsLeapYear(storage.Year);

0 commit comments

Comments
 (0)