Skip to content

Commit

Permalink
Fixed date format and some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fuersten committed Aug 22, 2024
1 parent 03ccbce commit 4021ec2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions include/rexsapi/Types.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
#if ((__cplusplus >= 202002L || _MSVC_LANG >= 202002L) && !defined(__APPLE__))
#include <chrono>
namespace rexs_date = std::chrono;
namespace rexs_format = std;
#else
#include <date/date.h>
namespace rexs_date = date;
namespace rexs_format = date;
#endif
#include <sstream>
#include <vector>
Expand Down Expand Up @@ -211,7 +209,8 @@ namespace rexsapi
/**
* @brief Construct a new TDatetime object from a string.
*
* @param datetime The string has to be in ISO8601 format `yyyy-mm-ddThh:mm:ss[+/-]<offset to UTC>`
* @param datetime The string has to be in ISO8601 format `yyyy-mm-ddThh:mm:ss[+/-]<offset to UTC>`.
The offset requires a : between hours and minutes.
* @throws std::exception if the string cannot be parsed or the date time is invalid
*/
explicit TDatetime(const std::string& datetime)
Expand Down Expand Up @@ -257,7 +256,11 @@ namespace rexsapi
*/
inline std::string asUTCString() const
{
return rexs_format::format("%FT%T%Ez", m_Timepoint);
#if ((__cplusplus >= 202002L || _MSVC_LANG >= 202002L) && !defined(__APPLE__))
return std::format("{:%FT%T%Ez}", m_Timepoint);
#else
return date::format("%FT%T%Ez", m_Timepoint);
#endif
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/JsonValueDecoderTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ TEST_CASE("Json value decoder error test")
"enum": { "enum": "unknown enum" },
"reference component": { "reference_component": "PR" },
"file reference": { "file_reference": 4711 },
"date time": { "date_time": "2023-02-31T11:11:11+00:00" },
"date time": { "date_time": "2023-02-31T11:11+00:00" },
"float array": { "floating_point_array": ["a", "b", "c"] },
"integer array": { "integer_array": ["a", "b", "c"] },
"boolean array": { "boolean_array": ["true", "false", "false"] },
Expand Down
2 changes: 1 addition & 1 deletion test/TypesTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,6 @@ TEST_CASE("Datetime test")

SUBCASE("Illegal date")
{
CHECK_THROWS(rexsapi::TDatetime{"2023-02-31T13:49:36+02:00"});
CHECK_THROWS(rexsapi::TDatetime{"2023-02T13:49:36+02:00"});
}
}
2 changes: 1 addition & 1 deletion test/XMLValueDecoderTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ TEST_CASE("XML value decoder error test")
<attribute id="string"></attribute>
<attribute id="enum">unknown enum</attribute>
<attribute id="reference component">PR</attribute>
<attribute id="date time">2022-02-30T08:50:27+02:00</attribute>
<attribute id="date time">2022-30T08:50:27+02:00</attribute>
<attribute id="integer array">
<array>
<c>1.1</c>
Expand Down

0 comments on commit 4021ec2

Please sign in to comment.