From 56dfe4554dceff86bff8e5b7d6608f2fa147c777 Mon Sep 17 00:00:00 2001 From: xanthospap Date: Fri, 3 May 2024 19:26:02 +0300 Subject: [PATCH] var --- src/datetime_io_core.cpp | 2 +- src/datetime_read.hpp | 10 +++++----- src/datetime_write.hpp | 16 ++++++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/datetime_io_core.cpp b/src/datetime_io_core.cpp index 2c6351c..a65222a 100644 --- a/src/datetime_io_core.cpp +++ b/src/datetime_io_core.cpp @@ -5,7 +5,7 @@ inline const char *skipws(const char *line) noexcept { const char *c = line; - while (*c && (*c == ' ' || *c == '/' || *c == '-' || *c == 'T' || *c == ':')) + while (*c && (*c == ' ' || *c == '/' || *c == '-' || *c == 'T' || *c == ':' || *c == '_')) ++c; return c; } diff --git a/src/datetime_read.hpp b/src/datetime_read.hpp index 7afe6d1..cb1eb63 100644 --- a/src/datetime_read.hpp +++ b/src/datetime_read.hpp @@ -20,7 +20,7 @@ template class ReadInDate {}; /** A Date parser expecting a Date-format of type YYYY:MM:DD * * The delimeter character (here denoted ':'), can actually be any character - * of: ' ', '/', '-', 'T' and ':', so that a date can be given as e.g. + * of: ' ', '/', '-', 'T', '_' and ':', so that a date can be given as e.g. * "2023:10:07", or * "2023/10/07", or * "2023 10 07", or @@ -64,7 +64,7 @@ template <> class ReadInDate { /** A Date parser expecting a Date-format of type DD:MM:YYYY * * The delimeter character (here denoted ':'), can actually be any character - * of: ' ', '/', '-', 'T' and ':', so that a date can be given as e.g. + * of: ' ', '/', '-', 'T', '_' and ':', so that a date can be given as e.g. * "07:10:2023" or * "07/10/2023" or * "07 10 2023" or @@ -109,7 +109,7 @@ template <> class ReadInDate { * Year * * The delimeter character (here denoted ':'), can actually be any character - * of: ' ', '/', '-', 'T' and ':', so that a date can be given as e.g. + * of: ' ', '/', '-', 'T', '_' and ':', so that a date can be given as e.g. * "2023:365" or * "2023-365" or * "2023/365" or @@ -164,7 +164,7 @@ class ReadInTime { /** A Time-Of-Day parser expecting a Time-format of type HHMMSS * * The delimeter character (here denoted ':'), can actually be any character - * of: ' ', '/', '-', 'T' and ':', so that a date can be given as e.g. + * of: ' ', '/', '-', 'T', '_' and ':', so that a date can be given as e.g. * "23:59:59", or * "23/59/59", or * "23T59T59", or @@ -216,7 +216,7 @@ class ReadInTime { /** A Time-Of-Day parser expecting a Time-format of type HHMMSS.SSSSSSS... * * The delimeter character (here denoted ':'), can actually be any character - * of: ' ', '/', '-', 'T' and ':', so that a date can be given as e.g. + * of: ' ', '/', '-', 'T', '_' and ':', so that a date can be given as e.g. * "23:59:59.012345678912", or * "23/59/59.012345678912", or * "23T59T59.012345678912", or diff --git a/src/datetime_write.hpp b/src/datetime_write.hpp index ca0839a..d9c2257 100644 --- a/src/datetime_write.hpp +++ b/src/datetime_write.hpp @@ -22,9 +22,11 @@ template class SpitDate {}; template <> class SpitDate { public: static const int numChars = 10; - static int spit(const ymd_date &ymd, char *buffer) noexcept { - return std::sprintf(buffer, "%4d/%02d/%02d", ymd.yr().as_underlying_type(), + static int spit(const ymd_date &ymd, char *buffer, char delimeter='/') noexcept { + return std::sprintf(buffer, "%4d%c%02d%c%02d", ymd.yr().as_underlying_type(), + delimeter, ymd.mn().as_underlying_type(), + delimeter, ymd.dm().as_underlying_type()); } }; @@ -33,9 +35,11 @@ template <> class SpitDate { template <> class SpitDate { public: static const int numChars = 10; - static int spit(const ymd_date &ymd, char *buffer) noexcept { - return std::sprintf(buffer, "%02d/%02d/%4d", ymd.dm().as_underlying_type(), + static int spit(const ymd_date &ymd, char *buffer, char delimeter='/') noexcept { + return std::sprintf(buffer, "%02d%c%02d%c%4d", ymd.dm().as_underlying_type(), + delimeter, ymd.mn().as_underlying_type(), + delimeter, ymd.yr().as_underlying_type()); } }; @@ -56,8 +60,8 @@ template <> class SpitDate { * to represent the date * @return On success, a pointer to \p buffer */ -template const char *to_char(const ymd_date &ymd, char *buffer) { - if (SpitDate::spit(ymd, buffer) != SpitDate::numChars) { +template const char *to_char(const ymd_date &ymd, char *buffer, char delimeter='/') { + if (SpitDate::spit(ymd, buffer, delimeter) != SpitDate::numChars) { throw std::runtime_error("[ERROR] Failed to format date to string\n"); } return buffer;