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;
}
{
/// <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.
}
/// <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>
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);
}
}
}