I thought the default output of date(1), with TZ unset, is something like
Mon Jan 20 06:07:07 UTC 2025
You could use `"%a %b %d %H:%M:%S %Z %Y"` for `fmt` (which is indeed the default for `date`) and it would work with yours.
Both results in the same timestamp.
date.l:
int fileno (FILE *); FILE *f; int printf(const char *__restrict, ...); #include <time.h> char *strptime(const char *s, const char *f, struct tm *tm); struct tm t; a (Mon|Tue|Wed|Thu|Fri|Sat|Sun) b (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) d [0-2][0-9]|3[01] H [0-2][0-9] M [0-5][0-9] S [0-5][0-9] Y [1-9][0-9][0-9][0-9] %option nounput noinput noyywrap %% {a}[ ]{b}[ ]{d}[ ]{H}:{M}:{S}[ ]UTC[ ]{Y} { strptime(yytext,"%a %b %d %H:%M:%S UTC %Y",&t); printf("%ld\n",mktime(&t)); } .|\n %% int main(){yylex();exit(0);} flex -8Cem date.l cc -O3 -std=c89 -W -Wall -pipe lex.yy.c -static -s -o yydate date|yydate
But if I substitute %Z or %z for "UTC" in strptime() above then this does not work.
Fun fact: strptime() can make timestamps for dates that do not exist on any calandar.
echo "Thu Jun 31 01:59:26 UTC 2024"|yydate
You could use `"%a %b %d %H:%M:%S %Z %Y"` for `fmt` (which is indeed the default for `date`) and it would work with yours.
Both results in the same timestamp.