mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-03-24 08:41:40 -04:00
refactor: move format_absolute_time_iso8601 from zm_monitor_onvif to zm_time
Move the ISO 8601 time formatting function to zm_time.cpp/h so it is reusable and not duplicated. Remove the local copies from zm_monitor_onvif.cpp (was static) and tests/zm_onvif_renewal.cpp (was a copy for testing). Both now use the shared declaration from zm_time.h. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "zm_monitor_onvif.h"
|
||||
#include "zm_monitor.h"
|
||||
#include "zm_signal.h"
|
||||
#include "zm_time.h"
|
||||
#include "zm_utils.h"
|
||||
|
||||
#include <cstring>
|
||||
@@ -1029,19 +1030,6 @@ void ONVIF::log_subscription_timing(const char* context) {
|
||||
}
|
||||
|
||||
|
||||
// Format an absolute time as ISO 8601 string for ONVIF RenewRequest
|
||||
// Returns a string like "2026-01-13T15:30:45.000Z"
|
||||
std::string format_absolute_time_iso8601(time_t time) {
|
||||
struct tm *tm_utc = gmtime(&time);
|
||||
if (!tm_utc) {
|
||||
return "";
|
||||
}
|
||||
|
||||
char buffer[32];
|
||||
strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S.000Z", tm_utc);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
// Perform ONVIF subscription renewal
|
||||
// Returns true if renewal succeeded or is not supported, false on error
|
||||
bool ONVIF::Renew() {
|
||||
|
||||
@@ -67,6 +67,17 @@ std::string TimePointToString(TimePoint tp) {
|
||||
return timeString;
|
||||
}
|
||||
|
||||
std::string format_absolute_time_iso8601(time_t time) {
|
||||
struct tm *tm_utc = gmtime(&time);
|
||||
if (!tm_utc) {
|
||||
return "";
|
||||
}
|
||||
|
||||
char buffer[32];
|
||||
strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S.000Z", tm_utc);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
SystemTimePoint StringToSystemTimePoint(const std::string ×tamp) {
|
||||
std::tm t{};
|
||||
strptime(timestamp.c_str(), "%Y-%m-%d %H:%M:%S", &t);
|
||||
|
||||
@@ -121,6 +121,7 @@ class TimeSegmentAdder {
|
||||
bool finished_;
|
||||
};
|
||||
|
||||
std::string format_absolute_time_iso8601(time_t time);
|
||||
std::string SystemTimePointToString(SystemTimePoint tp);
|
||||
std::string SystemTimePointToMysqlString(SystemTimePoint tp);
|
||||
std::string TimePointToString(TimePoint tp);
|
||||
|
||||
@@ -150,20 +150,6 @@ TEST_CASE("ONVIF Subscription Cleanup Logic") {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function from zm_monitor_onvif.cpp for testing
|
||||
// Format an absolute time as ISO 8601 string for ONVIF RenewRequest
|
||||
// Returns a string like "2026-01-13T15:30:45.000Z"
|
||||
std::string format_absolute_time_iso8601(time_t time) {
|
||||
struct tm *tm_utc = gmtime(&time);
|
||||
if (!tm_utc) {
|
||||
return "";
|
||||
}
|
||||
|
||||
char buffer[32];
|
||||
strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S.000Z", tm_utc);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
// Test the ISO 8601 absolute time formatting for ONVIF renewal requests
|
||||
TEST_CASE("ONVIF Absolute Time Formatting") {
|
||||
SECTION("Format known timestamp as ISO 8601") {
|
||||
|
||||
Reference in New Issue
Block a user