*Comparision operator overload added to Time class. 4.x-dev

Fri, 30 Oct 2020 01:07:43 +0200

author
Luca
date
Fri, 30 Oct 2020 01:07:43 +0200
branch
4.x-dev
changeset 1472
3ab474a95f5a
parent 1471
42787ccaa5b8
child 1473
71d5c7c0628b

*Comparision operator overload added to Time class.
*Output stream operator overload added.

Source/Gorgon/Time.h file | annotate | diff | comparison | revisions
Source/Gorgon/Time/Time.cpp file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/Time.h	Wed Oct 28 13:33:41 2020 +0200
+++ b/Source/Gorgon/Time.h	Fri Oct 30 01:07:43 2020 +0200
@@ -175,7 +175,20 @@
 			/// Gives the difference between two dates.
 			double operator - (const Date &other);
 			
-			/// Unsets the stored time
+			/// Compares 2 dates
+            bool operator == (const Date &other) const;
+            
+            /// Output stream operator overload 
+            std::ostream &operator << (std::ostream &out){
+                if(timezone){
+                    out<<ISODateTime(timezone);
+                }else
+                    out<<ISODate();
+                    
+                return out;
+            }
+            
+            /// Unsets the stored time
 			void Unset() {
 				Year=0;
 				Month=Empty;
--- a/Source/Gorgon/Time/Time.cpp	Wed Oct 28 13:33:41 2020 +0200
+++ b/Source/Gorgon/Time/Time.cpp	Fri Oct 30 01:07:43 2020 +0200
@@ -338,6 +338,15 @@
 		return difftime(x, y);
 	}
 	
+	bool Date::operator == (const Date &other) const{
+        tm a = totm(*this), b = totm(other);
+        
+        time_t x = mktime(&a);
+		time_t y = mktime(&b);
+        
+        return y == x;
+    }
+	
 	void Date::AddYears(int years) {
 		tm a = totm(*this);
 		a.tm_year += years;

mercurial