Add datetime::formatHm12h/formatTime12h and use them for the Home footer clock, the Timezone page's local-time sample, and the log viewer timestamps. Storage and parsing remain 24-hour HH:MM. Extends the date-format tests with the midnight/noon edge cases.
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <ctime>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace radiantwave::datetime {
|
|
|
|
// Default date format (US convention): MM/DD/YYYY.
|
|
constexpr const char* DEFAULT_DATE_FORMAT = "%m/%d/%Y";
|
|
|
|
// One selectable date format. `name` is a human-friendly convention label;
|
|
// `pattern` is the strftime spec used to render it.
|
|
struct DateFormatOption {
|
|
std::string name;
|
|
std::string pattern;
|
|
};
|
|
|
|
// The formats offered to the end user, ordered most-to-least common.
|
|
std::vector<DateFormatOption> getDateFormatOptions();
|
|
|
|
// Render `t` in local time using a strftime pattern (e.g. "%m/%d/%Y").
|
|
// Falls back to an empty string on error.
|
|
std::string formatDate(std::time_t t, const std::string& pattern);
|
|
|
|
// Render `t` as a 24-hour clock: HH:MM:SS.
|
|
std::string formatTime(std::time_t t);
|
|
|
|
// Convert a 24-hour clock `HH:MM` string to a 12-hour display label, e.g.
|
|
// "00:00" -> "12:00 AM", "13:05" -> "1:05 PM". Storage and parsing remain
|
|
// 24-hour; this is display-only. Returns `hm24` unchanged when it is not a
|
|
// valid 24-hour time.
|
|
std::string formatHm12h(const std::string& hm24);
|
|
|
|
// Render `t` in local time as a 12-hour clock label, e.g. "7:05 PM".
|
|
std::string formatTime12h(std::time_t t);
|
|
|
|
} // namespace radiantwave::datetime
|