2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Pims.Calendar
22 /// A class for time to set, get or calculate.
24 public class CalendarTime:IComparable<CalendarTime>
27 internal const int milliseconds = 10000000;
30 /// Enumeration for the time type.
45 /// Create UTC CalendarTime
47 /// <param name="utcTime">UTC epoch time. 0 is 1971/01/01</param>
48 public CalendarTime(long utcTime)
50 _type = (int)Type.Utc;
51 utcTime -= utcTime % milliseconds; /* delete millisecond */
52 UtcTime = new DateTime(utcTime);
56 /// Create Local CalendarTime
58 /// <param name="year">year</param>
59 /// <param name="month">month</param>
60 /// <param name="day">day</param>
61 /// <param name="hour">hour</param>
62 /// <param name="minute">minute</param>
63 /// <param name="second">second</param>
64 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
65 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
66 public CalendarTime(int year, int month, int day, int hour, int minute, int second)
68 _type = (int)Type.Local;
69 LocalTime = new DateTime(year, month, day, hour, minute, second);
75 /// <value>The Utc time</value>
76 public DateTime UtcTime
84 /// <value>The localtime</value>
85 public DateTime LocalTime
91 /// Compare CalendarTime
93 /// <param name="other">The CalendarTime to be compared</param>
95 /// A 32-bit signed integer that indicates the relative order of the objects being compared.
97 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
98 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
99 public int CompareTo(CalendarTime other)
101 if (_type != other._type)
103 Log.Error(Globals.LogTag, "Not to compare with different type");
104 throw CalendarErrorFactory.GetException((int)CalendarError.InvalidParameter);
107 if (_type == (int)Type.Utc)
108 return UtcTime.CompareTo(other.UtcTime);
110 return LocalTime.CompareTo(other.LocalTime);
113 public bool Equals(CalendarTime other)
115 if (_type != other._type)
117 Log.Error(Globals.LogTag, "Not to compare with different type");
118 throw CalendarErrorFactory.GetException((int)CalendarError.InvalidParameter);
121 if (_type == (int)Type.Utc)
122 return UtcTime.Equals(other.UtcTime);
124 return LocalTime.Equals(other.LocalTime);