mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:30:05 +00:00
QDate::toStdSysDays is needlessly behind __cpp_lib_chrono >= 201907L
This commit is contained in:
parent
1479525c4a
commit
5a078800e4
4 changed files with 56 additions and 4 deletions
24
scwx-qt/source/scwx/qt/util/time.cpp
Normal file
24
scwx-qt/source/scwx/qt/util/time.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include <scwx/qt/util/time.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
std::chrono::sys_days SysDays(const QDate& date)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using sys_days = time_point<system_clock, days>;
|
||||
constexpr auto julianEpoch = sys_days {-4713y / November / 24d};
|
||||
constexpr auto unixEpoch = sys_days {1970y / January / 1d};
|
||||
constexpr auto offset = std::chrono::days(julianEpoch - unixEpoch);
|
||||
|
||||
return std::chrono::sys_days(std::chrono::days(date.toJulianDay()) +
|
||||
julianEpoch);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
25
scwx-qt/source/scwx/qt/util/time.hpp
Normal file
25
scwx-qt/source/scwx/qt/util/time.hpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Convert QDate to std::chrono::sys_days.
|
||||
*
|
||||
* @param [in] date Date to convert
|
||||
*
|
||||
* @return Days
|
||||
*/
|
||||
std::chrono::sys_days SysDays(const QDate& date);
|
||||
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue