From: Stuart Henderson Subject: Re: newsyslog: refactor ISO-8601 parser To: Jan Klemkow Cc: tech@openbsd.org Date: Sun, 14 Sep 2025 18:39:24 +0100 On 2025/09/14 14:57, Jan Klemkow wrote: > ping? > > On Tue, Aug 12, 2025 at 06:29:56PM +0200, Jan Klemkow wrote: > > ping? > > > > On Fri, Jul 25, 2025 at 07:31:47PM +0200, Jan Klemkow wrote: > > > The following diff replaces the internals of parse8601() by an > > > equivalent call of strptime(3) to parse the time string. > > > > > > The only functional difference is the 2-digit year handling: > > > Values in the range 69-99 refer to years 1969 to 1999 and > > > values in the range 00-68 refer to years 2000 to 2068. > > > In the old version, 69-99 also refer to the 2069 to 2099 range. I think this approach makes sense, having fewer places in the tree where we might need to update 2-digit year handling in the future is useful. > > > + if (s != t) { > > > + switch (t == NULL ? strlen(s) : t - s) { > > > + case 8: strlcat(format, "%C", sizeof format); > > > + case 6: strlcat(format, "%y", sizeof format); > > > + case 4: strlcat(format, "%m", sizeof format); > > > + case 2: strlcat(format, "%d", sizeof format); > > > case 0: style(9) asks for /* FALLTHROUGH */ comments and I think that makes sense. otherwise ok > > > break; > > > default: > > > - return (-1); > > > + return -1; > > > } > > > + } > > > > > > - /* sanity check */ > > > - if (tm.tm_sec < 0 || tm.tm_sec > 60 || tm.tm_min < 0 || > > > - tm.tm_min > 59 || tm.tm_hour < 0 || tm.tm_hour > 23) > > > - return (-1); > > > + if (t != NULL) { > > > + strlcat(format, "T", sizeof format); > > > + > > > + switch (strlen(t)) { > > > + case 7: strlcat(format, "%H", sizeof format); > > > + case 5: strlcat(format, "%M", sizeof format); > > > + case 3: strlcat(format, "%S", sizeof format); > > > + case 1: > > > + break; > > > + default: > > > + return -1; > > > + } > > > } > > > - return (mktime(&tm)); > > > + > > > + if (strptime(s, format, tm) == NULL) > > > + return -1; > > > + > > > + return mktime(tm); > > > } > > > > > > /*- > > > > > >