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.
18 using System.Runtime.InteropServices;
20 namespace Tizen.Pims.Calendar
23 /// A class for time to set, get or calcurate.
25 public class CalendarTime : IComparable<CalendarTime>
28 internal const int milliseconds = 10000000;
31 /// Enumeration for the time type.
46 /// Create UTC CalendarTime
48 /// <param name="utcTime">UTC epoch time. 0 is 1971/01/01</param>
49 public CalendarTime(long utcTime)
51 _type = (int)Type.Utc;
52 utcTime -= utcTime % milliseconds; /* delete millisecond */
53 UtcTime = new DateTime(utcTime);
57 /// Create Local CalendarTime
59 /// <param name="year">year</param>
60 /// <param name="month">month</param>
61 /// <param name="day">day</param>
62 /// <param name="hour">hour</param>
63 /// <param name="minute">minute</param>
64 /// <param name="second">second</param>
65 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
66 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
67 public CalendarTime(int year, int month, int day, int hour, int minute, int second)
69 _type = (int)Type.Local;
70 LocalTime = new DateTime(year, month, day, hour, minute, second);
76 public DateTime UtcTime
84 public DateTime LocalTime
90 /// Compare CalendarTime
92 /// <param name="t">The CalendarTime to be compared</param>
94 /// A 32-bit signed integer that indicates the relative order of the objects being compared.
96 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
97 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
98 public int CompareTo(CalendarTime t)
100 if (_type != t._type)
102 Log.Error(Globals.LogTag, "Not to compare with different type");
103 throw CalendarErrorFactory.GetException((int)CalendarError.InvalidParameter);
106 if (_type == (int)Type.Utc)
107 return UtcTime.CompareTo(t.UtcTime);
109 return LocalTime.CompareTo(t.LocalTime);