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 public CalendarTime(int year, int month, int day, int hour, int minute, int second)
72 _type = (int)Type.Local;
73 LocalTime = new DateTime(year, month, day, hour, minute, second);
79 /// <since_tizen> 4 </since_tizen>
80 /// <value>The Utc time</value>
81 public DateTime UtcTime
89 /// <since_tizen> 4 </since_tizen>
90 /// <value>The Localtime</value>
91 public DateTime LocalTime
97 /// Compare CalendarTime
99 /// <since_tizen> 4 </since_tizen>
100 /// <param name="other">The CalendarTime to be compared</param>
102 /// A 32-bit signed integer that indicates the relative order of the objects being compared.
104 public int CompareTo(CalendarTime other)
106 if (_type != other._type)
108 Log.Error(Globals.LogTag, "Not to compare with different type");
109 throw CalendarErrorFactory.GetException((int)CalendarError.InvalidParameter);
112 if (_type == (int)Type.Utc)
113 return UtcTime.CompareTo(other.UtcTime);
115 return LocalTime.CompareTo(other.LocalTime);
119 /// Equals CalendarTime
121 /// <since_tizen> 4 </since_tizen>
122 /// <param name="obj">The CalendarTime to be compared</param>
124 /// A 32-bit signed integer that indicates the relative order of the objects being compared.
126 public override bool Equals(object obj)
128 var other = obj as CalendarTime;
129 if (_type != other._type)
131 Log.Error(Globals.LogTag, "Not to compare with different type");
135 if (_type == (int)Type.Utc)
136 return UtcTime.Equals(other.UtcTime);
138 return LocalTime.Equals(other.LocalTime);
142 /// GetHashCode CalendarTime
144 /// <since_tizen> 4 </since_tizen>
146 /// A hash code for the current object.
148 public override int GetHashCode()
150 if (_type == (int)Type.Utc)
151 return this.UtcTime.GetHashCode();
153 return this.LocalTime.GetHashCode();