diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/timedate.cpp | 33 | ||||
| -rw-r--r-- | src/timedate.h | 5 |
2 files changed, 34 insertions, 4 deletions
diff --git a/src/timedate.cpp b/src/timedate.cpp index 42bacf6..e6ec83f 100644 --- a/src/timedate.cpp +++ b/src/timedate.cpp @@ -125,9 +125,13 @@ static void slack_get_property(Glib::VariantBase& result, const Glib::RefPtr<Gio { result = Glib::Variant<bool>::create(dlackware::timedate::ntp_synchronized()); } - else if (prop_name == "TimeUSecRTC") + else if (prop_name == "TimeUSec") { - result = Glib::Variant<std::uint64_t>::create(dlackware::timedate::time_usec_rtc()); + result = Glib::Variant<std::uint64_t>::create(dlackware::timedate::time_usec()); + } + else if (prop_name == "RTCTimeUSec") + { + result = Glib::Variant<std::uint64_t>::create(dlackware::timedate::rtc_time_usec()); } } @@ -338,7 +342,30 @@ namespace dlackware::timedate return ntp_result != TIME_ERROR && (buffer.status & STA_UNSYNC) == 0; } - std::uint64_t time_usec_rtc() + std::uint64_t time_usec() + { + timespec spec; + + if (clock_gettime(CLOCK_REALTIME, &spec) == -1) + { + throw std::system_error(errno, std::generic_category()); + } + time_t seconds = spec.tv_sec; + tm time; + + if (local_rtc()) + { + gmtime_r(&seconds, &time); + } + else + { + localtime_r(&seconds, &time); + } + return std::chrono::duration_cast<std::chrono::microseconds>( + std::chrono::seconds(std::mktime(&time)) + std::chrono::nanoseconds(spec.tv_nsec)).count(); + } + + std::uint64_t rtc_time_usec() { return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::system_clock::now().time_since_epoch()).count(); diff --git a/src/timedate.h b/src/timedate.h index 952209c..1c33594 100644 --- a/src/timedate.h +++ b/src/timedate.h @@ -44,7 +44,10 @@ namespace dlackware::timedate bool ntp_synchronized(); // Shows the current time in the RTC. - std::uint64_t time_usec_rtc(); + std::uint64_t rtc_time_usec(); + + // Shows the current time on the system. + std::uint64_t time_usec(); // Returns the timezones available on the system. std::vector<Glib::ustring> list_timezones(); |
