modify CalendarTime : IComparable
authorJeesun Kim <iamjs.kim@samsung.com>
Wed, 17 May 2017 01:42:53 +0000 (10:42 +0900)
committerJeesun Kim <iamjs.kim@samsung.com>
Wed, 17 May 2017 01:47:05 +0000 (10:47 +0900)
Change-Id: Idbe17253e97be8f3a388aa88432e16d96a8b332d

src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarRecord.cs
src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarStructs.cs

index 64234e7..9c31306 100644 (file)
@@ -132,20 +132,19 @@ namespace Tizen.Pims.Calendar
         internal static Interop.Calendar.Record.DateTime ConvertCalendarTimeToStruct(CalendarTime value)
         {
             Interop.Calendar.Record.DateTime time = new Interop.Calendar.Record.DateTime();
-            time.type = value.TypeValue;
             if ((int)CalendarTime.Type.Utc == time.type)
             {
                 DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
-                time.utime = (value.DateTime.Ticks - epoch.Ticks) / 10000000;
+                time.utime = (value.UtcTime.Ticks - epoch.Ticks) / 10000000;
             }
             else
             {
-                time.year = value.DateTime.Year;
-                time.month = value.DateTime.Month;
-                time.mday = value.DateTime.Day;
-                time.hour = value.DateTime.Hour;
-                time.minute = value.DateTime.Minute;
-                time.second = value.DateTime.Second;
+                time.year = value.LocalTime.Year;
+                time.month = value.LocalTime.Month;
+                time.mday = value.LocalTime.Day;
+                time.hour = value.LocalTime.Hour;
+                time.minute = value.LocalTime.Minute;
+                time.second = value.LocalTime.Second;
             }
             return time;
         }
index 15c6544..f3d9821 100644 (file)
@@ -25,10 +25,10 @@ namespace Tizen.Pims.Calendar
 {
     /// <summary>
     /// </summary>
-    public class CalendarTime : IDisposable
+    public class CalendarTime : IComparable<CalendarTime>
     {
         internal int _type;
-        internal DateTime _dateTime;
+        internal const int milliseconds = 10000000;
 
         /// <summary>
         /// Enumeration for the time type.
@@ -46,36 +46,14 @@ namespace Tizen.Pims.Calendar
         }
 
         /// <summary>
-        /// Get time type.
-        /// </summary>
-        public int TypeValue
-        {
-            get
-            {
-                return _type;
-            }
-        }
-
-        /// <summary>
-        /// Get datatime.
-        /// </summary>
-        public DateTime DateTime
-        {
-            get
-            {
-                return _dateTime;
-            }
-        }
-
-        /// <summary>
         /// Create UTC CalendarTime
         /// </summary>
         /// <param name="utcTime">UTC epoch time. 0 is 1971/01/01</param>
         public CalendarTime(long utcTime)
         {
             _type = (int)Type.Utc;
-            utcTime -= utcTime % 10000000; /* delete millisecond */
-            _dateTime = new DateTime(utcTime);
+            utcTime -= utcTime % milliseconds; /* delete millisecond */
+            UtcTime = new DateTime(utcTime);
         }
 
         /// <summary>
@@ -90,32 +68,41 @@ namespace Tizen.Pims.Calendar
         public CalendarTime(int year, int month, int day, int hour, int minute, int second)
         {
             _type = (int)Type.Local;
-            _dateTime = new DateTime(year, month, day, hour, minute, second);
+            LocalTime = new DateTime(year, month, day, hour, minute, second);
         }
 
         /// <summary>
-        /// Compare CalendarTime
+        /// Get utcTime
         /// </summary>
-        /// <param name="t1">The first CalendarTime to compare</param>
-        /// <param name="t1">The second CalendarTime to compare</param>
-        /// <returns>
-        /// A signed number indicating the relative values of t1 and t2.
-        /// </returns>
-        public static int Compare(CalendarTime t1, CalendarTime t2)
+        public DateTime UtcTime
         {
-            if (t1.TypeValue != t2.TypeValue)
-                return -1;
+            get;
+        }
 
-            long ret = (t1.DateTime.Ticks / 10000000) - (t2.DateTime.Ticks / 10000000);
-            return (int)(0 == ret ? 0 : (ret / ret));
+        /// <summary>
+        /// Get localTime
+        /// </summary>
+        public DateTime LocalTime
+        {
+            get;
         }
 
         /// <summary>
+        /// Compare CalendarTime
         /// </summary>
-        /// <param name=""></param>
-        public void Dispose()
+        /// <param name="t">The CalendarTime to be compared</param>
+        /// <returns>
+        /// A 32-bit signed integer that indicates the relative order of the objects being compared.
+        /// </returns>
+        public int CompareTo(CalendarTime t)
         {
+            if (_type != t._type)
+                throw new NotImplementedException("Not to compare with different type");
 
+            if (_type == (int)Type.Utc)
+                return UtcTime.CompareTo(t.UtcTime);
+            else
+                return LocalTime.CompareTo(t.LocalTime);
         }
     }
 }