mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Implement GncDate::format()
Analog of GncDateTime::format().
This commit is contained in:
parent
2b84dfae8d
commit
269bb510fb
@ -65,6 +65,7 @@ public:
|
|||||||
|
|
||||||
void today() { m_greg = boost::gregorian::day_clock::local_day(); }
|
void today() { m_greg = boost::gregorian::day_clock::local_day(); }
|
||||||
ymd year_month_day() const;
|
ymd year_month_day() const;
|
||||||
|
std::string format(const char* format) const;
|
||||||
private:
|
private:
|
||||||
Date m_greg;
|
Date m_greg;
|
||||||
};
|
};
|
||||||
@ -76,6 +77,18 @@ GncDateImpl::year_month_day() const
|
|||||||
return {boost_ymd.year, boost_ymd.month.as_number(), boost_ymd.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.
|
/** Private implementation of GncDateTime. See the documentation for that class.
|
||||||
*/
|
*/
|
||||||
static LDT
|
static LDT
|
||||||
@ -211,6 +224,7 @@ GncDateTimeImpl::format(const char* format) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* =================== Presentation-class Implementations ====================*/
|
/* =================== Presentation-class Implementations ====================*/
|
||||||
|
/* GncDate */
|
||||||
GncDate::GncDate() : m_impl{new GncDateImpl} {}
|
GncDate::GncDate() : m_impl{new GncDateImpl} {}
|
||||||
GncDate::GncDate(int year, int month, int day) :
|
GncDate::GncDate(int year, int month, int day) :
|
||||||
m_impl(new GncDateImpl(year, month, day)) {}
|
m_impl(new GncDateImpl(year, month, day)) {}
|
||||||
@ -228,12 +242,20 @@ GncDate::today()
|
|||||||
m_impl->today();
|
m_impl->today();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
GncDate::format(const char* format)
|
||||||
|
{
|
||||||
|
return m_impl->format(format);
|
||||||
|
}
|
||||||
|
|
||||||
ymd
|
ymd
|
||||||
GncDate::year_month_day() const
|
GncDate::year_month_day() const
|
||||||
{
|
{
|
||||||
return m_impl->year_month_day();
|
return m_impl->year_month_day();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* GncDateTime */
|
||||||
|
|
||||||
GncDateTime::GncDateTime() : m_impl(new GncDateTimeImpl) {}
|
GncDateTime::GncDateTime() : m_impl(new GncDateTimeImpl) {}
|
||||||
GncDateTime::GncDateTime(const time64 time) :
|
GncDateTime::GncDateTime(const time64 time) :
|
||||||
m_impl(new GncDateTimeImpl(time)) {}
|
m_impl(new GncDateTimeImpl(time)) {}
|
||||||
|
@ -69,6 +69,15 @@ public:/** Construct a GncDate representing the current day.
|
|||||||
@return ymd struct
|
@return ymd struct
|
||||||
*/
|
*/
|
||||||
ymd year_month_day() const;
|
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. */
|
/** Test that the Date has an implementation. */
|
||||||
bool isnull (void) { return m_impl == nullptr; }
|
bool isnull (void) { return m_impl == nullptr; }
|
||||||
|
|
||||||
@ -83,7 +92,7 @@ private:
|
|||||||
* between 1400 and 9999 CE.
|
* between 1400 and 9999 CE.
|
||||||
*
|
*
|
||||||
* Be careful when using times: A particular time is represented
|
* Be careful when using times: A particular time is represented
|
||||||
* differently depending on the timezone, which can shif the displayed
|
* differently depending on the timezone, which can shift the displayed
|
||||||
* date. Accounting is generally not sensitive to the time of day, but
|
* date. Accounting is generally not sensitive to the time of day, but
|
||||||
* is sensitive to the recorded day. Since GncDates are not timezone
|
* is sensitive to the recorded day. Since GncDates are not timezone
|
||||||
* dependent they should be preferred for accounting entries.
|
* dependent they should be preferred for accounting entries.
|
||||||
@ -110,7 +119,7 @@ public:
|
|||||||
* @exception std::invalid_argument if the year is outside the constraints.
|
* @exception std::invalid_argument if the year is outside the constraints.
|
||||||
*/
|
*/
|
||||||
GncDateTime(const struct tm tm);
|
GncDateTime(const struct tm tm);
|
||||||
/** Construct a GncDateTime
|
/** Construct a GncDateTime
|
||||||
* @param str: A string representing the date and time in some
|
* @param str: A string representing the date and time in some
|
||||||
* recognizable format. Note that if a timezone is not specified the
|
* recognizable format. Note that if a timezone is not specified the
|
||||||
* default is UTC, not the local one.
|
* default is UTC, not the local one.
|
||||||
@ -142,11 +151,12 @@ public:
|
|||||||
/** Test if the GncDateTime has a member pointer. Testing only. */
|
/** Test if the GncDateTime has a member pointer. Testing only. */
|
||||||
bool isnull (void) { return m_impl == nullptr; }
|
bool isnull (void) { return m_impl == nullptr; }
|
||||||
/** Format the GncDateTime into a std::string
|
/** Format the GncDateTime 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
|
* @return a std::string containing a representation of the date
|
||||||
* according to the format. Consult the boost::date_time
|
* according to the format.
|
||||||
* documentation for format characters; while they mostly compy with
|
|
||||||
* POSIX there are a few differences.
|
|
||||||
*/
|
*/
|
||||||
std::string format(const char* format) const;
|
std::string format(const char* format) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user