Skip to content

Commit

Permalink
var
Browse files Browse the repository at this point in the history
  • Loading branch information
xanthospap committed May 3, 2024
1 parent c129248 commit 56dfe45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/datetime_io_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/datetime_read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ template <YMDFormat F> 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
Expand Down Expand Up @@ -64,7 +64,7 @@ template <> class ReadInDate<YMDFormat::YYYYMMDD> {
/** 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
Expand Down Expand Up @@ -109,7 +109,7 @@ template <> class ReadInDate<YMDFormat::DDMMYYYY> {
* 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -216,7 +216,7 @@ class ReadInTime<S, HMSFormat::HHMMSS> {
/** 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
Expand Down
16 changes: 10 additions & 6 deletions src/datetime_write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ template <YMDFormat F> class SpitDate {};
template <> class SpitDate<YMDFormat::YYYYMMDD> {
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());
}
};
Expand All @@ -33,9 +35,11 @@ template <> class SpitDate<YMDFormat::YYYYMMDD> {
template <> class SpitDate<YMDFormat::DDMMYYYY> {
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());
}
};
Expand All @@ -56,8 +60,8 @@ template <> class SpitDate<YMDFormat::DDMMYYYY> {
* to represent the date
* @return On success, a pointer to \p buffer
*/
template <YMDFormat F> const char *to_char(const ymd_date &ymd, char *buffer) {
if (SpitDate<F>::spit(ymd, buffer) != SpitDate<F>::numChars) {
template <YMDFormat F> const char *to_char(const ymd_date &ymd, char *buffer, char delimeter='/') {
if (SpitDate<F>::spit(ymd, buffer, delimeter) != SpitDate<F>::numChars) {
throw std::runtime_error("[ERROR] Failed to format date to string\n");
}
return buffer;
Expand Down

0 comments on commit 56dfe45

Please sign in to comment.