File tree Expand file tree Collapse file tree 2 files changed +18
-12
lines changed
Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Original file line number Diff line number Diff line change 11// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
22// vim: ts=8 sw=2 smarttab ft=cpp
33
4+ #include < fmt/chrono.h>
45#include < string.h>
56#include < iostream>
67#include < map>
@@ -2821,18 +2822,11 @@ std::string s3_expiration_header(
28212822
28222823 // cond format header
28232824 if (expiration_date && rule_id) {
2824- // Fri, 23 Dec 2012 00:00:00 GMT
2825- char exp_buf[100 ];
2826- time_t exp = ceph::real_clock::to_time_t (*expiration_date);
2827- if (std::strftime (exp_buf, sizeof (exp_buf),
2828- " %a, %d %b %Y %T %Z" , std::gmtime (&exp))) {
2829- hdr = fmt::format (" expiry-date=\" {0}\" , rule-id=\" {1}\" " , exp_buf,
2830- *rule_id);
2831- } else {
2832- ldpp_dout (dpp, 0 ) << __func__ <<
2833- " () strftime of life cycle expiration header failed"
2834- << dendl;
2835- }
2825+ auto exp = ceph::real_clock::to_time_t (*expiration_date);
2826+ // Fri, 21 Dec 2012 00:00:00 GMT
2827+ auto exp_str = fmt::format (" {:%a, %d %b %Y %T %Z}" , fmt::gmtime (exp));
2828+ hdr = fmt::format (" expiry-date=\" {0}\" , rule-id=\" {1}\" " , exp_str,
2829+ *rule_id);
28362830 }
28372831
28382832 return hdr;
Original file line number Diff line number Diff line change 77#include < gtest/gtest.h>
88#include < string>
99#include < vector>
10+ #include < chrono>
1011#include < stdexcept>
1112
1213static const char * xmldoc_1 =
@@ -107,6 +108,17 @@ TEST(TestLCFilterInvalidAnd, XMLDoc3)
107108 ASSERT_EQ (filter.get_flags (), uint32_t (LCFlagType::none));
108109}
109110
111+ TEST (ExpHdr, ReplaceStrftime)
112+ {
113+ using namespace std ::chrono;
114+
115+ constexpr auto dec21 = year (2012 )/12 /21 ;
116+ auto exp = sys_days (dec21) + 9h + 13min + 7s ;
117+ auto exp_str = fmt::format (" {:%a, %d %b %Y %T %Z}" , fmt::gmtime (exp));
118+ std::cout << " exp_str: " << exp_str << std::endl;
119+ ASSERT_EQ (exp_str, " Fri, 21 Dec 2012 09:13:07 GMT" );
120+ }
121+
110122struct LCWorkTimeTests : ::testing::Test
111123{
112124 CephContext* cct;
You can’t perform that action at this time.
0 commit comments