Add Timestamp::EncodeStringWithOffset() for representation outside of UTC.
authormsheby <msheby@cinecert.com>
Mon, 6 Apr 2009 07:18:14 +0000 (07:18 +0000)
committermsheby <>
Mon, 6 Apr 2009 07:18:14 +0000 (07:18 +0000)
src/KM_util.cpp
src/KM_util.h

index 953159c2ca719ab936b9ee631226e22820175ca2..ba27a37c5d6bffc554343d1a801c517ad2beef03 100755 (executable)
@@ -952,15 +952,42 @@ Kumu::Timestamp::operator!=(const Timestamp& rhs) const
 // 
 const char*
 Kumu::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const
+{
+  return EncodeStringWithOffset(str_buf, buf_len, 0);
+}
+
+// 
+const char*
+Kumu::Timestamp::EncodeStringWithOffset(char* str_buf, ui32_t buf_len,
+                                       i32_t offset_minutes) const
 {
   if ( buf_len < ( DateTimeLen + 1 ) )
     return 0;
 
-  // 2004-05-01T13:20:00-00:00
+  // ensure offset is within +/- 14 hours
+  if ((offset_minutes < -14 * 60) || (offset_minutes > 14 * 60))
+    return 0;
+
+  // set the apparent time
+  Kumu::Timestamp tmp_t(*this);
+  tmp_t.AddMinutes(offset_minutes);
+
+  char direction = '+';
+  if (offset_minutes < 0) {
+    direction = '-';
+    // need absolute offset from zero
+    offset_minutes = -offset_minutes;
+  }
+
+  // 2004-05-01T13:20:00+00:00
   snprintf(str_buf, buf_len,
-          "%04hu-%02hu-%02huT%02hu:%02hu:%02hu+00:00",
-          Year, Month, Day, Hour, Minute, Second);
-  
+          "%04hu-%02hu-%02huT%02hu:%02hu:%02hu%c%02hu:%02hu",
+          tmp_t.Year, tmp_t.Month, tmp_t.Day,
+          tmp_t.Hour, tmp_t.Minute, tmp_t.Second,
+          direction,
+          offset_minutes / 60,
+          offset_minutes % 60);
+
   return str_buf;
 }
 
index 8dd573f2e247ad569189ecc781f0158a247bd85a..7318de82f5f34b68f5060e3ce2ffaf3858aee929 100755 (executable)
@@ -390,6 +390,8 @@ namespace Kumu
       // Write the timestamp value to the given buffer in the form 2004-05-01T13:20:00+00:00
       // returns 0 if the buffer is smaller than DateTimeLen
       const char* EncodeString(char* str_buf, ui32_t buf_len) const;
+      const char* EncodeStringWithOffset(char* str_buf, ui32_t buf_len,
+                                        i32_t offset_minutes = 0) const;
 
       // decode and set value from string formatted by EncodeString
       bool        DecodeString(const char* datestr);