Skip to content

Commit

Permalink
strptime: add basic support for '%s' (seconds since epoch)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtzWill committed Jul 15, 2018
1 parent 9cad27a commit 8cc60ad
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/time/strptime.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <stddef.h>
#include <string.h>
#include <strings.h>
#include "time_impl.h"

struct tm *__localtime_r(const time_t *restrict, struct tm *restrict);

char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm)
{
Expand Down Expand Up @@ -119,6 +122,15 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
min = 0;
range = 61;
goto numeric_range;
case 's':
if (!isdigit(*s)) return 0;
else {
char *new_s;
time_t t = strtoull(s, &new_s, 10);
s = new_s;
if (!__localtime_r(&t, tm)) return 0;
}
break;
case 'T':
s = strptime(s, "%H:%M:%S", tm);
if (!s) return 0;
Expand Down

0 comments on commit 8cc60ad

Please sign in to comment.