48char *strptime(
const char *,
const char *,
struct tm *);
56 if (hour < 0 || hour > 23)
60 if (min < 0 || min > 59)
69 if (strftime(value, 6,
"%R", &tm) != 0)
87 result.push_back(
'-');
90 uint16_t whole = rate >> 2;
91 uint16_t frac = rate & 0x3;
93 result += integer_to_string(whole);
102 result.append(
".25");
105 result.append(
".50");
108 result.append(
".75");
120 tm.tm_year = year - 1900;
121 tm.tm_mon = month - 1;
124 if (strftime(value, 13,
"%b %e, %Y", &tm) != 0)
138 const std::string &stime,
int *hour,
int *min)
141 if (strptime(stime.c_str(),
"%R", &tm) ==
nullptr)
162 const char *rate_c_str = srate.c_str();
164 float rate = strtof(rate_c_str, &end);
166 if (end == rate_c_str)
176 else if (rate > 511.75)
182 rate += rate < 0 ? -0.5 : 0.5;
190 const std::string &sdate,
int *year,
int *month,
int *day)
193 memset(&tm, 0,
sizeof(tm));
194 if (strptime(sdate.c_str(),
"%b %e, %Y", &tm) ==
nullptr)
207 time_t t = mktime(&tm);
218 if (tm.tm_year < (0 - 1900) || tm.tm_year > (4095 - 1900))
223 *year = tm.tm_year + 1900;
224 *month = tm.tm_mon + 1;
235 *srate = std::move(out);
243 int y = 1970, m = 1, d = 1;
248 *sdate = std::move(out);
261 *stime = std::move(out);
static std::string time_to_string(int hour, int min)
Convert time in integer hours/minutes to a string ("hh:mm").
static std::string rate_quarters_to_string(int16_t rate)
Convert rate in integer rate quarters to a string (float).
static bool string_to_time(const std::string &stime, int *hour, int *min)
Convert a string (hh:mm) to hour and minute component integers.
static int16_t string_to_rate_quarters(const std::string &srate)
Convert a string (float) to rate quarters.
static bool canonicalize_time_string(std::string *stime)
Verifies that a user-provided string parses as time, and canonicalizes the string format.
static std::string date_to_string(int year, int month, int day)
Converts a date to a string "Mmm dd, yyyy".
static bool canonicalize_rate_string(std::string *srate)
Verifies that a user-provided string parses as rate quarters, and canonicalizes the string format.
static bool canonicalize_date_string(std::string *sdate)
Verifies that a user-provided string parses as date, and canonicalizes the string format.
static bool string_to_date(const std::string &sdate, int *year, int *month, int *day)
Converts a (user-provided) string "Mmm dd, yyyy" to date.