Skip to content

Commit

Permalink
Merge pull request #478 from bazsi/strptime-percentf-skips-optional-dot
Browse files Browse the repository at this point in the history
wallclocktime: optionally skip the leading dot in strptime(%f) parsing
  • Loading branch information
MrAnno authored Jan 29, 2025
2 parents f209cab + 65bd0ac commit 52eacd5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/timeutils/tests/test_wallclocktime.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ Test(wallclocktime, test_strptime_parses_broken_down_time)
cr_expect(wct.wct_gmtoff == -1);
}

Test(wallclocktime, test_strptime_percentf_skips_optional_dot)
{
WallClockTime wct = WALL_CLOCK_TIME_INIT;
gchar *end;

end = wall_clock_time_strptime(&wct, "%b %d %Y %H:%M:%S%f", "Jan 16 2019 18:23:12.012345");
cr_assert(*end == 0);
cr_expect(wct.wct_year == 119);
cr_expect(wct.wct_mon == 0);
cr_expect(wct.wct_mday == 16);

cr_expect(wct.wct_hour == 18);
cr_expect(wct.wct_min == 23);
cr_expect(wct.wct_sec == 12);
cr_expect(wct.wct_usec == 12345);

cr_expect(wct.wct_gmtoff == -1);
}

Test(wallclocktime, test_strptime_parses_truncated_usec)
{
WallClockTime wct = WALL_CLOCK_TIME_INIT;
Expand Down
2 changes: 2 additions & 0 deletions lib/timeutils/wallclocktime.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ wall_clock_time_strptime(WallClockTime *wct, const gchar *format, const gchar *i

case 'f':
{
if (*bp == '.')
bp++;
const unsigned char *end = conv_num(bp, &wct->wct_usec, 0, 999999);
if (!end)
return NULL;
Expand Down

0 comments on commit 52eacd5

Please sign in to comment.