[gnote] Enhance DateTime with additional opetators
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Enhance DateTime with additional opetators
- Date: Wed, 25 Jan 2012 22:03:32 +0000 (UTC)
commit 491e9c4163d9f9b9ad3eaffa633c517eba3ba217
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Sun Jan 22 15:48:39 2012 +0200
Enhance DateTime with additional opetators
Add more comparison operators.
Add difference operator with TimeSpan use.
src/sharp/datetime.cpp | 22 +++++++++++++++++++++-
src/sharp/datetime.hpp | 24 ++++++++++++++++++++++--
2 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/src/sharp/datetime.cpp b/src/sharp/datetime.cpp
index d95c984..917792b 100644
--- a/src/sharp/datetime.cpp
+++ b/src/sharp/datetime.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -172,6 +172,26 @@ namespace sharp {
&& (m_date.tv_usec == dt.m_date.tv_usec);
}
+ 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 TimeSpan(days, hrs, mins, secs, usecs);
+ }
+
+ DateTime DateTime::operator-(const TimeSpan & ts) const
+ {
+ Glib::TimeVal timeval(m_date);
+ timeval.add_milliseconds(ts.total_milliseconds());
+ return DateTime(timeval);
+ }
+
bool DateTime::operator>(const DateTime & dt) const
{
if(m_date.tv_sec == dt.m_date.tv_sec) {
diff --git a/src/sharp/datetime.hpp b/src/sharp/datetime.hpp
index 6f62ec0..458d9fb 100644
--- a/src/sharp/datetime.hpp
+++ b/src/sharp/datetime.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -35,6 +35,8 @@
#include <glibmm/timeval.h>
+#include "timespan.hpp"
+
namespace sharp {
@@ -54,7 +56,6 @@ public:
int day_of_year() const;
bool is_valid() const;
- bool operator>(const DateTime & dt) const;
std::string to_string(const char * format) const;
std::string to_string(const std::string & format) const
@@ -69,6 +70,25 @@ public:
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);
+ }
+ TimeSpan operator-(const DateTime & dt) const;
+ DateTime operator-(const TimeSpan & ts) const;
glong sec() const
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]