diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-04 19:55:27 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-04 19:55:27 -0400 |
commit | 2d941730b1c60342be5b108d2d654723b3b7c2cb (patch) | |
tree | 6a3f4b7305857e85d2684670492007bafc3668d0 /src/times.h | |
parent | 73cf3b01fbd50c3a8a4fd96ff69643c28394d8fe (diff) | |
download | fork-ledger-2d941730b1c60342be5b108d2d654723b3b7c2cb.tar.gz fork-ledger-2d941730b1c60342be5b108d2d654723b3b7c2cb.tar.bz2 fork-ledger-2d941730b1c60342be5b108d2d654723b3b7c2cb.zip |
Largely removed all of Ledger's use of global variables, for the REPL's sake.
Diffstat (limited to 'src/times.h')
-rw-r--r-- | src/times.h | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/times.h b/src/times.h index 375a2555..4bcdd9e2 100644 --- a/src/times.h +++ b/src/times.h @@ -63,22 +63,25 @@ inline bool is_valid(const date_t& moment) { return ! moment.is_not_a_date(); } -extern const datetime_t& current_time; -extern const date_t& current_date; -extern int current_year; -extern optional<string> input_date_format; -extern string output_date_format; +#ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK +#define CURRENT_TIME() boost::posix_time::microsec_clock::universal_time() +#else +#define CURRENT_TIME() boost::posix_time::second_clock::universal_time() +#endif +#define CURRENT_DATE() boost::gregorian::day_clock::universal_day() -datetime_t parse_datetime(const char * str); +extern optional<string> input_date_format; -inline datetime_t parse_datetime(const string& str) { - return parse_datetime(str.c_str()); +datetime_t parse_datetime(const char * str, int current_year = -1); + +inline datetime_t parse_datetime(const string& str, int current_year = -1) { + return parse_datetime(str.c_str(), current_year); } -date_t parse_date(const char * str); +date_t parse_date(const char * str, int current_year = -1); -inline date_t parse_date(const string& str) { - return parse_date(str.c_str()); +inline date_t parse_date(const string& str, int current_year = -1) { + return parse_date(str.c_str(), current_year); } inline std::time_t to_time_t(const ptime& t) @@ -91,27 +94,22 @@ inline std::time_t to_time_t(const ptime& t) return (t-start).total_seconds(); } -inline string format_datetime(const datetime_t& when) +inline string format_datetime(const datetime_t& when, + const string format = "%Y-%m-%d %H:%M:%S") { char buf[256]; time_t moment = to_time_t(when); - std::strftime(buf, 255, (output_date_format + " %H:%M:%S").c_str(), - std::localtime(&moment)); + std::strftime(buf, 255, format.c_str(), std::localtime(&moment)); return buf; } inline string format_date(const date_t& when, - const optional<string>& format = none) + const string format = "%Y-%m-%d") { - if (format || ! output_date_format.empty()) { - char buf[256]; - std::tm moment = gregorian::to_tm(when); - std::strftime(buf, 255, format ? - format->c_str() : output_date_format.c_str(), &moment); - return buf; - } else { - return to_simple_string(when).substr(2); - } + char buf[256]; + std::tm moment = gregorian::to_tm(when); + std::strftime(buf, 255, format.c_str(), &moment); + return buf; } /** |