Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Fix: DST switch for NTP client
* Fix/Change: Save data to flash in case of restart from console
* Fix: SunRise-Calculation was wrong for UTC-day-change (this was not an issue for Europe, but e.g. New Zealand)
* Fix/Change: Support negative hours in TimeDate constructor
* Update: Increase minimum OpenKNXproducer version to 4.3.5
* Fix: Suppress warnings for intentionally overlapping parameters
* Feature: Indicate unconfigured and PA not set via PROG-LED
Expand Down
15 changes: 13 additions & 2 deletions src/OpenKNX/DateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,28 @@ namespace OpenKNX
}
}

DateTime::DateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, DateTimeType type)
DateTime::DateTime(uint16_t year, uint8_t month, uint8_t day, int32_t hour, uint8_t minute, uint8_t second, DateTimeType type)
{
// TODO: Check need and support for handling out of range field values.
// Note: Hotfix for negative hours to solve broken SunRise

// 1. setting fiels ONLY
this->year = year;
this->month = month;
this->day = day;
this->hour = hour;
this->hour = hour; // note: additional special handling at the end, for handle hours out of range
this->minute = minute;
this->second = second;
this->isDst = type == DateTimeTypeLocalTimeDST;
this->isUtc = type == DateTimeTypeUTC;
this->isLocalTime = type != DateTimeTypeUTC;

// 2. after setting all values, handle hours out of range (e.g. negative!)
if (hour < 0 || 24 <= hour)
{
this->hour = 0;
addHours(hour);
}
}

DateTime::DateTime(time_t time, bool createUtc)
Expand Down
2 changes: 1 addition & 1 deletion src/OpenKNX/DateTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace OpenKNX
struct DateTime : public DateOnly, public TimeOnly
{
DateTime() = default;
DateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, DateTimeType type);
DateTime(uint16_t year, uint8_t month, uint8_t day, int32_t hour, uint8_t minute, uint8_t second, DateTimeType type);

DateTime(time_t time, bool createUtc = false);

Expand Down
27 changes: 18 additions & 9 deletions src/OpenKNX/Sun/SunCalculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,27 @@ namespace OpenKNX

double rise, set;
// sunrise/sunset calculation
// TODO check the return {<,=,>}0 for special cases
SunRiseAndSet::sunRiseSet(utc.year, utc.month, utc.day,
longitude, latitude, -35.0 / 60.0, 1, &rise, &set);

_sunRiseUtc.hour = (int)floor(rise);
_sunRiseUtc.minute = (int)(60 * (rise - floor(rise)));
_sunRiseUtc.second = 0;
_sunRiseLocalTime = DateTime(utc.year, utc.month, utc.day, _sunRiseUtc.hour, _sunRiseUtc.minute, _sunRiseUtc.second, DateTimeTypeUTC).toLocalTime();
const int32_t sunRiseUtcHour = (int32_t)floor(rise);
const uint8_t sunRiseUtcMinute = (int32_t)(60 * (rise - floor(rise)));
const uint8_t sunRiseUtcSecond = 0;
DateTime dtRise = DateTime(utc.year, utc.month, utc.day, sunRiseUtcHour, sunRiseUtcMinute, sunRiseUtcSecond, DateTimeTypeUTC);
_sunRiseUtc.hour = dtRise.hour;
_sunRiseUtc.minute = dtRise.minute;
_sunRiseUtc.second = dtRise.second;
_sunRiseLocalTime = dtRise.toLocalTime();

_sunSetUtc.hour = (int)floor(set);
_sunSetUtc.minute = (int)(60 * (set - floor(set)));
_sunSetUtc.second = 0;
_sunSetLocalTime = DateTime(utc.year, utc.month, utc.day, _sunSetUtc.hour, _sunSetUtc.minute, _sunSetUtc.second, DateTimeTypeUTC).toLocalTime();
const int32_t sunSetUtcHour = (int32_t)floor(set);
const uint8_t sunSetUtcMinute = (int32_t)(60 * (set - floor(set)));
const uint8_t sunSetUtcSecond = 0;
DateTime dtSet = DateTime(utc.year, utc.month, utc.day, sunSetUtcHour, sunSetUtcMinute, sunSetUtcSecond, DateTimeTypeUTC);
_sunSetUtc.hour = dtSet.hour;
_sunSetUtc.minute = dtSet.minute;
_sunSetUtc.second = dtSet.second;
_sunSetLocalTime = dtSet.toLocalTime();

_sunCalculationValid = true;
}
Expand Down Expand Up @@ -116,4 +125,4 @@ namespace OpenKNX
} // namespace Sun
} // namespace OpenKNX

#endif
#endif
Loading