From 3f3a54c611fd02c2429300c6e8853c6275c41930 Mon Sep 17 00:00:00 2001 From: Dennis Bonke Date: Mon, 10 Jun 2024 13:04:23 +0200 Subject: [PATCH] options/ansi: Implement %E in strftime --- options/ansi/generic/time-stubs.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/options/ansi/generic/time-stubs.cpp b/options/ansi/generic/time-stubs.cpp index 798d08c536..1e896cf93a 100644 --- a/options/ansi/generic/time-stubs.cpp +++ b/options/ansi/generic/time-stubs.cpp @@ -94,6 +94,7 @@ size_t strftime(char *__restrict dest, size_t max_size, auto c = format; auto p = dest; [[maybe_unused]] bool use_alternative_symbols = false; + [[maybe_unused]] bool use_alternative_era_format = false; while(*c) { int chunk; @@ -124,6 +125,21 @@ size_t strftime(char *__restrict dest, size_t max_size, c++; continue; } + } else if(*(c + 1) == 'E') { + std::array valid{{'c', 'C', 'x', 'X', 'y', 'Y'}}; + auto next = *(c + 2); + if(std::find(valid.begin(), valid.end(), next) != valid.end()) { + use_alternative_era_format = true; + c++; + } else { + *p = '%'; + p++; + c++; + *p = 'E'; + p++; + c++; + continue; + } } switch(*++c) {