Updated to new esp-idf

This commit is contained in:
2023-02-27 17:27:04 +01:00
parent 8a44b1ecf7
commit 32bdd0911d
6 changed files with 15 additions and 16 deletions

View File

@ -13,7 +13,6 @@ set(dependencies
cpputils
date
expected
fmt
)

View File

@ -187,7 +187,7 @@ LocalDateTime toDateTime(local_clock::time_point ts)
return dateTime;
}
tl::expected<DateTime, std::string> parseDateTime(std::string_view str)
std::expected<DateTime, std::string> parseDateTime(std::string_view str)
{
// both valid:
// 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";
if (const auto scanned = std::sscanf(str.data(), dateTimeFormat, &year, &month, &day, &hour, &minute, &second, &millisecond, &microsecond); scanned < 5)
return tl::make_unexpected(fmt::format("invalid DateTime ({})", str));
return std::unexpected(fmt::format("invalid DateTime ({})", str));
return DateTime{
.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{};
constexpr auto daypointFormat = "%2hhd:%2hhd:%2hhd";
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)
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};
}

View File

@ -12,10 +12,10 @@
#include <string>
#include <string_view>
#include <type_traits>
#include <expected>
// 3rdparty lib includes
#include <date/date.h>
#include <tl/expected.hpp>
// local includes
#include "cpptypesafeenum.h"
@ -193,9 +193,9 @@ local_clock::time_point utcToLocal(utc_clock::time_point ts);
DateTime toDateTime(utc_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);

View File

@ -76,7 +76,7 @@ char *toString(const espchrono::seconds32 &val)
}
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)");
}

View File

@ -25,7 +25,7 @@ Q_DECLARE_METATYPE(espchrono::utc_clock::time_point)
Q_DECLARE_METATYPE(espchrono::local_clock::time_point)
Q_DECLARE_METATYPE(espchrono::DateTime)
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)
extern const espchrono::time_zone testTimeZone;
@ -85,5 +85,5 @@ template<>
char *toString(const espchrono::seconds32 &val);
template<>
char *toString(const tl::expected<espchrono::seconds32, std::string> &val);
char *toString(const std::expected<espchrono::seconds32, std::string> &val);
} // namespace QTest

View File

@ -227,13 +227,13 @@ private slots:
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<result_t>("expected");
QTest::addRow("bullshit") << "bullshit"s << result_t{tl::make_unexpected("invalid daypoint (bullshit)")};
QTest::addRow("missing_minute") << "00:"s << result_t{tl::make_unexpected("invalid daypoint (00:)")};
QTest::addRow("bullshit") << "bullshit"s << result_t{std::unexpected("invalid daypoint (bullshit)")};
QTest::addRow("missing_minute") << "00:"s << result_t{std::unexpected("invalid daypoint (00:)")};
QTest::addRow("zero") << "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};
@ -244,7 +244,7 @@ private slots:
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(result_t, expected);