[gnote] Fix a bug in printing date/time values with 0 micro-second (Closes #581844)



commit bf3025759c8092ea8417b6d812f974a01a9c01be
Author: Hubert Figuiere <hub figuiere net>
Date:   Mon Jun 15 13:17:27 2009 -0400

    Fix a bug in printing date/time values with 0 micro-second (Closes #581844)

 NEWS                   |    2 ++
 src/sharp/datetime.cpp |    6 ++++++
 src/sharp/datetime.hpp |    4 ++++
 src/test/dttest.cpp    |    7 +++++++
 4 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 1ec9c53..313c900 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,8 @@ Fixes:
     (Closes #582789) (Yves Junqueira)
   * Enable/disable spellchecking when the preferences are changed. 
     (Closes #582242)
+  * Fix a bug in printing date/time values with 0 micro-second
+    (Closes #581844)
 
 Translations:
 
diff --git a/src/sharp/datetime.cpp b/src/sharp/datetime.cpp
index 82dadb8..6c818b5 100644
--- a/src/sharp/datetime.cpp
+++ b/src/sharp/datetime.cpp
@@ -114,6 +114,12 @@ namespace sharp {
     char *  iso8601 = g_time_val_to_iso8601(const_cast<GTimeVal*>(&m_date));
     if(iso8601) {
       retval = iso8601;
+      if(m_date.tv_usec == 0) {
+        // see http://bugzilla.gnome.org/show_bug.cgi?id=581844
+        // when usec is 0, glib/libc does NOT add the usec values
+        // to the output
+        retval.insert(19, ".000000");
+      }
       g_free(iso8601);
     }
     return retval;
diff --git a/src/sharp/datetime.hpp b/src/sharp/datetime.hpp
index 9cd7efc..2110638 100644
--- a/src/sharp/datetime.hpp
+++ b/src/sharp/datetime.hpp
@@ -74,6 +74,10 @@ public:
     {
       return m_date.tv_usec;
     }
+  void set_usec(glong _usec) 
+    {
+      m_date.tv_usec = _usec;
+    }
 private:
   // return the string formatted according to strftime
   std::string _to_string(const char * format, struct tm *) const;
diff --git a/src/test/dttest.cpp b/src/test/dttest.cpp
index d59e118..f204b36 100644
--- a/src/test/dttest.cpp
+++ b/src/test/dttest.cpp
@@ -41,6 +41,13 @@ int test_main(int /*argc*/, char ** /*argv*/)
   sharp::DateTime d3 = sharp::DateTime::from_iso8601("2009-03-24T03:34:35.2914680-04:00");
   BOOST_CHECK(d3.is_valid());
 
+  // check when usec is 0.
+  // see http://bugzilla.gnome.org/show_bug.cgi?id=581844
+  d3.set_usec(0);
+
+  date_string = sharp::XmlConvert::to_string(d3);
+  BOOST_CHECK(date_string == "2009-03-24T07:34:35.000000Z");
+
   return 0;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]