// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp
+#include <fmt/chrono.h>
#include <string.h>
#include <iostream>
#include <map>
// cond format header
if (expiration_date && rule_id) {
- // Fri, 23 Dec 2012 00:00:00 GMT
- char exp_buf[100];
- time_t exp = ceph::real_clock::to_time_t(*expiration_date);
- if (std::strftime(exp_buf, sizeof(exp_buf),
- "%a, %d %b %Y %T %Z", std::gmtime(&exp))) {
- hdr = fmt::format("expiry-date=\"{0}\", rule-id=\"{1}\"", exp_buf,
- *rule_id);
- } else {
- ldpp_dout(dpp, 0) << __func__ <<
- "() strftime of life cycle expiration header failed"
- << dendl;
- }
+ auto exp = ceph::real_clock::to_time_t(*expiration_date);
+ // Fri, 21 Dec 2012 00:00:00 GMT
+ auto exp_str = fmt::format("{:%a, %d %b %Y %T %Z}", fmt::gmtime(exp));
+ hdr = fmt::format("expiry-date=\"{0}\", rule-id=\"{1}\"", exp_str,
+ *rule_id);
}
return hdr;
#include <gtest/gtest.h>
#include <string>
#include <vector>
+#include <chrono>
#include <stdexcept>
static const char* xmldoc_1 =
ASSERT_EQ(filter.get_flags(), uint32_t(LCFlagType::none));
}
+TEST(ExpHdr, ReplaceStrftime)
+{
+ using namespace std::chrono;
+
+ constexpr auto dec21 = year(2012)/12/21;
+ auto exp = sys_days(dec21) + 9h + 13min + 7s ;
+ auto exp_str = fmt::format("{:%a, %d %b %Y %T %Z}", fmt::gmtime(exp));
+ std::cout << "exp_str: " << exp_str << std::endl;
+ ASSERT_EQ(exp_str, "Fri, 21 Dec 2012 09:13:07 GMT");
+}
+
struct LCWorkTimeTests : ::testing::Test
{
CephContext* cct;