diff --git a/libs/libcommon/include/common/DateLUTImpl.h b/libs/libcommon/include/common/DateLUTImpl.h index 505ee968f6b699ed12f7aa0cc47c91196135d86f..f506e7a82f688e982a9fa7c06b4fbb1e41fde117 100644 --- a/libs/libcommon/include/common/DateLUTImpl.h +++ b/libs/libcommon/include/common/DateLUTImpl.h @@ -247,6 +247,8 @@ public: time_t res = t - lut[index].date; + /// NOTE We doesn't support cases when time change result in switching to previous day. + /// Data is cleaned to avoid these cases, so no underflow occurs here. if (res >= lut[index].time_at_offset_change) res += lut[index].amount_of_offset_change; diff --git a/libs/libcommon/src/DateLUTImpl.cpp b/libs/libcommon/src/DateLUTImpl.cpp index 5b3fc2a295e0e477c2bd94a6e94123a9017ecd77..95e5454f90de2411b2718c060ff264af93ba7904 100644 --- a/libs/libcommon/src/DateLUTImpl.cpp +++ b/libs/libcommon/src/DateLUTImpl.cpp @@ -116,6 +116,15 @@ DateLUTImpl::DateLUTImpl(const std::string & time_zone_) /* std::cerr << lut[i - 1].year << "-" << int(lut[i - 1].month) << "-" << int(lut[i - 1].day_of_month) << " offset was changed at " << lut[i - 1].time_at_offset_change << " for " << lut[i - 1].amount_of_offset_change << " seconds.\n";*/ + + /** We doesn't support cases when time change results in switching to previous day. + * As an example, it was a case in Moscow at years 1981..1983 on October 1: + * clock was adjusted one hour backwards exactly at midnight (that was lead to extra hour 23 of Sep 30th). + * We must clean data (and we will make it slightly incorrect) to avoid these cases. + * (In previous example, it will lead to extra hour 0 of Sep 30 instead.) + */ + if (static_cast(lut[i - 1].time_at_offset_change) + static_cast(lut[i - 1].amount_of_offset_change) < 0) + lut[i - 1].time_at_offset_change = -lut[i - 1].amount_of_offset_change; } }