25 #ifndef SRC_TIME_TIMESTAMP_H_ 26 #define SRC_TIME_TIMESTAMP_H_ 28 #include "../quantity/IQuantity.h" 33 enum TimestampResolution { Second, Millisecond, Microsecond, Nanosecond };
35 TimestampResolution resolution;
39 this->resolution = TimestampResolution::Millisecond;
43 this->timestamp = ts_copy.timestamp;
44 this->resolution = ts_copy.resolution;
47 Timestamp(
long timestamp, TimestampResolution resolution) {
48 this->timestamp = timestamp;
49 this->resolution = resolution;
52 Timestamp(
double seconds, TimestampResolution resolution) {
53 this->resolution = resolution;
54 this->fromSeconds(seconds);
60 return this->timestamp;
63 void setTimestamp(
long new_timestamp) {
64 this->timestamp = new_timestamp;
67 void setResolution(TimestampResolution r) {
71 TimestampResolution getResolution() {
72 return this->resolution;
75 static const long MILLISECONDS_PER_SECOND = 1000;
76 static const long MICROSECONDS_PER_SECOND = MILLISECONDS_PER_SECOND * 1000;
77 static const long NANOSECONDS_PER_SECOND = MICROSECONDS_PER_SECOND * 1000;
78 static const long NANOSECONDS_PER_MICROSECOND = 1000;
79 static const long MICROSECONDS_PER_MILLISECOND = 1000;
80 static const long NANOSECONDS_PER_MILLISECOND = NANOSECONDS_PER_MICROSECOND * 1000;
82 long getNanoseconds() {
83 switch ( resolution ) {
85 return timestamp * NANOSECONDS_PER_SECOND;
87 return timestamp * NANOSECONDS_PER_MILLISECOND;
89 return timestamp * NANOSECONDS_PER_MICROSECOND;
96 long getMicroseconds() {
97 switch ( resolution ) {
99 return timestamp * MICROSECONDS_PER_SECOND;
101 return timestamp * MICROSECONDS_PER_MILLISECOND;
106 return timestamp / NANOSECONDS_PER_MICROSECOND;
110 long getMilliseconds() {
111 switch ( resolution ) {
113 return timestamp * MILLISECONDS_PER_SECOND;
118 return timestamp / MICROSECONDS_PER_MILLISECOND;
120 return timestamp / NANOSECONDS_PER_MILLISECOND;
124 double getSeconds() {
125 switch ( resolution ) {
127 return (
double)timestamp;
130 return ((
double)timestamp)/MILLISECONDS_PER_SECOND;
132 return ((
double)timestamp)/MICROSECONDS_PER_SECOND;
134 return ((
double)timestamp)/NANOSECONDS_PER_SECOND;
138 void fromSeconds(
double seconds) {
139 switch ( resolution ) {
141 timestamp = (long)seconds;
145 timestamp = (long)(seconds * MILLISECONDS_PER_SECOND);
148 timestamp = (long)(seconds * MICROSECONDS_PER_SECOND);
151 timestamp = (long)(seconds * NANOSECONDS_PER_SECOND);
157 bool getPrintableString(vector<string>& printable_string) {
158 printable_string.push_back(to_string(timestamp));
162 bool getContainedQuantities(vector<IQuantity *>& quantities) {
166 bool getContainedQuantityNames(vector<string>& quantity_names) {
Definition: IQuantity.h:33
Definition: Timestamp.h:30