implement utils::current_date() convenience function to reduce replicated code

This commit is contained in:
Axel Kohlmeyer
2021-09-18 09:05:35 -04:00
parent 5a6c1abeed
commit db76edbade
9 changed files with 64 additions and 49 deletions

View File

@ -18,6 +18,7 @@
#include "compute.h"
#include "error.h"
#include "fix.h"
#include "fmt/chrono.h"
#include "memory.h"
#include "modify.h"
#include "text_file_reader.h"
@ -27,6 +28,7 @@
#include <cctype>
#include <cerrno>
#include <cstring>
#include <ctime>
#if defined(__linux__)
#include <unistd.h> // for readlink
@ -1316,7 +1318,21 @@ int utils::date2num(const std::string &date)
return num;
}
/* binary search in vector of ascending doubles */
/* ----------------------------------------------------------------------
get formatted string of current date from fmtlib
------------------------------------------------------------------------- */
std::string utils::current_date()
{
time_t tv = time(nullptr);
std::tm today = fmt::localtime(tv);
return fmt::format("{:%Y-%m-%d}", today);
}
/* ----------------------------------------------------------------------
binary search in vector of ascending doubles
------------------------------------------------------------------------- */
int utils::binary_search(const double needle, const int n, const double *haystack)
{
int lo = 0;