mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-16 18:25:11 -06:00
Swap GncDate and GncDateTime in preparation of a future commit
This commit is contained in:
parent
b2b32e29fa
commit
724f8aa784
@ -58,43 +58,6 @@ static constexpr auto ticks_per_second = INT64_C(1000000);
|
||||
static constexpr auto ticks_per_second = INT64_C(1000000000);
|
||||
#endif
|
||||
|
||||
/** Private implementation of GncDate. See the documentation for that class.
|
||||
*/
|
||||
class GncDateImpl
|
||||
{
|
||||
public:
|
||||
GncDateImpl(): m_greg(boost::gregorian::day_clock::local_day()) {}
|
||||
GncDateImpl(const int year, const int month, const int day) :
|
||||
m_greg(year, static_cast<Month>(month), day) {}
|
||||
GncDateImpl(Date d) : m_greg(d) {}
|
||||
|
||||
void today() { m_greg = boost::gregorian::day_clock::local_day(); }
|
||||
ymd year_month_day() const;
|
||||
std::string format(const char* format) const;
|
||||
std::string format_zulu(const char* format) const;
|
||||
private:
|
||||
Date m_greg;
|
||||
};
|
||||
|
||||
ymd
|
||||
GncDateImpl::year_month_day() const
|
||||
{
|
||||
auto boost_ymd = m_greg.year_month_day();
|
||||
return {boost_ymd.year, boost_ymd.month.as_number(), boost_ymd.day};
|
||||
}
|
||||
|
||||
std::string
|
||||
GncDateImpl::format(const char* format) const
|
||||
{
|
||||
using Facet = boost::gregorian::date_facet;
|
||||
std::stringstream ss;
|
||||
//The stream destructor frees the facet, so it must be heap-allocated.
|
||||
auto output_facet(new Facet(format));
|
||||
ss.imbue(std::locale(std::locale(), output_facet));
|
||||
ss << m_greg;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/** Private implementation of GncDateTime. See the documentation for that class.
|
||||
*/
|
||||
static LDT
|
||||
@ -153,6 +116,26 @@ private:
|
||||
LDT m_time;
|
||||
};
|
||||
|
||||
/** Private implementation of GncDate. See the documentation for that class.
|
||||
*/
|
||||
class GncDateImpl
|
||||
{
|
||||
public:
|
||||
GncDateImpl(): m_greg(boost::gregorian::day_clock::local_day()) {}
|
||||
GncDateImpl(const int year, const int month, const int day) :
|
||||
m_greg(year, static_cast<Month>(month), day) {}
|
||||
GncDateImpl(Date d) : m_greg(d) {}
|
||||
|
||||
void today() { m_greg = boost::gregorian::day_clock::local_day(); }
|
||||
ymd year_month_day() const;
|
||||
std::string format(const char* format) const;
|
||||
std::string format_zulu(const char* format) const;
|
||||
private:
|
||||
Date m_greg;
|
||||
};
|
||||
|
||||
/* Member function definitions for GncDateTimeImpl.
|
||||
*/
|
||||
GncDateTimeImpl::GncDateTimeImpl(const std::string str) :
|
||||
m_time(unix_epoch, utc_zone)
|
||||
{
|
||||
@ -270,37 +253,28 @@ GncDateTimeImpl::format_zulu(const char* format) const
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/* =================== Presentation-class Implementations ====================*/
|
||||
/* GncDate */
|
||||
GncDate::GncDate() : m_impl{new GncDateImpl} {}
|
||||
GncDate::GncDate(int year, int month, int day) :
|
||||
m_impl(new GncDateImpl(year, month, day)) {}
|
||||
GncDate::GncDate(std::unique_ptr<GncDateImpl> impl) :
|
||||
m_impl(std::move(impl)) {}
|
||||
GncDate::GncDate(GncDate&&) = default;
|
||||
GncDate::~GncDate() = default;
|
||||
|
||||
GncDate&
|
||||
GncDate::operator=(GncDate&&) = default;
|
||||
|
||||
void
|
||||
GncDate::today()
|
||||
/* Member function definitions for GncDateTimeImpl.
|
||||
*/
|
||||
ymd
|
||||
GncDateImpl::year_month_day() const
|
||||
{
|
||||
m_impl->today();
|
||||
auto boost_ymd = m_greg.year_month_day();
|
||||
return {boost_ymd.year, boost_ymd.month.as_number(), boost_ymd.day};
|
||||
}
|
||||
|
||||
std::string
|
||||
GncDate::format(const char* format)
|
||||
GncDateImpl::format(const char* format) const
|
||||
{
|
||||
return m_impl->format(format);
|
||||
}
|
||||
|
||||
ymd
|
||||
GncDate::year_month_day() const
|
||||
{
|
||||
return m_impl->year_month_day();
|
||||
using Facet = boost::gregorian::date_facet;
|
||||
std::stringstream ss;
|
||||
//The stream destructor frees the facet, so it must be heap-allocated.
|
||||
auto output_facet(new Facet(format));
|
||||
ss.imbue(std::locale(std::locale(), output_facet));
|
||||
ss << m_greg;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/* =================== Presentation-class Implementations ====================*/
|
||||
/* GncDateTime */
|
||||
|
||||
GncDateTime::GncDateTime() : m_impl(new GncDateTimeImpl) {}
|
||||
@ -357,3 +331,33 @@ GncDateTime::format_zulu(const char* format) const
|
||||
{
|
||||
return m_impl->format_zulu(format);
|
||||
}
|
||||
|
||||
/* GncDate */
|
||||
GncDate::GncDate() : m_impl{new GncDateImpl} {}
|
||||
GncDate::GncDate(int year, int month, int day) :
|
||||
m_impl(new GncDateImpl(year, month, day)) {}
|
||||
GncDate::GncDate(std::unique_ptr<GncDateImpl> impl) :
|
||||
m_impl(std::move(impl)) {}
|
||||
GncDate::GncDate(GncDate&&) = default;
|
||||
GncDate::~GncDate() = default;
|
||||
|
||||
GncDate&
|
||||
GncDate::operator=(GncDate&&) = default;
|
||||
|
||||
void
|
||||
GncDate::today()
|
||||
{
|
||||
m_impl->today();
|
||||
}
|
||||
|
||||
std::string
|
||||
GncDate::format(const char* format)
|
||||
{
|
||||
return m_impl->format(format);
|
||||
}
|
||||
|
||||
ymd
|
||||
GncDate::year_month_day() const
|
||||
{
|
||||
return m_impl->year_month_day();
|
||||
}
|
||||
|
@ -36,57 +36,13 @@ typedef struct
|
||||
int day; //1-31
|
||||
} ymd;
|
||||
|
||||
class GncDateImpl;
|
||||
class GncDateTimeImpl;
|
||||
class GncDateImpl;
|
||||
class GncDate;
|
||||
using time64 = int64_t;
|
||||
constexpr const time64 MINTIME = -17987443200;
|
||||
constexpr const time64 MAXTIME = 253402214400;
|
||||
|
||||
class GncDate
|
||||
{
|
||||
public:/** Construct a GncDate representing the current day.
|
||||
*/
|
||||
GncDate();;
|
||||
/** 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.
|
||||
*
|
||||
* @param year: The year in the Common Era.
|
||||
* @param month: The month, where 1 is January and 12 is December.
|
||||
* @param day: The day of the month, beginning with 1.
|
||||
* @exception std::invalid_argument if the calculated year is outside
|
||||
* of the constrained range.
|
||||
*/
|
||||
GncDate(int year, int month, int day);
|
||||
GncDate(std::unique_ptr<GncDateImpl> impl);
|
||||
GncDate(GncDate&&);
|
||||
~GncDate();
|
||||
GncDate& operator=(GncDate&&);
|
||||
/** Set the date object to the computer clock's current day. */
|
||||
void today();
|
||||
/** Get the year, month, and day from the date as a ymd.
|
||||
@return ymd struct
|
||||
*/
|
||||
ymd year_month_day() const;
|
||||
/** Format the GncDate into a std::string
|
||||
* @param format: A 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.
|
||||
* @return a std::string containing a representation of the date
|
||||
* according to the format.
|
||||
*/
|
||||
std::string format(const char* format);
|
||||
/** Test that the Date has an implementation. */
|
||||
bool isnull (void) { return m_impl == nullptr; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<GncDateImpl> m_impl;
|
||||
};
|
||||
|
||||
/** GnuCash DateTime class
|
||||
*
|
||||
* Represents local time in the current timezone.
|
||||
@ -175,4 +131,49 @@ private:
|
||||
std::unique_ptr<GncDateTimeImpl> m_impl;
|
||||
};
|
||||
|
||||
class GncDate
|
||||
{
|
||||
public:/** Construct a GncDate representing the current day.
|
||||
*/
|
||||
GncDate();;
|
||||
/** 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.
|
||||
*
|
||||
* @param year: The year in the Common Era.
|
||||
* @param month: The month, where 1 is January and 12 is December.
|
||||
* @param day: The day of the month, beginning with 1.
|
||||
* @exception std::invalid_argument if the calculated year is outside
|
||||
* of the constrained range.
|
||||
*/
|
||||
GncDate(int year, int month, int day);
|
||||
GncDate(std::unique_ptr<GncDateImpl> impl);
|
||||
GncDate(GncDate&&);
|
||||
~GncDate();
|
||||
GncDate& operator=(GncDate&&);
|
||||
/** Set the date object to the computer clock's current day. */
|
||||
void today();
|
||||
/** Get the year, month, and day from the date as a ymd.
|
||||
* @return ymd struct
|
||||
*/
|
||||
ymd year_month_day() const;
|
||||
/** Format the GncDate into a std::string
|
||||
* @param format: A 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.
|
||||
* @return a std::string containing a representation of the date
|
||||
* according to the format.
|
||||
*/
|
||||
std::string format(const char* format);
|
||||
/** Test that the Date has an implementation. */
|
||||
bool isnull (void) { return m_impl == nullptr; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<GncDateImpl> m_impl;
|
||||
};
|
||||
|
||||
#endif // __GNC_DATETIME_HPP__
|
||||
|
Loading…
Reference in New Issue
Block a user