mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
runner: periodically check if there's a new version available on github and offer a visit
This commit is contained in:
committed by
Andrey Nekrasov
parent
c543b7585a
commit
0016836022
57
src/common/timeutil.h
Normal file
57
src/common/timeutil.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#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 * 24));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user