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 /// <since_tizen> 4 </since_tizen>
25 public class CalendarTime:IComparable<CalendarTime>
28 internal const int milliseconds = 10000000;
31 /// Enumeration for the time type.
33 /// <since_tizen> 4 </since_tizen>
39 /// <since_tizen> 4 </since_tizen>
44 /// <since_tizen> 4 </since_tizen>
49 /// Create UTC CalendarTime
51 /// <since_tizen> 4 </since_tizen>
52 /// <param name="utcTime">UTC epoch time. 0 is 1971/01/01</param>
53 public CalendarTime(long utcTime)
55 _type = (int)Type.Utc;
56 utcTime -= utcTime % milliseconds; /* delete millisecond */
57 UtcTime = new DateTime(utcTime);
61 /// Create Local CalendarTime
63 /// <since_tizen> 4 </since_tizen>
64 /// <param name="year">year</param>
65 /// <param name="month">month</param>
66 /// <param name="day">day</param>
67 /// <param name="hour">hour</param>
68 /// <param name="minute">minute</param>
69 /// <param name="second">second</param>
70 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
71 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
72 public CalendarTime(int year, int month, int day, int hour, int minute, int second)
74 _type = (int)Type.Local;
75 LocalTime = new DateTime(year, month, day, hour, minute, second);
81 /// <since_tizen> 4 </since_tizen>
82 /// <value>The Utc time</value>
83 public DateTime UtcTime
91 /// <since_tizen> 4 </since_tizen>
92 /// <value>The Localtime</value>
93 public DateTime LocalTime
99 /// Compare CalendarTime
101 /// <since_tizen> 4 </since_tizen>
102 /// <param name="other">The CalendarTime to be compared</param>
104 /// A 32-bit signed integer that indicates the relative order of the objects being compared.
106 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
107 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
108 public int CompareTo(CalendarTime other)
110 if (_type != other._type)
112 Log.Error(Globals.LogTag, "Not to compare with different type");
113 throw CalendarErrorFactory.GetException((int)CalendarError.InvalidParameter);
116 if (_type == (int)Type.Utc)
117 return UtcTime.CompareTo(other.UtcTime);
119 return LocalTime.CompareTo(other.LocalTime);
123 /// Equals CalendarTime
125 /// <since_tizen> 4 </since_tizen>
126 /// <param name="obj">The CalendarTime to be compared</param>
128 /// A 32-bit signed integer that indicates the relative order of the objects being compared.
130 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
131 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
132 public override bool Equals(object obj)
134 var other = obj as CalendarTime;
135 if (_type != other._type)
137 Log.Error(Globals.LogTag, "Not to compare with different type");
141 if (_type == (int)Type.Utc)
142 return UtcTime.Equals(other.UtcTime);
144 return LocalTime.Equals(other.LocalTime);
148 /// GetHashCode CalendarTime
150 /// <since_tizen> 4 </since_tizen>
152 /// A hash code for the current object.
154 public override int GetHashCode()
156 if (_type == (int)Type.Utc)
157 return this.UtcTime.GetHashCode();
159 return this.LocalTime.GetHashCode();