From e3483ea8d93626f54b03aaedb9cc41627ed7aea5 Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Wed, 17 May 2017 10:42:53 +0900 Subject: [PATCH] modify CalendarTime : IComparable Change-Id: Idbe17253e97be8f3a388aa88432e16d96a8b332d --- .../Tizen.Pims.Calendar/CalendarRecord.cs | 15 +++-- .../Tizen.Pims.Calendar/CalendarStructs.cs | 67 +++++++++------------- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarRecord.cs b/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarRecord.cs index 64234e7..9c31306 100644 --- a/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarRecord.cs +++ b/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarRecord.cs @@ -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; } diff --git a/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarStructs.cs b/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarStructs.cs index 15c6544..f3d9821 100644 --- a/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarStructs.cs +++ b/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarStructs.cs @@ -25,10 +25,10 @@ namespace Tizen.Pims.Calendar { /// /// - public class CalendarTime : IDisposable + public class CalendarTime : IComparable { internal int _type; - internal DateTime _dateTime; + internal const int milliseconds = 10000000; /// /// Enumeration for the time type. @@ -46,36 +46,14 @@ namespace Tizen.Pims.Calendar } /// - /// Get time type. - /// - public int TypeValue - { - get - { - return _type; - } - } - - /// - /// Get datatime. - /// - public DateTime DateTime - { - get - { - return _dateTime; - } - } - - /// /// Create UTC CalendarTime /// /// UTC epoch time. 0 is 1971/01/01 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); } /// @@ -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); } /// - /// Compare CalendarTime + /// Get utcTime /// - /// The first CalendarTime to compare - /// The second CalendarTime to compare - /// - /// A signed number indicating the relative values of t1 and t2. - /// - 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)); + /// + /// Get localTime + /// + public DateTime LocalTime + { + get; } /// + /// Compare CalendarTime /// - /// - public void Dispose() + /// The CalendarTime to be compared + /// + /// A 32-bit signed integer that indicates the relative order of the objects being compared. + /// + 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); } } } -- 2.7.4