The doc says that the String
variable InAppPurchases::Purchase::purchaseTime
contains the date in ISO-8601 format, which I expect would be 2023-10-25 hh:mm:ss.000 for the date of today, so I expect to convert it to a Time
object with Time::fromISO8601()
but this is not the case, because the string set into the variable reads “25 Oct 2023 …” (adds hhmmss).
Just so the posterity will not be disappointed… this is a function to parse the literal date:
Time stringEnglishDateToTime(const String& dateTime)
{
static const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
auto blocks = StringArray::fromTokens(dateTime, " ", " ");
if (blocks.size() < 3) return Time();
int day = blocks[0].getIntValue();
int month = 0;
int year = blocks[2].getIntValue();
for (int m = 0; m < 12; m++) if (blocks[1].containsIgnoreCase(shortMonthNames[m])) month = m;
return Time(year, month, day, 0, 0);
}
I guess it’s not easy to handle dates because… what will happen when a big chinese corporation will acquire Apple and will change all basecode in chinese language?