struct tm parsed_time;
//"%Y-%m-%d %H:%M:%S"
//"%F %T"
- parse_end = strptime("%F %T", "%Y-%m-%d %H:%M:%S", &parsed_time);
+ parse_end = strptime(str, "%F %T", &parsed_time);
if(parse_end == NULL) {
return mp_printf(pool, "Invalid value of timestamp: '%s'.", str);
}
static u64 timestamp_parsed[] = {
1403685533,
- 1403685533,
+ 1403678333,
};
struct mempool *pool = mp_new(4096);
while(timestamp_strs[i]) {
u64 result;
- const char *err_str = xt_size.parse(timestamp_strs[i], &result, pool);
+ const char *err_str = xt_timestamp.parse(timestamp_strs[i], &result, pool);
ASSERT_MSG(err_str == NULL, "Unexpected error in xt_size.parse: %s", err_str);
ASSERT_MSG(timestamp_parsed[i] == result, "Expected: %" PRIu64 " but got %" PRIu64, timestamp_parsed[i], result);
bprintf(out, "%" PRIu64 " %" PRIu64 "\n", timestamp_parsed[i], result);
mp_delete(pool);
}
-static void test_timestamp_parse_errors(struct fastbuf *out UNUSED)
+static void test_timestamp_parse_errors(struct fastbuf *out)
{
static const char *timestamp_strs[] = {
"1403685533X",
while(timestamp_strs[i]) {
u64 result;
- const char *err_str = xt_size.parse(timestamp_strs[i], &result, pool);
+ const char *err_str = xt_timestamp.parse(timestamp_strs[i], &result, pool);
if(err_str == NULL) {
bprintf(out, "xt_timestamp.parse incorrectly did not result in error while parsing: '%s'.\n", timestamp_strs[i]);
test_size_parse_errors(out);
test_bool_parse_correct(out);
test_timestamp_parse_correct(out);
+ test_timestamp_parse_errors(out);
bclose(out);
return 0;
1 true
false false
true true
+1403685533 1403685533
+1403678333 1403678333
+xt_timestamp.parse error: 'Invalid value of timestamp: '1403685533X'.'.
+xt_timestamp.parse error: 'Invalid value of timestamp: '2014X-06-25 08:38:53'.'.
+xt_timestamp.parse error: 'Invalid value of timestamp: '2X014-06-25 08:38:53'.'.
+xt_timestamp.parse error: 'Invalid value of timestamp: 'X1403685533'.'.
EOF