PragmaTwice commented on code in PR #2822:
URL: https://github.com/apache/kvrocks/pull/2822#discussion_r1986519164


##########
src/commands/cmd_server.cc:
##########
@@ -1006,12 +1008,42 @@ static uint64_t GenerateConfigFlag(uint64_t flags, 
const std::vector<std::string
 
 class CommandLastSave : public Commander {
  public:
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+    if (args.size() > 2) {
+      return {Status::RedisParseErr, "unknown extra arguments"};
+    }
+    while (parser.Good()) {
+      if (parser.EatEqICase("iso8601")) {
+        format_spec_ = true;
+      } else {
+        return {Status::RedisParseErr, "unknown arguments"};
+      }
+    }
+
+    return Status::OK();
+  }
   Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv, 
[[maybe_unused]] Connection *conn,
                  std::string *output) override {
     int64_t unix_sec = srv->GetLastBgsaveTime();
-    *output = redis::Integer(unix_sec);
+    if (format_spec_) {
+      time_t raw_time = static_cast<time_t>(unix_sec);
+      struct tm local_time;
+      if (localtime_r(&raw_time, &local_time)) {
+        char buf[100];
+        strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", &local_time);
+        *output = redis::BulkString(buf);
+      } else {
+        *output = redis::Error({Status::NotOK, "unable to convert timestamp to 
local time"});

Review Comment:
   ```suggestion
           return {Status::NotOK, "unable to convert timestamp to local time"};
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to