Updated to new esp-idf
This commit is contained in:
@ -13,7 +13,6 @@ set(dependencies
|
|||||||
|
|
||||||
cpputils
|
cpputils
|
||||||
date
|
date
|
||||||
expected
|
|
||||||
fmt
|
fmt
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ LocalDateTime toDateTime(local_clock::time_point ts)
|
|||||||
return dateTime;
|
return dateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
tl::expected<DateTime, std::string> parseDateTime(std::string_view str)
|
std::expected<DateTime, std::string> parseDateTime(std::string_view str)
|
||||||
{
|
{
|
||||||
// both valid:
|
// both valid:
|
||||||
// 2020-11-10T21:31
|
// 2020-11-10T21:31
|
||||||
@ -206,7 +206,7 @@ tl::expected<DateTime, std::string> parseDateTime(std::string_view str)
|
|||||||
|
|
||||||
constexpr auto dateTimeFormat = "%4d-%2u-%2uT%2hhu:%2hhu:%2hhu.%3hu.%3hu";
|
constexpr auto dateTimeFormat = "%4d-%2u-%2uT%2hhu:%2hhu:%2hhu.%3hu.%3hu";
|
||||||
if (const auto scanned = std::sscanf(str.data(), dateTimeFormat, &year, &month, &day, &hour, &minute, &second, &millisecond, µsecond); scanned < 5)
|
if (const auto scanned = std::sscanf(str.data(), dateTimeFormat, &year, &month, &day, &hour, &minute, &second, &millisecond, µsecond); scanned < 5)
|
||||||
return tl::make_unexpected(fmt::format("invalid DateTime ({})", str));
|
return std::unexpected(fmt::format("invalid DateTime ({})", str));
|
||||||
|
|
||||||
return DateTime{
|
return DateTime{
|
||||||
.date=date::year_month_day{date::year{year}, date::month{month}, date::day{day}},
|
.date=date::year_month_day{date::year{year}, date::month{month}, date::day{day}},
|
||||||
@ -218,16 +218,16 @@ tl::expected<DateTime, std::string> parseDateTime(std::string_view str)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
tl::expected<std::chrono::seconds, std::string> parseDaypoint(std::string_view str)
|
std::expected<std::chrono::seconds, std::string> parseDaypoint(std::string_view str)
|
||||||
{
|
{
|
||||||
int8_t hour, minute, second{};
|
int8_t hour, minute, second{};
|
||||||
|
|
||||||
constexpr auto daypointFormat = "%2hhd:%2hhd:%2hhd";
|
constexpr auto daypointFormat = "%2hhd:%2hhd:%2hhd";
|
||||||
if (const auto scanned = std::sscanf(str.data(), daypointFormat, &hour, &minute, &second); scanned < 2)
|
if (const auto scanned = std::sscanf(str.data(), daypointFormat, &hour, &minute, &second); scanned < 2)
|
||||||
return tl::make_unexpected(fmt::format("invalid daypoint ({})", str));
|
return std::unexpected(fmt::format("invalid daypoint ({})", str));
|
||||||
|
|
||||||
if (hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59)
|
if (hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59)
|
||||||
return tl::make_unexpected(fmt::format("invalid daypoint ({})", str));
|
return std::unexpected(fmt::format("invalid daypoint ({})", str));
|
||||||
|
|
||||||
return std::chrono::hours{hour} + std::chrono::minutes{minute} + std::chrono::seconds{second};
|
return std::chrono::hours{hour} + std::chrono::minutes{minute} + std::chrono::seconds{second};
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <expected>
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <date/date.h>
|
#include <date/date.h>
|
||||||
#include <tl/expected.hpp>
|
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "cpptypesafeenum.h"
|
#include "cpptypesafeenum.h"
|
||||||
@ -193,9 +193,9 @@ local_clock::time_point utcToLocal(utc_clock::time_point ts);
|
|||||||
DateTime toDateTime(utc_clock::time_point ts);
|
DateTime toDateTime(utc_clock::time_point ts);
|
||||||
LocalDateTime toDateTime(local_clock::time_point ts);
|
LocalDateTime toDateTime(local_clock::time_point ts);
|
||||||
|
|
||||||
tl::expected<DateTime, std::string> parseDateTime(std::string_view str);
|
std::expected<DateTime, std::string> parseDateTime(std::string_view str);
|
||||||
|
|
||||||
tl::expected<std::chrono::seconds, std::string> parseDaypoint(std::string_view str);
|
std::expected<std::chrono::seconds, std::string> parseDaypoint(std::string_view str);
|
||||||
|
|
||||||
std::string toString(const DateTime &dateTime);
|
std::string toString(const DateTime &dateTime);
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ char *toString(const espchrono::seconds32 &val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
char *toString(const tl::expected<espchrono::seconds32, std::string> &val)
|
char *toString(const std::expected<espchrono::seconds32, std::string> &val)
|
||||||
{
|
{
|
||||||
return val ? ::QTest::toString(*val) : ::QTest::toString("(invalid)");
|
return val ? ::QTest::toString(*val) : ::QTest::toString("(invalid)");
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ Q_DECLARE_METATYPE(espchrono::utc_clock::time_point)
|
|||||||
Q_DECLARE_METATYPE(espchrono::local_clock::time_point)
|
Q_DECLARE_METATYPE(espchrono::local_clock::time_point)
|
||||||
Q_DECLARE_METATYPE(espchrono::DateTime)
|
Q_DECLARE_METATYPE(espchrono::DateTime)
|
||||||
Q_DECLARE_METATYPE(espchrono::LocalDateTime)
|
Q_DECLARE_METATYPE(espchrono::LocalDateTime)
|
||||||
using X = tl::expected<espchrono::seconds32, std::string>;
|
using X = std::expected<espchrono::seconds32, std::string>;
|
||||||
Q_DECLARE_METATYPE(X)
|
Q_DECLARE_METATYPE(X)
|
||||||
|
|
||||||
extern const espchrono::time_zone testTimeZone;
|
extern const espchrono::time_zone testTimeZone;
|
||||||
@ -85,5 +85,5 @@ template<>
|
|||||||
char *toString(const espchrono::seconds32 &val);
|
char *toString(const espchrono::seconds32 &val);
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
char *toString(const tl::expected<espchrono::seconds32, std::string> &val);
|
char *toString(const std::expected<espchrono::seconds32, std::string> &val);
|
||||||
} // namespace QTest
|
} // namespace QTest
|
||||||
|
@ -227,13 +227,13 @@ private slots:
|
|||||||
|
|
||||||
void test_parseDaypoint_data()
|
void test_parseDaypoint_data()
|
||||||
{
|
{
|
||||||
using result_t = tl::expected<espchrono::seconds32, std::string>;
|
using result_t = std::expected<espchrono::seconds32, std::string>;
|
||||||
|
|
||||||
QTest::addColumn<std::string>("input");
|
QTest::addColumn<std::string>("input");
|
||||||
QTest::addColumn<result_t>("expected");
|
QTest::addColumn<result_t>("expected");
|
||||||
|
|
||||||
QTest::addRow("bullshit") << "bullshit"s << result_t{tl::make_unexpected("invalid daypoint (bullshit)")};
|
QTest::addRow("bullshit") << "bullshit"s << result_t{std::unexpected("invalid daypoint (bullshit)")};
|
||||||
QTest::addRow("missing_minute") << "00:"s << result_t{tl::make_unexpected("invalid daypoint (00:)")};
|
QTest::addRow("missing_minute") << "00:"s << result_t{std::unexpected("invalid daypoint (00:)")};
|
||||||
QTest::addRow("zero") << "00:00"s << result_t{0s};
|
QTest::addRow("zero") << "00:00"s << result_t{0s};
|
||||||
QTest::addRow("zero3") << "00:00:00"s << result_t{0s};
|
QTest::addRow("zero3") << "00:00:00"s << result_t{0s};
|
||||||
QTest::addRow("random") << "12:34:56"s << result_t{12h+34min+56s};
|
QTest::addRow("random") << "12:34:56"s << result_t{12h+34min+56s};
|
||||||
@ -244,7 +244,7 @@ private slots:
|
|||||||
|
|
||||||
void test_parseDaypoint()
|
void test_parseDaypoint()
|
||||||
{
|
{
|
||||||
using result_t = tl::expected<espchrono::seconds32, std::string>;
|
using result_t = std::expected<espchrono::seconds32, std::string>;
|
||||||
|
|
||||||
QFETCH(std::string, input);
|
QFETCH(std::string, input);
|
||||||
QFETCH(result_t, expected);
|
QFETCH(result_t, expected);
|
||||||
|
Reference in New Issue
Block a user