Skip to content

Commit

Permalink
Use ms for ISO8601
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed May 25, 2023
1 parent cfb560f commit 8588609
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions libs/indibase/indiccd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <libnova/ln_types.h>
#include <libastro.h>

#include <iomanip>
#include <cmath>
#include <regex>
#include <iterator>
Expand Down Expand Up @@ -2543,14 +2544,18 @@ bool CCD::uploadFile(CCDChip * targetChip, const void * fitsData, size_t totalBy

if (maxIndex > 0)
{
char ts[32];
struct tm * tp;
time_t t;
time(&t);
tp = localtime(&t);
strftime(ts, sizeof(ts), "%Y-%m-%dT%H-%M-%S", tp);
std::string filets(ts);
prefix = std::regex_replace(prefix, std::regex("ISO8601"), filets);
auto now = std::chrono::system_clock::now();
std::time_t time = std::chrono::system_clock::to_time_t(now);
std::tm* now_tm = std::localtime(&time);
long long timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();

std::stringstream stream;
stream << std::setfill('0')
<< std::put_time(now_tm, "%FT%H:%M:")
<< std::setw(2) << (timestamp / 1000) % 60 << '.'
<< std::setw(3) << timestamp % 1000;

prefix = std::regex_replace(prefix, std::regex("ISO8601"), stream.str());

char indexString[8];
snprintf(indexString, 8, "%03d", maxIndex);
Expand Down

0 comments on commit 8588609

Please sign in to comment.