mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add GncDateTime::timestamp().
To provide a C++ implementation of gnc_date_timestamp and to avoid using the expensive and localized GncDateTime::format().
This commit is contained in:
parent
793fb1a3ed
commit
cee97be8d4
@ -1075,7 +1075,7 @@ qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
|
||||
gchar *
|
||||
gnc_date_timestamp (void)
|
||||
{
|
||||
return gnc_print_time64(gnc_time(nullptr), "%Y%m%d%H%M%S");
|
||||
return g_strdup(GncDateTime::timestamp().c_str());
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
|
@ -236,6 +236,7 @@ public:
|
||||
std::string format(const char* format) const;
|
||||
std::string format_zulu(const char* format) const;
|
||||
std::string format_iso8601() const;
|
||||
static std::string timestamp();
|
||||
private:
|
||||
LDT m_time;
|
||||
static const TD time_of_day[3];
|
||||
@ -466,6 +467,14 @@ GncDateTimeImpl::format_iso8601() const
|
||||
return str.substr(0, 19);
|
||||
}
|
||||
|
||||
std::string
|
||||
GncDateTimeImpl::timestamp()
|
||||
{
|
||||
GncDateTimeImpl gdt;
|
||||
auto str = boost::posix_time::to_iso_string(gdt.m_time.local_time());
|
||||
return str.substr(0, 8) + str.substr(9, 15);
|
||||
}
|
||||
|
||||
/* Member function definitions for GncDateImpl.
|
||||
*/
|
||||
GncDateImpl::GncDateImpl(const std::string str, const std::string fmt) :
|
||||
@ -600,6 +609,12 @@ GncDateTime::format_iso8601() const
|
||||
return m_impl->format_iso8601();
|
||||
}
|
||||
|
||||
std::string
|
||||
GncDateTime::timestamp()
|
||||
{
|
||||
return GncDateTimeImpl::timestamp();
|
||||
}
|
||||
|
||||
/* GncDate */
|
||||
GncDate::GncDate() : m_impl{new GncDateImpl} {}
|
||||
GncDate::GncDate(int year, int month, int day) :
|
||||
|
@ -152,7 +152,11 @@ public:
|
||||
* @return a std::string in the format YYYY-MM-DD HH:MM:SS.
|
||||
*/
|
||||
std::string format_iso8601() const;
|
||||
|
||||
/** Get an undelimited string representing the current date and time.
|
||||
* @return a std::string in the format YYYYMMDDHHMMSS.
|
||||
*/
|
||||
static std::string timestamp();
|
||||
|
||||
private:
|
||||
std::unique_ptr<GncDateTimeImpl> m_impl;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user