summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-12-14 23:10:33 +0000
committerChris Wilson <chris+github@qwirx.com>2006-12-14 23:10:33 +0000
commitc4ab10fda1d44778a904303ccd56f8f9c3f8bc54 (patch)
treebf456105e7a765cae49acd3dd056d34627beb10f /lib/common
parentc04c61f9374176d606d9d5a3c34a708320f8deb8 (diff)
Add option to bbackupquery list command to show times in UTC or local time
(merges [1036])
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/BoxTimeToText.cpp38
-rw-r--r--lib/common/BoxTimeToText.h2
2 files changed, 27 insertions, 13 deletions
diff --git a/lib/common/BoxTimeToText.cpp b/lib/common/BoxTimeToText.cpp
index ff8b2e49..dbeefe1b 100644
--- a/lib/common/BoxTimeToText.cpp
+++ b/lib/common/BoxTimeToText.cpp
@@ -20,23 +20,31 @@
// --------------------------------------------------------------------------
//
// Function
-// Name: BoxTimeToISO8601String(box_time_t)
-// Purpose: Convert a 64 bit box time to a ISO 8601 complient string
+// Name: BoxTimeToISO8601String(box_time_t, bool)
+// Purpose: Convert a 64 bit box time to a ISO 8601 compliant
+// string, either in local or UTC time
// Created: 2003/10/10
//
// --------------------------------------------------------------------------
-std::string BoxTimeToISO8601String(box_time_t Time)
+std::string BoxTimeToISO8601String(box_time_t Time, bool localTime)
{
+ time_t timeInSecs = BoxTimeToSeconds(Time);
+ char str[128]; // more than enough space
+
#ifdef WIN32
struct tm *time;
- time_t bob = BoxTimeToSeconds(Time);
+ __time64_t winTime = timeInSecs;
- __time64_t winTime = bob;
+ if(localTime)
+ {
+ time = _localtime64(&winTime);
+ }
+ else
+ {
+ time = _gmtime64(&winTime);
+ }
- time = _gmtime64(&winTime);
- char str[128]; // more than enough space
-
- if ( time == NULL )
+ if(time == NULL)
{
// ::sprintf(str, "%016I64x ", bob);
return std::string("unable to convert time");
@@ -46,11 +54,17 @@ std::string BoxTimeToISO8601String(box_time_t Time)
time->tm_mon + 1, time->tm_mday, time->tm_hour,
time->tm_min, time->tm_sec);
#else // ! WIN32
- time_t timeInSecs = BoxTimeToSeconds(Time);
struct tm time;
- gmtime_r(&timeInSecs, &time);
+
+ if(localTime)
+ {
+ localtime_r(&timeInSecs, &time);
+ }
+ else
+ {
+ gmtime_r(&timeInSecs, &time);
+ }
- char str[128]; // more than enough space
sprintf(str, "%04d-%02d-%02dT%02d:%02d:%02d", time.tm_year + 1900,
time.tm_mon + 1, time.tm_mday, time.tm_hour,
time.tm_min, time.tm_sec);
diff --git a/lib/common/BoxTimeToText.h b/lib/common/BoxTimeToText.h
index a25c70b6..21fa5d57 100644
--- a/lib/common/BoxTimeToText.h
+++ b/lib/common/BoxTimeToText.h
@@ -13,7 +13,7 @@
#include <string>
#include "BoxTime.h"
-std::string BoxTimeToISO8601String(box_time_t Time);
+std::string BoxTimeToISO8601String(box_time_t Time, bool localTime);
#endif // BOXTIMETOTEXT__H