feat: add sunrise/sunset scheduling support#72
Open
BaigHack3rss wants to merge 3 commits into
Open
Conversation
- add NSunCalc helper that computes sunrise/sunset with NOAA formulas - extend ConfigManager with latitude/longitude options and SUN-based profile times - warn when two profiles share a clock slot and skip profiles with missing sun events Tests: Tested locally; Original features work, sunset works according to my knowledge, sunrise not tested (2:00 am right now)
Resolved conflicts in ConfigManager.cpp: - Preserved sunrise/sunset scheduling feature - Adopted upstream's graceful error handling (continue instead of RASSERT) - Combined both approaches for robust sun time computation
vaxerski
reviewed
May 8, 2026
| @@ -0,0 +1,116 @@ | |||
| #ifndef SUNCALC_HPP | |||
| #define SUNCALC_HPP | |||
Member
There was a problem hiding this comment.
please use #pragma once it's not 1978
| namespace NSunCalc { | ||
|
|
||
| struct SLocation { | ||
| double latitude; // degrees |
| static double calcSunEventUTC(int day, int month, int year, double latitude, double longitude, bool isSunrise); | ||
|
|
||
| // Shared constants | ||
| static constexpr double MINUTES_PER_HOUR = 60.0; |
Member
There was a problem hiding this comment.
no need to spit those into the hpp file they can stay in the cpp
| #include <limits> | ||
| #include <chrono> | ||
|
|
||
| namespace NSunCalc { |
Member
There was a problem hiding this comment.
no namespace xxx { in .cpp files. Prefix your methods with NSunCalc or using namespace NSunCalc.
| } | ||
|
|
||
| // ------------------ NOAA Core Functions ------------------ | ||
| // Based on NOAA solar position calculator reference implementation. |
Member
There was a problem hiding this comment.
what's the reference implementation? If it's GPL, we can't do that.
| const double timezoneHours = static_cast<double>(info.offset.count()) / SECONDS_PER_HOUR; | ||
| std::time_t nowT = std::chrono::system_clock::to_time_t(now); | ||
| std::tm localTm{}; | ||
| localtime_r(&nowT, &localTm); |
| result.reserve(keys.size()); | ||
|
|
||
| const double latitude = static_cast<double>(std::any_cast<Hyprlang::FLOAT>(m_config.getConfigValue("latitude"))); | ||
| const double longitude = static_cast<double>(std::any_cast<Hyprlang::FLOAT>(m_config.getConfigValue("longitude"))); |
| std::time_t tt = system_clock::to_time_t(shifted); | ||
|
|
||
| std::tm utc{}; | ||
| gmtime_r(&tt, &utc); |
Member
There was a problem hiding this comment.
isn't there an STL fn for this?
| int m = static_cast<int>(std::fmod(totalMinutes, MINUTES_PER_HOUR)); | ||
|
|
||
| char buf[6]; | ||
| std::snprintf(buf, sizeof(buf), "%02d:%02d", h, m); |
Member
There was a problem hiding this comment.
ew, ouch, no C allowed here. std::format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates
New Helper
Config Enhancements
latitudeandlongitudeoptionsBehavior Changes
Testing Notes