[gnote] Remove sharp::DateTime



commit ed11adf2fa518e5d97f9f3555664f9c1cd3158d4
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Jan 26 17:38:35 2020 +0200

    Remove sharp::DateTime

 src/sharp/datetime.cpp | 173 -------------------------------------------------
 src/sharp/datetime.hpp |  77 ----------------------
 2 files changed, 250 deletions(-)
---
diff --git a/src/sharp/datetime.cpp b/src/sharp/datetime.cpp
index defdf0c6..17b6616c 100644
--- a/src/sharp/datetime.cpp
+++ b/src/sharp/datetime.cpp
@@ -34,179 +34,6 @@
 
 namespace sharp {
 
-#define SEC_PER_MINUTE 60
-#define SEC_PER_HOUR (SEC_PER_MINUTE * 60)
-#define SEC_PER_DAY (SEC_PER_HOUR * 24)
-
-  DateTime::DateTime()
-  {
-    m_date.tv_sec = -1;
-    m_date.tv_usec = -1;
-  }
-
-  DateTime::DateTime(time_t t, glong _usec)
-  {
-    m_date.tv_sec = t;
-    m_date.tv_usec = _usec;
-  }
-
-  DateTime::DateTime(const Glib::TimeVal & v)
-    : m_date(v)
-  {
-  }
-
-  DateTime & DateTime::add_days(int days)
-  {
-    m_date.tv_sec += (days * SEC_PER_DAY);
-    return *this;
-  }
-
-  DateTime & DateTime::add_hours(int hours)
-  {
-    m_date.tv_sec += (hours * SEC_PER_HOUR);
-    return *this;
-  }
-
-  DateTime & DateTime::add_seconds(int seconds)
-  {
-    m_date.add_seconds(seconds);
-    return *this;
-  }
-
-  int DateTime::day() const
-  {
-    struct tm result;
-    localtime_r((const time_t *)&m_date.tv_sec, &result);
-    return result.tm_mday;
-  }
-
-  int DateTime::month() const
-  {
-    struct tm result;
-    localtime_r((const time_t *)&m_date.tv_sec, &result);
-    return result.tm_mon + 1;
-  }
-
-  int DateTime::year() const
-  {
-    struct tm result;
-    localtime_r((const time_t *)&m_date.tv_sec, &result);
-    return result.tm_year + 1900;
-  }
-
-  int DateTime::day_of_year() const
-  {
-    struct tm result;
-    localtime_r((const time_t *)&m_date.tv_sec, &result);
-    return result.tm_yday;
-  }
-
-  bool DateTime::is_valid() const
-  {
-    return ((m_date.tv_sec != -1) && (m_date.tv_usec != -1));
-  }
-
-  Glib::ustring DateTime::_to_string(const char * format, struct tm * t) const
-  {
-    char output[256];
-    strftime(output, sizeof(output), format, t);
-    return Glib::locale_to_utf8(output);
-  }
-
-  Glib::ustring DateTime::to_string(const char * format) const
-  {
-    struct tm result; 
-    return _to_string(format, localtime_r((const time_t *)&m_date.tv_sec, &result));
-  }
-
-
-  Glib::ustring DateTime::to_short_time_string() const
-  {
-    struct tm result;
-    return _to_string("%R", localtime_r((const time_t *)&m_date.tv_sec, &result));
-  }
-
-  Glib::ustring DateTime::to_iso8601() const
-  {
-    Glib::ustring retval;
-    if(!is_valid()) {
-      return retval;
-    }
-    char *  iso8601 = g_time_val_to_iso8601(const_cast<Glib::TimeVal*>(&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;
-  }
-
-  DateTime DateTime::now()
-  {
-    GTimeVal n;
-    g_get_current_time(&n);
-    return DateTime(n);
-  }
-
-  DateTime DateTime::from_iso8601(const Glib::ustring &iso8601)
-  {
-    DateTime retval;
-    if(g_time_val_from_iso8601(iso8601.c_str(), &retval.m_date)) {
-      return retval;
-    }
-    return DateTime();
-  }
-
-
-  int DateTime::compare(const DateTime &a, const DateTime &b)
-  {
-    if(a > b)
-      return +1;
-    if(b > a)
-      return -1;
-    return 0;
-  }
-
-  bool DateTime::operator==(const DateTime & dt) const
-  {
-    return (m_date.tv_sec == dt.m_date.tv_sec) 
-      && (m_date.tv_usec == dt.m_date.tv_usec);
-  }
-
-  Glib::TimeSpan DateTime::operator-(const DateTime & dt) const
-  {
-    int secs = m_date.tv_sec - dt.m_date.tv_sec;
-    int usecs = m_date.tv_usec - dt.m_date.tv_usec;
-    int mins = secs / 60;
-    secs %= 60;
-    int hrs = mins / 60;
-    mins %= 60;
-    int days = hrs / 24;
-    hrs %= 24;
-    return sharp::time_span(days, hrs, mins, secs, usecs);
-  }
-
-  DateTime DateTime::operator-(const Glib::TimeSpan & ts) const
-  {
-    Glib::TimeVal timeval(m_date);
-    timeval.add_milliseconds(time_span_total_milliseconds(ts));
-    return DateTime(timeval);
-  }
-
-  bool DateTime::operator>(const DateTime & dt) const
-  {
-    if(m_date.tv_sec == dt.m_date.tv_sec) {
-      return (m_date.tv_usec > dt.m_date.tv_usec);
-    }
-    return (m_date.tv_sec > dt.m_date.tv_sec);
-  }
-
-
 Glib::ustring date_time_to_string(const Glib::DateTime & dt, const char *format)
 {
   struct tm t;
diff --git a/src/sharp/datetime.hpp b/src/sharp/datetime.hpp
index 63e657f8..39de8cb4 100644
--- a/src/sharp/datetime.hpp
+++ b/src/sharp/datetime.hpp
@@ -39,88 +39,11 @@
 
 namespace sharp {
 
-
-class DateTime
-{
-public:
-  DateTime();
-  explicit DateTime(time_t t, glong _usec = 0);
-  explicit DateTime(const Glib::TimeVal & v);
- 
-  DateTime & add_days(int days);
-  DateTime & add_hours(int hours);
-  DateTime & add_seconds(int seconds);
-
-  int day() const;
-  int month() const;
-  int year() const;
-  int day_of_year() const;
-
-  bool is_valid() const;
-
-  Glib::ustring to_string(const char * format) const;
-  Glib::ustring to_string(const Glib::ustring & format) const
-    {
-      return to_string(format.c_str());
-    }
-  Glib::ustring to_short_time_string() const;
-  Glib::ustring to_iso8601() const;
-
-  static DateTime now();
-  static DateTime from_iso8601(const Glib::ustring &);
-  static int compare(const DateTime &, const DateTime &);
-
-  bool operator==(const DateTime & dt) const;
-  bool operator!=(const DateTime & dt) const
-    {
-      return !(*this == dt);
-    }
-  bool operator>(const DateTime & dt) const;
-  bool operator>=(const DateTime & dt) const
-    {
-      return (*this == dt) || (*this > dt);
-    }
-  bool operator<(const DateTime & dt) const
-    {
-      return !(*this >= dt);
-    }
-  bool operator<=(const DateTime & dt) const
-    {
-      return (*this < dt) || (*this == dt);
-    }
-  Glib::TimeSpan operator-(const DateTime & dt) const;
-  DateTime operator-(const Glib::TimeSpan & ts) const;
-
-  operator Glib::DateTime() const
-  {
-    return Glib::DateTime::create_now_local(m_date);
-  }
-
-  glong sec() const
-    {
-      return m_date.tv_sec;
-    }
-  glong usec() const
-    {
-      return m_date.tv_usec;
-    }
-  void set_usec(glong _usec) 
-    {
-      m_date.tv_usec = _usec;
-    }
-private:
-  // return the string formatted according to strftime
-  Glib::ustring _to_string(const char * format, struct tm *) const;
-  Glib::TimeVal m_date;
-};
-
-
 Glib::ustring date_time_to_string(const Glib::DateTime & dt, const char *format);
 Glib::ustring date_time_to_string(const Glib::DateTime & dt, const Glib::ustring & format);
 Glib::ustring date_time_to_iso8601(const Glib::DateTime & dt);
 Glib::DateTime date_time_from_iso8601(const Glib::ustring & dt);
 
-
 }
 
 


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