27 #if defined _SYSTEM_LXRT_ 32 #if defined(_IC_BUILDER_BOOST_DATE_TIME_) 33 #include "boost/date_time/posix_time/posix_time.hpp" 34 #include "boost/date_time/posix_time/posix_time_types.hpp" 37 #ifdef _IC_BUILDER_OPENSPLICEDDS_ 38 # include <ccpp_dds_dcps.h> 39 # include "icl_core/iTimeStamp.h" 46 #ifdef _IC_BUILDER_OPENSPLICEDDS_ 48 : TimeBase(time_stamp.sec, time_stamp.nanosec)
53 : TimeBase(time_stamp.sec, time_stamp.nsec)
57 TimeStamp& TimeStamp::operator = (
const DDS::Time_t& time_stamp)
59 secs = time_stamp.sec;
60 nsecs = time_stamp.nanosec;
64 TimeStamp& TimeStamp::operator = (
const iTimeStamp& time_stamp)
66 secs = time_stamp.sec;
67 nsecs = time_stamp.nsec;
71 TimeStamp::operator DDS::Time_t ()
75 result.nanosec =
nsecs;
79 TimeStamp::operator iTimeStamp ()
88 #if defined(_IC_BUILDER_BOOST_DATE_TIME_) 91 boost::posix_time::ptime unix_time_base(boost::gregorian::date(1970, 1, 1));
93 secs = boost::posix_time::time_period(unix_time_base, ptime_stamp).length().total_seconds();
94 nsecs =
int32_t(boost::posix_time::time_period(unix_time_base, ptime_stamp).
95 length().total_nanoseconds());
99 TimeStamp& TimeStamp::operator = (
const boost::posix_time::ptime& ptime_stamp)
101 boost::posix_time::ptime unix_time_base(boost::gregorian::date(1970, 1, 1));
103 secs = boost::posix_time::time_period(unix_time_base, ptime_stamp).length().total_seconds();
104 nsecs =
int32_t(boost::posix_time::time_period(unix_time_base, ptime_stamp).
105 length().total_nanoseconds());
135 tm_year = boost::lexical_cast<
int32_t>(str.substr(0,4));
139 tm_mon = boost::lexical_cast<
int32_t>(str.substr(4,2));
143 tm_mday = boost::lexical_cast<
int32_t>(str.substr(6,2));
146 if (str.size() >= 11)
148 tm_hour = boost::lexical_cast<
int32_t>(str.substr(9,2));
150 if (str.size() >= 13)
152 tm_min = boost::lexical_cast<
int32_t>(str.substr(11,2));
154 if (str.size() >= 15)
156 tm_sec = boost::lexical_cast<
int32_t>(str.substr(13,2));
162 std::string nsec_str = (str.substr(16, 9) +
"000000000").substr(0, 9);
163 nsecs = boost::lexical_cast<
int32_t>(nsec_str);
168 for (
int32_t y = 1970; y < tm_year; ++y)
170 bool leap_year = (y % 400 == 0
173 days_since_epoch += leap_year ? 366 : 365;
176 bool leap_year = (tm_year % 400 == 0
178 && tm_year % 100 != 0));
179 int32_t days_per_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
182 days_per_month[1] = 29;
184 for (
int32_t m = 1; m < tm_mon; ++m)
186 days_since_epoch += days_per_month[m-1];
189 days_since_epoch += tm_mday-1;
190 uint64_t secs = 86400 * days_since_epoch + 3600*tm_hour + 60*tm_min + tm_sec;
205 time_t time =
tsSec();
207 newtime = gmtime(&time);
208 strftime(dest, max_len, format, newtime);
213 time_t time =
tsSec();
214 struct tm *newtime = localtime(&time);
217 strftime(dest, max_len, format, newtime);
223 char date_time_sec[20];
225 return String(date_time_sec);
230 char date_time_sec[20];
231 strfTime(date_time_sec, 20,
"%Y-%m-%d %H:%M:%S");
232 return String(date_time_sec);
237 char date_time_sec[16], date_time_nsec[10];
239 while (adjust_nsec.
nsecs < 0)
242 adjust_nsec.
nsecs += 1000000000;
244 adjust_nsec.
strfLocaltime(date_time_sec, 16,
"%Y%m%dT%H%M%S");
246 return String(date_time_sec) +
"," +
String(date_time_nsec);
251 char date_time_sec[16], date_time_nsec[10];
253 while (adjust_nsec.
nsecs < 0)
256 adjust_nsec.
nsecs += 1000000000;
258 adjust_nsec.
strfTime(date_time_sec, 16,
"%Y%m%dT%H%M%S");
260 return String(date_time_sec) +
"," +
String(date_time_nsec);
264 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 291 void TimeStamp::Strftime(
char* dest,
size_t max_len,
const char *format)
const 296 void TimeStamp::StrfLocaltime(
char* dest,
size_t max_len,
const char *format)
const 301 String TimeStamp::FormatIso8601()
const TimeStamp & fromNow()
Set the timestamp to the current system time.
Represents absolute times.
String formatIso8601UTC() const
void strfLocaltime(char *dest, size_t max_len, const char *format) const
unsigned __int64 uint64_t
String formatIso8601BasicUTC() const
static TimeStamp futureMSec(uint64_t msec)
Returns a time stamp which lies msec ms in the future.
void strfTime(char *dest, size_t max_len, const char *format) const
Contains global functions, encapsulated into the icl_core::os namespace.
static const TimeStamp cZERO
static TimeStamp fromIso8601BasicUTC(const String &str)
TimeStamp & operator+=(const TimeSpan &span)
Adds a TimeSpan.
String formatIso8601Basic() const
TimeStamp()
Standard constructor, creates a null time.
void gettimeofday(struct timespec *time)
String formatIso8601() const
static TimeStamp maxTime()
void fromTimespec(const struct timespec &time)
int snprintf(char *buffer, size_t maxlen, const char *format,...)