GnuCash  5.6-150-g038405b370+
Public Member Functions | Static Public Attributes | Friends
GncDate Class Reference

GnuCash Date class. More...

#include <gnc-datetime.hpp>

Public Member Functions

 GncDate ()
 Construct a GncDate representing the current day.
 
 GncDate (int year, int month, int day)
 Construct a GncDate representing the given year, month, and day in the proleptic Gregorian calendar. More...
 
 GncDate (const std::string str, const std::string fmt)
 Construct a GncDate by parsing a string assumed to be in the format passed in. More...
 
 GncDate (std::unique_ptr< GncDateImpl > impl)
 Construct a GncDate from a GncDateImpl.
 
 GncDate (const GncDate &)
 Copy constructor.
 
 GncDate (GncDate &&)
 Move constructor.
 
 ~GncDate ()
 Default destructor.
 
GncDateoperator= (const GncDate &)
 Copy assignment operator.
 
GncDateoperator= (GncDate &&)
 Move assignment operator.
 
void today ()
 Set the date object to the computer clock's current day. More...
 
gnc_ymd year_month_day () const
 Get the year, month, and day from the date as a gnc_ymd. More...
 
std::string format (const char *format)
 Format the GncDate into a std::string. More...
 
bool isnull (void)
 Test that the Date has an implementation. More...
 

Static Public Attributes

static const std::vector< GncDateFormatc_formats
 A vector with all the date formats supported by the string constructor. More...
 

Friends

bool operator< (const GncDate &, const GncDate &)
 
bool operator> (const GncDate &, const GncDate &)
 
bool operator== (const GncDate &, const GncDate &)
 
bool operator<= (const GncDate &, const GncDate &)
 
bool operator>= (const GncDate &, const GncDate &)
 
bool operator!= (const GncDate &, const GncDate &)
 

Detailed Description

GnuCash Date class.

The represented date is limited to the period between 1400 and 9999 CE.

Definition at line 213 of file gnc-datetime.hpp.

Constructor & Destructor Documentation

◆ GncDate() [1/2]

GncDate::GncDate ( int  year,
int  month,
int  day 
)

Construct a GncDate representing the given year, month, and day in the proleptic Gregorian calendar.

Years are constrained to be from 1400 - 9999 CE inclusive. Dates will be normalized if the day or month values are outside of the normal ranges. e.g. 1994, -3, 47 will be normalized to 1993-10-17.

Parameters
yearThe year in the Common Era.
monthThe month, where 1 is January and 12 is December.
dayThe day of the month, beginning with 1.
Exceptions
std::invalid_argumentif the calculated year is outside of the constrained range.

Definition at line 840 of file gnc-datetime.cpp.

840  :
841 m_impl(new GncDateImpl(year, month, day)) {}
Private implementation of GncDate.

◆ GncDate() [2/2]

GncDate::GncDate ( const std::string  str,
const std::string  fmt 
)

Construct a GncDate by parsing a string assumed to be in the format passed in.

The currently recognized formats are d-m-y, m-d-y, y-m-d, m-d, d-m. Note while the format descriptions use "-" as separator any of "-" (hyphen), "/" (slash), "'" (single quote), " " (space) or "." will be accepted.

Parameters
strThe string to be interpreted.
fmtThe expected date format of the string passed in.
Exceptions
std::invalid_argumentif
  • the string couldn't be parsed using the provided format
  • any of the date components is outside of its limit (like month being 13, or day being 31 in February)
  • fmt doesn't specify a year, yet a year was found in the string

Definition at line 842 of file gnc-datetime.cpp.

842  :
843 m_impl(new GncDateImpl(str, fmt)) {}
Private implementation of GncDate.

Member Function Documentation

◆ format()

std::string GncDate::format ( const char *  format)

Format the GncDate into a std::string.

Parameters
formatA cstr describing the way the date and time are presented. Code letters preceded with % stand in for arguments; most are the same as described in strftime(3), but there are a few differences. Consult the boost::date_time documentation.
Returns
a std::string containing a representation of the date according to the format.

Definition at line 867 of file gnc-datetime.cpp.

868 {
869  return m_impl->format(format);
870 }
std::string format(const char *format)
Format the GncDate into a std::string.

◆ isnull()

bool GncDate::isnull ( void  )
inline

Test that the Date has an implementation.

Definition at line 301 of file gnc-datetime.hpp.

301 { return m_impl == nullptr; }

◆ today()

void GncDate::today ( )

Set the date object to the computer clock's current day.

Definition at line 861 of file gnc-datetime.cpp.

862 {
863  m_impl->today();
864 }

◆ year_month_day()

gnc_ymd GncDate::year_month_day ( ) const

Get the year, month, and day from the date as a gnc_ymd.

Returns
gnc_ymd struct

Definition at line 873 of file gnc-datetime.cpp.

874 {
875  return m_impl->year_month_day();
876 }

Friends And Related Function Documentation

◆ operator<

bool operator< ( const GncDate ,
const GncDate  
)
friend

Standard comparison operators working on GncDate objects.

Definition at line 878 of file gnc-datetime.cpp.

878 { return *(a.m_impl) < *(b.m_impl); }

Field Documentation

◆ c_formats

const std::vector< GncDateFormat > GncDate::c_formats
static

A vector with all the date formats supported by the string constructor.

The currently supported formats are: "y-m-d" (including yyyymmdd) "d-m-y" (including ddmmyyyy) "m-d-y" (including mmddyyyy) "d-m" (including ddmm) "m-d" (including mmdd)

Notes:

  • while the format names are using a "-" as separator, the regexes will accept any of "-/.' " and will also work for dates without separators.
  • the format strings are marked for translation so it is possible to use a localized version of a format string using gettext. Example: gettext(GncDate::c_formats[0])

Definition at line 232 of file gnc-datetime.hpp.


The documentation for this class was generated from the following files: