This commit is contained in:
parent
b11e18e560
commit
d75053b243
@ -7,7 +7,8 @@
|
||||
<property name="NTP" type="b" access="read"/>
|
||||
<property name="CanNTP" type="b" access="read"/>
|
||||
<property name="NTPSynchronized" type="b" access="read"/>
|
||||
<property name="TimeUSecRTC" type="t" access="read"/>
|
||||
<property name="TimeUSec" type="t" access="read"/>
|
||||
<property name="RTCTimeUSec" type="t" access="read"/>
|
||||
<method name="SetTime">
|
||||
<arg name="usec_utc" type="x" direction="in"/>
|
||||
<arg name="relative" type="b" direction="in"/>
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user