From 6ca01af594148e12cd8e1da87302644a0bbae3a0 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 9 Feb 2009 17:27:54 -0400 Subject: Fixed the use of --effective and --date-format (-y). --- src/times.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/times.h') 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 input_date_format; +extern optional 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& 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& 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; } -- cgit v1.2.3