Fix setting the clock by one hour back
All checks were successful
Build / build (push) Successful in 17s
All checks were successful
Build / build (push) Successful in 17s
This commit is contained in:
parent
8bf3a92cbc
commit
78f9939afc
@ -161,9 +161,6 @@ static void slack_get_property(Glib::VariantBase& result, const Glib::RefPtr<Gio
|
||||
|
||||
namespace dlackware::timedate
|
||||
{
|
||||
constexpr const std::uint64_t usec_per_sec = 1000000ULL;
|
||||
constexpr const std::uint64_t nsec_per_usec = 1000ULL;
|
||||
|
||||
timedate1::timedate1()
|
||||
: interface_vtable{ &slack_method_call, &slack_get_property }
|
||||
{
|
||||
@ -279,30 +276,26 @@ namespace dlackware::timedate
|
||||
}
|
||||
}
|
||||
|
||||
void set_time(std::int64_t seconds_since_epoch, bool relative, bool)
|
||||
void set_time(std::int64_t usec_utc, bool relative, bool)
|
||||
{
|
||||
timespec ts;
|
||||
std::chrono::system_clock::duration current_time_since_epoch;
|
||||
|
||||
if (relative)
|
||||
{
|
||||
if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
|
||||
{
|
||||
throw std::system_error(errno, std::generic_category());
|
||||
}
|
||||
ts.tv_sec += static_cast<time_t>(seconds_since_epoch / dlackware::timedate::usec_per_sec);
|
||||
ts.tv_nsec += (seconds_since_epoch % dlackware::timedate::usec_per_sec) * dlackware::timedate::nsec_per_usec;
|
||||
|
||||
if (ts.tv_nsec < 0)
|
||||
{
|
||||
--ts.tv_sec;
|
||||
ts.tv_nsec += dlackware::timedate::usec_per_sec;
|
||||
}
|
||||
current_time_since_epoch = std::chrono::system_clock::now().time_since_epoch();
|
||||
current_time_since_epoch += std::chrono::microseconds(usec_utc);
|
||||
}
|
||||
else
|
||||
{
|
||||
ts.tv_sec = static_cast<time_t>(seconds_since_epoch / dlackware::timedate::usec_per_sec);
|
||||
ts.tv_nsec = (seconds_since_epoch % dlackware::timedate::usec_per_sec) * dlackware::timedate::nsec_per_usec;
|
||||
current_time_since_epoch = std::chrono::microseconds(usec_utc);
|
||||
}
|
||||
auto seconds_since_epoch = std::chrono::floor<std::chrono::seconds>(current_time_since_epoch);
|
||||
|
||||
ts.tv_sec = seconds_since_epoch.count();
|
||||
ts.tv_nsec = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
current_time_since_epoch - seconds_since_epoch).count();
|
||||
|
||||
if (clock_settime(CLOCK_REALTIME, &ts) == -1)
|
||||
{
|
||||
throw std::system_error(errno, std::generic_category());
|
||||
|
@ -63,7 +63,7 @@ namespace dlackware::timedate
|
||||
// Changes the date/time
|
||||
// Takes the amount of seconds since UNIX epoche and
|
||||
// Throws std::system_error.
|
||||
void set_time(std::int64_t seconds_since_epoch, bool relative, bool user_interaction);
|
||||
void set_time(std::int64_t usec_utc, bool relative, bool user_interaction);
|
||||
|
||||
// Controls whether the RTC is local time or UTC.
|
||||
void set_local_rtc(bool local_rtc, bool fix_system, bool user_interaction);
|
||||
|
Loading…
Reference in New Issue
Block a user