mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-02 20:30:11 +01:00
parent
cafd56a947
commit
6a97657df8
@ -20,6 +20,7 @@
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include <chrono>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -47,6 +48,11 @@ public:
|
||||
Timespan(const Timespan& timespan);
|
||||
/// Creates a Timespan from another one.
|
||||
|
||||
template <class T, class Period>
|
||||
Timespan(const std::chrono::duration<T, Period>& dtime) :
|
||||
_span(std::chrono::duration_cast<std::chrono::microseconds>(dtime).count()) {}
|
||||
/// Creates a Timespan from std::chrono::duration
|
||||
|
||||
~Timespan();
|
||||
/// Destroys the Timespan.
|
||||
|
||||
@ -63,6 +69,14 @@ public:
|
||||
/// Assigns a new span. Useful for assigning
|
||||
/// from a struct timeval.
|
||||
|
||||
template <class T, class Period>
|
||||
Timespan& assign(const std::chrono::duration<T, Period>& dtime)
|
||||
/// Assigns a new span from std::chrono::duration.
|
||||
{
|
||||
_span = std::chrono::duration_cast<std::chrono::microseconds>(dtime).count();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(Timespan& timespan);
|
||||
/// Swaps the Timespan with another one.
|
||||
|
||||
|
@ -70,6 +70,10 @@ void TimespanTest::testConversions()
|
||||
assertTrue (ts.minutes() == 30);
|
||||
assertTrue (ts.hours() == 12);
|
||||
assertTrue (ts.days() == 1);
|
||||
|
||||
ts.assign(std::chrono::minutes(62));
|
||||
assertTrue(ts.hours() == 1);
|
||||
assertTrue(ts.minutes() == 2);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user