31 lines
1.1 KiB
C++
31 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
#include <optional>
|
|
#include <chrono>
|
|
|
|
class Utils {
|
|
public:
|
|
// Safe conversions with fallback
|
|
static int optionalStoiOrDefault(const std::unordered_map<std::string, std::string>& row,
|
|
const std::string& key, int def = -1);
|
|
static double optionalStodOrDefault(const std::unordered_map<std::string, std::string>& row,
|
|
const std::string& key, double def = 0.0);
|
|
|
|
static bool isNullOrEmpty(const std::string& s);
|
|
|
|
// Parse timestamp from common ISO / SQL formats into time_point
|
|
static std::optional<std::chrono::system_clock::time_point> parseTimestamp(const std::string& iso);
|
|
|
|
// Compute full years age from birthdate string; returns nullopt on parse failure.
|
|
static std::optional<int> computeAgeYears(const std::string& birthdate_iso);
|
|
|
|
// Build Postgres integer array literal "{1,2,3}"
|
|
static std::string buildPgIntArrayLiteral(const std::vector<int>& elems);
|
|
|
|
// Safely parse a nullable integer-like string
|
|
static std::optional<int> optionalUid(const std::string& val);
|
|
};
|