slsDetectorPackage/python/src/DurationWrapper.cpp
Erik Fröjdh 045a28b5de
Nanosecond times in Python (#522)
* initital implementation

* datetime replaces with sls::Duration in Python C bindings

* using custom type caster

* fix for conversion to seconds

* added set_count in python

* common header for pybind11 includes

authored-by: Erik Frojdh <erik.frojdh@psi.ch>
2022-08-26 11:48:40 +02:00

26 lines
562 B
C++

#include "DurationWrapper.h"
#include <cmath>
namespace sls{
DurationWrapper::DurationWrapper(double seconds){
ns_tick = std::round(seconds*1e9);
}
uint64_t DurationWrapper::count() const{
return ns_tick;
}
void DurationWrapper::set_count(uint64_t ns_count){
ns_tick = ns_count;
}
bool DurationWrapper::operator==(const DurationWrapper& other)const{
return ns_tick == other.ns_tick;
}
double DurationWrapper::total_seconds()const{
return static_cast<double>(ns_tick)/1e9;
}
}