57 return ! moment.is_not_a_date_time();
60typedef boost::gregorian::date
date_t;
64 return ! moment.is_not_a_date();
67extern optional<datetime_t>
epoch;
70#ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
71#define TRUE_CURRENT_TIME() (boost::posix_time::microsec_clock::local_time())
72#define CURRENT_TIME() (epoch ? *epoch : TRUE_CURRENT_TIME())
74#define TRUE_CURRENT_TIME() (boost::posix_time::second_clock::local_time())
75#define CURRENT_TIME() (epoch ? *epoch : TRUE_CURRENT_TIME())
77#define CURRENT_DATE() \
78 (epoch ? epoch->date() : boost::gregorian::day_clock::local_day())
82optional<date_time::weekdays>
84optional<date_time::months_of_year>
105 const optional<const char *>& format = none);
110 const optional<const char *>& format = none);
129 bool _has_month =
false,
130 bool _has_day =
false)
193#if !defined(__clang__)
211#if !defined(__clang__)
217 std::ostringstream out;
222 case DAYS: out <<
"day";
break;
223 case WEEKS: out <<
"week";
break;
224 case MONTHS: out <<
"month";
break;
225 case QUARTERS: out <<
"quarter";
break;
226 case YEARS: out <<
"year";
break;
256 optional<day_of_week_type>
wday;
260 const optional<month_type>& _month = none,
261 const optional<day_type>& _day = none,
262 const optional<day_of_week_type>& _wday = none)
265 "year_type, month_type, day_type, day_of_week_type");
268 const optional<date_traits_t>& traits = none) {
269 if (! traits || traits->has_year)
271 if (! traits || traits->has_month)
273 if (! traits || traits->has_day)
306 std::ostringstream out;
309 out <<
" year " << *
year;
311 out <<
" month " << *
month;
313 out <<
" day " << *
day;
315 out <<
" wday " << *
wday;
325 optional<date_specifier_t> range_begin;
326 optional<date_specifier_t> range_end;
332 const optional<date_specifier_t>& _range_end = none)
333 : range_begin(_range_begin), range_end(_range_end),
334 end_inclusive(false) {
338 : range_begin(other.range_begin), range_end(other.range_end),
339 end_inclusive(other.end_inclusive) {
348 return range_begin->begin();
352 optional<date_t>
end()
const {
355 return range_end->end();
357 return range_end->begin();
364 optional<date_t> b =
begin();
365 optional<date_t> e =
end();
366 bool after_begin = b ?
date >= *b :
true;
367 bool before_end = e ?
date < *e :
true;
368 return after_begin && before_end;
372 std::ostringstream out;
375 out <<
"from" << range_begin->to_string();
377 out <<
" to" << range_end->to_string();
385 typedef variant<int, date_specifier_t, date_range_t> value_type;
387 value_type specifier_or_range;
394 : specifier_or_range(other.specifier_or_range) {
398 : specifier_or_range(specifier) {
402 : specifier_or_range(range) {
411 return boost::get<date_specifier_t>(specifier_or_range).begin();
412 else if (specifier_or_range.type() ==
typeid(
date_range_t))
413 return boost::get<date_range_t>(specifier_or_range).begin();
417 optional<date_t>
end()
const {
419 return boost::get<date_specifier_t>(specifier_or_range).end();
420 else if (specifier_or_range.type() ==
typeid(
date_range_t))
421 return boost::get<date_range_t>(specifier_or_range).end();
428 std::ostringstream out;
431 out <<
"in" << boost::get<date_specifier_t>(specifier_or_range).to_string();
432 else if (specifier_or_range.type() ==
typeid(
date_range_t))
433 out << boost::get<date_range_t>(specifier_or_range).to_string();
447 optional<date_specifier_or_range_t>
range;
488 operator bool()
const {
495 optional<date_t>
end()
const {
502 void stabilize(
const optional<date_t>&
date = none,
bool align_intervals =
false);
505 return static_cast<bool>(
start);
512 const bool align_intervals =
false,
513 const bool allow_shift =
true);
#define DECLARE_EXCEPTION(name, kind)
General utility facilities used by Ledger.
#define TRACE_CTOR(cls, args)
optional< date_time::months_of_year > string_to_month_of_year(const std::string &str)
void put_date(property_tree::ptree &pt, const date_t &when)
std::string format_datetime(const datetime_t &when, const format_type_t format_type=FMT_PRINTED, const optional< const char * > &format=none)
void set_date_format(const char *format)
optional< datetime_t > epoch
datetime_t::time_duration_type time_duration_t
bool is_valid(const datetime_t &moment)
void set_input_date_format(const char *format)
optional< int > year_directive_year
boost::gregorian::date date_t
boost::gregorian::date_iterator date_iterator_t
void put_datetime(property_tree::ptree &pt, const datetime_t &when)
std::string format_date(const date_t &when, const format_type_t format_type=FMT_PRINTED, const optional< const char * > &format=none)
date_time::weekdays start_of_week
std::ostream & operator<<(std::ostream &out, const account_t &account)
void show_period_tokens(std::ostream &out, const string &arg)
optional< date_time::weekdays > string_to_day_of_week(const std::string &str)
void set_datetime_format(const char *format)
datetime_t parse_datetime(const char *str)
boost::posix_time::ptime datetime_t
date_t parse_date(const char *str)
datetime_error(const string &why)
date_error(const string &why)
bool operator==(const date_traits_t &traits) const
date_traits_t(const date_traits_t &traits)
date_traits_t & operator=(const date_traits_t &traits)
date_traits_t(bool _has_year=false, bool _has_month=false, bool _has_day=false)
date_t add(const date_t &date) const
static date_t find_nearest(const date_t &date, skip_quantum_t skip)
enum ledger::date_duration_t::skip_quantum_t quantum
date_t subtract(const date_t &date) const
date_duration_t(const date_duration_t &dur)
date_duration_t(skip_quantum_t _quantum, int _length)
date_specifier_t(const optional< year_type > &_year=none, const optional< month_type > &_month=none, const optional< day_type > &_day=none, const optional< day_of_week_type > &_wday=none)
optional< month_type > month
optional< day_of_week_type > wday
bool is_within(const date_t &date) const
optional< date_duration_t > implied_duration() const
optional< year_type > year
date_t::day_type day_type
date_t::month_type month_type
date_t::day_of_week_type day_of_week_type
friend class date_parser_t
date_specifier_t(const date_specifier_t &other)
date_specifier_t(const date_t &date, const optional< date_traits_t > &traits=none)
date_range_t(const optional< date_specifier_t > &_range_begin=none, const optional< date_specifier_t > &_range_end=none)
optional< date_t > end() const
optional< date_t > begin() const
bool is_within(const date_t &date) const
date_range_t(const date_range_t &other)
friend class date_parser_t
optional< date_t > end() const
~date_specifier_or_range_t()
date_specifier_or_range_t()
date_specifier_or_range_t(const date_range_t &range)
optional< date_t > begin() const
date_specifier_or_range_t(const date_specifier_t &specifier)
date_specifier_or_range_t(const date_specifier_or_range_t &other)
optional< date_t > begin() const
void dump(std::ostream &out)
optional< date_t > finish
void stabilize(const optional< date_t > &date=none, bool align_intervals=false)
static date_t subtract_duration(const date_t &date, const date_duration_t &duration)
date_interval_t & operator++()
bool operator<(const date_interval_t &other) const
optional< date_t > end() const
optional< date_t > end_of_duration
date_interval_t(const string &str)
void parse(const string &str)
static date_t add_duration(const date_t &date, const date_duration_t &duration)
bool operator==(const date_interval_t &other) const
date_interval_t(const date_interval_t &other)
optional< date_t > inclusive_end() const
bool within_period(const date_t &date=(epoch ? epoch->date() :boost::gregorian::day_clock::local_day()))
optional< date_specifier_or_range_t > range
bool find_period(const date_t &date=(epoch ? epoch->date() :boost::gregorian::day_clock::local_day()), const bool align_intervals=false, const bool allow_shift=true)
Find the current or next period containing date.
optional< date_duration_t > duration