From 7c73095012edaee669f281c1791a72eaa224a28c Mon Sep 17 00:00:00 2001 From: istvans Date: Tue, 9 Apr 2024 10:35:58 +0200 Subject: [PATCH] Add microseconds to BUFR message --- ingest/src/ingest/bufr/ESOHBufr.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ingest/src/ingest/bufr/ESOHBufr.cpp b/ingest/src/ingest/bufr/ESOHBufr.cpp index 6b6316fb..889349bb 100644 --- a/ingest/src/ingest/bufr/ESOHBufr.cpp +++ b/ingest/src/ingest/bufr/ESOHBufr.cpp @@ -82,11 +82,16 @@ std::list ESOHBufr::msg() const { // pubtime rapidjson::Value pubtime; { - time_t pubtime_value = time(0); + struct timeval tv; + gettimeofday(&tv, 0); const int date_len = 50; char date_str[date_len]; - size_t dl = - strftime(date_str, date_len, "%FT%H:%M:%S%z", gmtime(&pubtime_value)); + size_t dl = strftime(date_str, date_len, "%FT%H:%M:%S.000000%z", + gmtime(&(tv.tv_sec))); + char usec[8]; + sprintf(usec, "%06ld", tv.tv_usec); + // Copy microseconds into the date char string + memcpy(date_str + 20, usec, 6); pubtime.SetString(date_str, static_cast(dl), message_allocator); } @@ -858,7 +863,8 @@ bool ESOHBufr::setDateTime(struct tm *meas_datetime, const int date_len = 50; char date_str[date_len]; - size_t dl = strftime(date_str, date_len, "%FT%H:%M:%S%z", meas_datetime); + size_t dl = + strftime(date_str, date_len, "%FT%H:%M:%S.000000%z", meas_datetime); datetime.SetString(date_str, static_cast(dl), message_allocator); @@ -882,7 +888,7 @@ bool ESOHBufr::setStartDateTime(struct tm *start_meas_datetime, const int date_len = 50; char date_str[date_len]; size_t dl = - strftime(date_str, date_len, "%FT%H:%M:%S%z", start_meas_datetime); + strftime(date_str, date_len, "%FT%H:%M:%S.000000%z", start_meas_datetime); start_datetime.SetString(date_str, static_cast(dl), message_allocator);