Replace boost::scoped_ptr with std::unique_ptr.
[cumulus.git] / util.h
diff --git a/util.h b/util.h
index c6c6f9e..b55320e 100644 (file)
--- a/util.h
+++ b/util.h
@@ -27,6 +27,9 @@
 #include <map>
 #include <string>
 
+std::string string_printf(const char *fmt, ...)
+    __attribute__((format(printf, 1, 2)));
+
 std::string uri_encode(const std::string &in);
 std::string uri_decode(const std::string &in);
 std::string encode_int(long long n, int base=10);
@@ -36,4 +39,25 @@ void cloexec(int fd);
 
 void fatal(std::string msg) __attribute__((noreturn));
 
+/* Date/time string formatting and parsing utility functions.  All data and
+ * methods are static, so this class should not be instantiated. */
+class TimeFormat {
+public:
+    // Abbreviated time format encoded in snapshot file names.
+    static const char FORMAT_FILENAME[];
+    // A timestamp, in UTC, written out in an ISO 8601 format (compatible with
+    // the SQLite datetime function).
+    static const char FORMAT_ISO8601[];
+    // Similar to the above, but including a timezone offset.
+    static const char FORMAT_LOCALTIME[];
+
+    static std::string format(time_t timestamp, const char *format, bool utc);
+
+    static std::string isoformat(time_t timestamp)
+        { return format(timestamp, FORMAT_ISO8601, true); }
+
+private:
+    TimeFormat() { }
+};
+
 #endif // _LBS_TARSTORE_H