]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: utility function to dump iso8601
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 19 Aug 2016 11:39:06 +0000 (04:39 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 7 Oct 2016 17:31:22 +0000 (10:31 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_rest.cc

index ffe34094a648ab1ea96c899ef450385a1e6aef91..50c3b90b7d3adb101c2acf41f9101b4a908fb0bc 100644 (file)
@@ -474,6 +474,32 @@ int parse_time(const char *time_str, real_time *time)
   return 0;
 }
 
+#define TIME_BUF_SIZE 128
+
+void rgw_to_iso8601(const real_time& t, char *dest, int buf_size)
+{
+  utime_t ut(t);
+
+  char buf[TIME_BUF_SIZE];
+  struct tm result;
+  time_t epoch = ut.sec();
+  struct tm *tmp = gmtime_r(&epoch, &result);
+  if (tmp == NULL)
+    return;
+
+  if (strftime(buf, sizeof(buf), "%Y-%m-%dT%T", tmp) == 0)
+    return;
+
+  snprintf(dest, buf_size, "%s.%03dZ", buf, (int)(ut.usec() / 1000));
+}
+
+void rgw_to_iso8601(const real_time& t, string *dest)
+{
+  char buf[TIME_BUF_SIZE];
+  rgw_to_iso8601(t, buf, sizeof(buf));
+  *dest = buf;
+}
+
 /*
  * calculate the sha1 value of a given msg and key
  */
index 42a1ec821987266a12180e7370e397d5f5efa6b9..96c03a4eb874a5cba5578924555b2f4bb8926901 100644 (file)
@@ -1914,6 +1914,8 @@ extern bool parse_iso8601(const char *s, struct tm *t, uint32_t *pns = NULL, boo
 extern string rgw_trim_whitespace(const string& src);
 extern string rgw_trim_quotes(const string& val);
 
+extern void rgw_to_iso8601(const real_time& t, char *dest, int buf_size);
+extern void rgw_to_iso8601(const real_time& t, string *dest);
 
 /** Check if the req_state's user has the necessary permissions
  * to do the requested action */
index 06da365b6842d9abf51b1f9ec7f83372af7f303d..20b846e65d406d72dcf04024ecf5107ee2ef0bd6 100644 (file)
@@ -527,22 +527,10 @@ void dump_epoch_header(struct req_state *s, const char *name, real_time t)
 
 void dump_time(struct req_state *s, const char *name, real_time *t)
 {
-  utime_t ut(*t);
-
   char buf[TIME_BUF_SIZE];
-  struct tm result;
-  time_t epoch = ut.sec();
-  struct tm *tmp = gmtime_r(&epoch, &result);
-  if (tmp == NULL)
-    return;
-
-  if (strftime(buf, sizeof(buf), "%Y-%m-%dT%T", tmp) == 0)
-    return;
-
-  char buf2[TIME_BUF_SIZE];
-  snprintf(buf2, sizeof(buf2), "%s.%03dZ", buf, (int)(ut.usec() / 1000));
+  rgw_to_iso8601(*t, buf, sizeof(buf));
 
-  s->formatter->dump_string(name, buf2);
+  s->formatter->dump_string(name, buf);
 }
 
 void dump_owner(struct req_state *s, rgw_user& id, string& name,