I'm trying to use the ICU library to convert a time stamp from a string to a time_t value.
To do so, I though all I had to do is create a time instance and call its parse()
function. Unfortunately, all I get is a U_ILLEGAL_ARGUMENT_ERROR from the parser.
There is a simplified version of the code that shows the unexpected behavior:
#include <iostream>
#include <unicode/datefmt.h>
#include <unicode/errorcode.h>
#include <unicode/locid.h>
#include <unicode/smpdtfmt.h>
#include <unicode/timezone.h>
int main(int argc, char *argv[])
{
LocalPointer<DateFormat> dt(DateFormat::createTimeInstance());
UErrorCode err(U_ZERO_ERROR);
UDate const result(dt->parse("12:05:33", err));
std::cerr << "*** err = " << u_errorName(err)
<< " and result = " << result << "\n";
return 0;
}
When I run this, the output is
*** err = U_ILLEGAL_ARGUMENT_ERROR and result = 0
I was expecting something more like a representation of the time such as 12 x 3600 + 5 * 60 + 33 = 43533.
Am I doing something wrong? From the documentation, it looks like the library is capable of converting various types of time stamps.