Quantum 3xplorer (Q3)
An AI-native quantum simulation engine
Loading...
Searching...
No Matches
time.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * ISO 8601 timestamp utility with timezone offset.
5 */
6
7#include <cctype>
8#include <chrono>
9#include <ctime>
10#include <iomanip>
11#include <sstream>
12#include <string>
13
14namespace q3 {
15
16/**
17 * Return the current local time as an ISO 8601 string with timezone offset.
18 *
19 * Example output: "2026-06-18T15:30:45-07:00"
20 */
21inline std::string get_iso_timestamp_with_timezone() {
22 auto current_time = std::chrono::system_clock::now();
23 std::time_t calendar_time = std::chrono::system_clock::to_time_t(current_time);
24 std::ostringstream timestamp_stream;
25 timestamp_stream << std::put_time(std::localtime(&calendar_time), "%Y-%m-%dT%H:%M:%S%z");
26 std::string timestamp_string = timestamp_stream.str();
27
28 if (timestamp_string.length() >= 5) {
29 std::string timezone_offset = timestamp_string.substr(timestamp_string.length() - 5);
30 if ((timezone_offset[0] == '+' || timezone_offset[0] == '-') &&
31 std::isdigit(timezone_offset[1]) && std::isdigit(timezone_offset[2]) &&
32 std::isdigit(timezone_offset[3]) && std::isdigit(timezone_offset[4])) {
33 timestamp_string = timestamp_string.substr(0, timestamp_string.length() - 2) + ":" +
34 timestamp_string.substr(timestamp_string.length() - 2);
35 }
36 }
37 return timestamp_string;
38}
39
40} // namespace q3
std::string get_iso_timestamp_with_timezone()
Definition time.hpp:21