mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
- remove common lib - split settings, remove common-md - move ipc interop/kb_layout to interop - rename core -> settings, settings -> old_settings - os-detect header-only; interop -> PowerToysInterop - split notifications, move single-use headers where they're used - winstore lib - rename com utils - rename Updating and Telemetry projects - rename core -> settings-ui and remove examples folder - rename settings-ui folder + consisent common/version include
58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <ctime>
|
|
#include <cinttypes>
|
|
#include <string>
|
|
#include <optional>
|
|
|
|
#include <winrt/base.h>
|
|
|
|
namespace timeutil
|
|
{
|
|
inline std::wstring to_string(const time_t time)
|
|
{
|
|
return std::to_wstring(static_cast<uint64_t>(time));
|
|
}
|
|
|
|
inline std::optional<std::time_t> from_string(const std::wstring& s)
|
|
{
|
|
try
|
|
{
|
|
uint64_t i = std::stoull(s);
|
|
return static_cast<std::time_t>(i);
|
|
}
|
|
catch (...)
|
|
{
|
|
return std::nullopt;
|
|
}
|
|
}
|
|
|
|
inline std::time_t now()
|
|
{
|
|
return winrt::clock::to_time_t(winrt::clock::now());
|
|
}
|
|
|
|
namespace diff
|
|
{
|
|
inline int64_t in_seconds(const std::time_t to, const std::time_t from)
|
|
{
|
|
return static_cast<int64_t>(std::difftime(to, from));
|
|
}
|
|
|
|
inline int64_t in_minutes(const std::time_t to, const std::time_t from)
|
|
{
|
|
return static_cast<int64_t>(std::difftime(to, from) / 60);
|
|
}
|
|
|
|
inline int64_t in_hours(const std::time_t to, const std::time_t from)
|
|
{
|
|
return static_cast<int64_t>(std::difftime(to, from) / 3600);
|
|
}
|
|
|
|
inline int64_t in_days(const std::time_t to, const std::time_t from)
|
|
{
|
|
return static_cast<int64_t>(std::difftime(to, from) / (3600 * (int64_t)24));
|
|
}
|
|
}
|
|
}
|