-
Notifications
You must be signed in to change notification settings - Fork 0
/
testDateConversionFormat.cpp
50 lines (36 loc) · 1.8 KB
/
testDateConversionFormat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// test conversions for 'Date'
#include <iostream>
#include <converter/converter.h>
#include "unittest.h"
constexpr char dmY_fmt[] = "%d-%m-%Y"; // string literal object with static storage duration
namespace chr = std::chrono;
constexpr chr::year_month_day (*ToVal_dmY)(const std::string& str) =
&converter::ConvertFromStr< chr::year_month_day,
converter::S2T_Format_StreamYMD< dmY_fmt >
>::ToVal;
constexpr std::string (*FromStr_dmY)(const chr::year_month_day& val) =
&converter::ConvertFromVal< chr::year_month_day,
converter::T2S_Format_StreamYMD< dmY_fmt >
>::ToStr;
int main()
{
int rv = 0;
try {
unittest::ExpectEqual(chr::year_month_day,
ToVal_dmY("27-12-2020"),
chr::year_month_day{chr::year{2020} COMMA chr::month{12} COMMA chr::day{27} });
unittest::ExpectEqual(std::string,
FromStr_dmY( chr::year_month_day{chr::year{1980} COMMA chr::month{2} COMMA chr::day{28} } ),
"28-02-1980");
unittest::ExpectEqual(chr::year_month_day,
converter::fromStr_dbY("27-Dec-2020"),
chr::year_month_day{chr::year{2020} COMMA chr::month{12} COMMA chr::day{27} });
unittest::ExpectEqual(std::string,
converter::toStr_dbY( chr::year_month_day{chr::year{1980} COMMA chr::month{2} COMMA chr::day{28} } ),
"28-Feb-1980");
} catch (const std::exception& ex) {
std::cout << "Unexpected exception in testDateConversionFormat: " << ex.what() << std::endl;
rv = 1;
}
return rv;
}