mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add operator time64() to enable static_casting a GncDateTime.
This commit is contained in:
parent
10daa27abc
commit
e5861dc119
@ -86,11 +86,20 @@ public:
|
|||||||
GncDateTimeImpl(const time64 time) : m_time(LDT_from_unix_local(time)) {}
|
GncDateTimeImpl(const time64 time) : m_time(LDT_from_unix_local(time)) {}
|
||||||
GncDateTimeImpl(PTime&& pt) : m_time(pt, tzp.get(pt.date().year())) {}
|
GncDateTimeImpl(PTime&& pt) : m_time(pt, tzp.get(pt.date().year())) {}
|
||||||
GncDateTimeImpl(LDT&& ldt) : m_time(ldt) {}
|
GncDateTimeImpl(LDT&& ldt) : m_time(ldt) {}
|
||||||
|
|
||||||
|
operator time64() const;
|
||||||
void now() { m_time = boost::local_time::local_sec_clock::local_time(tzp.get(boost::gregorian::day_clock::local_day().year())); }
|
void now() { m_time = boost::local_time::local_sec_clock::local_time(tzp.get(boost::gregorian::day_clock::local_day().year())); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LDT m_time;
|
LDT m_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GncDateTimeImpl::operator time64() const
|
||||||
|
{
|
||||||
|
auto duration = m_time.utc_time() - unix_epoch;
|
||||||
|
auto secs = duration.ticks();
|
||||||
|
secs /= ticks_per_second;
|
||||||
|
return secs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =================== Presentation-class Implementations ====================*/
|
/* =================== Presentation-class Implementations ====================*/
|
||||||
@ -114,4 +123,8 @@ GncDateTime::now()
|
|||||||
{
|
{
|
||||||
m_impl->now();
|
m_impl->now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GncDateTime::operator time64() const
|
||||||
|
{
|
||||||
|
return m_impl->operator time64();
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ public:
|
|||||||
GncDateTime(time64 time);
|
GncDateTime(time64 time);
|
||||||
~GncDateTime();
|
~GncDateTime();
|
||||||
void now();
|
void now();
|
||||||
|
explicit operator time64() const;
|
||||||
bool isnull (void) { return m_impl == nullptr; }
|
bool isnull (void) { return m_impl == nullptr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -40,12 +40,13 @@ TEST(gnc_date_constructors, test_ymd_constructor)
|
|||||||
TEST(gnc_datetime_constructors, test_default_constructor)
|
TEST(gnc_datetime_constructors, test_default_constructor)
|
||||||
{
|
{
|
||||||
GncDateTime atime;
|
GncDateTime atime;
|
||||||
EXPECT_FALSE(atime.isnull());
|
EXPECT_EQ(static_cast<time64>(atime), static_cast<time64>(INT64_C(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(gnc_datetime_constructors, test_time64_constructor)
|
TEST(gnc_datetime_constructors, test_time64_constructor)
|
||||||
{
|
{
|
||||||
const time64 time = 2394187200; //2045-11-13 12:00:00 Z
|
const time64 time = 2394187200; //2045-11-13 12:00:00 Z
|
||||||
GncDateTime atime(time);
|
GncDateTime atime(time);
|
||||||
EXPECT_FALSE(atime.isnull());
|
EXPECT_EQ(static_cast<time64>(atime), time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user