diff options
Diffstat (limited to 'src/times.h')
-rw-r--r-- | src/times.h | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/times.h b/src/times.h index 4bcdd9e2..190e5c6b 100644 --- a/src/times.h +++ b/src/times.h @@ -70,17 +70,17 @@ inline bool is_valid(const date_t& moment) { #endif #define CURRENT_DATE() boost::gregorian::day_clock::universal_day() -extern optional<string> input_date_format; +extern optional<std::string> input_date_format; datetime_t parse_datetime(const char * str, int current_year = -1); -inline datetime_t parse_datetime(const string& str, int current_year = -1) { +inline datetime_t parse_datetime(const std::string& str, int current_year = -1) { return parse_datetime(str.c_str(), current_year); } date_t parse_date(const char * str, int current_year = -1); -inline date_t parse_date(const string& str, int current_year = -1) { +inline date_t parse_date(const std::string& str, int current_year = -1) { return parse_date(str.c_str(), current_year); } @@ -94,21 +94,27 @@ inline std::time_t to_time_t(const ptime& t) return (t-start).total_seconds(); } -inline string format_datetime(const datetime_t& when, - const string format = "%Y-%m-%d %H:%M:%S") +extern std::string output_datetime_format; + +inline std::string format_datetime(const datetime_t& when, + const optional<std::string>& format = none) { char buf[256]; time_t moment = to_time_t(when); - std::strftime(buf, 255, format.c_str(), std::localtime(&moment)); + std::strftime(buf, 255, format ? format->c_str() : + output_datetime_format.c_str(), std::localtime(&moment)); return buf; } -inline string format_date(const date_t& when, - const string format = "%Y-%m-%d") +extern std::string output_date_format; + +inline std::string format_date(const date_t& when, + const optional<std::string>& format = none) { char buf[256]; std::tm moment = gregorian::to_tm(when); - std::strftime(buf, 255, format.c_str(), &moment); + std::strftime(buf, 255, format ? format->c_str() : + output_date_format.c_str(), &moment); return buf; } |