Refactor clock format to wxdata

This commit is contained in:
Dan Paulat 2024-03-29 00:26:52 -05:00
parent bb287dad9c
commit a7cb459e20
6 changed files with 42 additions and 33 deletions

View file

@ -1,7 +1,10 @@
#pragma once
#include <scwx/util/iterator.hpp>
#include <chrono>
#include <optional>
#include <string>
#if !defined(_MSC_VER)
# include <date/tz.h>
@ -18,6 +21,19 @@ typedef std::chrono::time_zone time_zone;
typedef date::time_zone time_zone;
#endif
enum class ClockFormat
{
_12Hour,
_24Hour,
Unknown
};
typedef scwx::util::
Iterator<ClockFormat, ClockFormat::_12Hour, ClockFormat::_24Hour>
ClockFormatIterator;
ClockFormat GetClockFormat(const std::string& name);
const std::string& GetClockFormatName(ClockFormat clockFormat);
std::chrono::system_clock::time_point TimePoint(uint32_t modifiedJulianDate,
uint32_t milliseconds);

View file

@ -9,8 +9,12 @@
#endif
#include <scwx/util/time.hpp>
#include <scwx/util/enum.hpp>
#include <sstream>
#include <unordered_map>
#include <boost/algorithm/string.hpp>
#if !defined(_MSC_VER)
# include <date/date.h>
@ -21,6 +25,18 @@ namespace scwx
namespace util
{
static const std::unordered_map<ClockFormat, std::string> clockFormatName_ {
{ClockFormat::_12Hour, "12-hour"},
{ClockFormat::_24Hour, "24-hour"},
{ClockFormat::Unknown, "?"}};
SCWX_GET_ENUM(ClockFormat, GetClockFormat, clockFormatName_)
const std::string& GetClockFormatName(ClockFormat clockFormat)
{
return clockFormatName_.at(clockFormat);
}
std::chrono::system_clock::time_point TimePoint(uint32_t modifiedJulianDate,
uint32_t milliseconds)
{