/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace Tizen.Pims.Calendar { /// /// A class for the time to set, get, or calculate. /// /// 4 public class CalendarTime:IComparable { internal int _type; internal const int milliseconds = 10000000; /// /// Enumeration for the time type. /// /// 4 public enum Type { /// /// UTC time. /// /// 4 Utc, /// /// Local time. /// /// 4 Local } /// /// Creates the UTC CalendarTime. /// /// 4 /// The UTC epoch time. 0 is 1971/01/01. public CalendarTime(long utcTime) { _type = (int)Type.Utc; utcTime -= utcTime % milliseconds; /* delete millisecond */ UtcTime = new DateTime(utcTime); } /// /// Creates the local CalendarTime /// /// 4 /// The year. /// The month. /// The day. /// The hour. /// The minute. /// The second. public CalendarTime(int year, int month, int day, int hour, int minute, int second) { _type = (int)Type.Local; LocalTime = new DateTime(year, month, day, hour, minute, second); } /// /// Gets the UtcTime. /// /// 4 /// The UTC time. public DateTime UtcTime { get; } /// /// Gets the LocalTime /// /// 4 /// The local time. public DateTime LocalTime { get; } /// /// Compares the CalendarTime. /// /// 4 /// The CalendarTime to be compared. /// /// A 32-bit signed integer that indicates the relative order of the objects being compared. /// public int CompareTo(CalendarTime other) { if (_type != other._type) { Log.Error(Globals.LogTag, "Not to compare with different type"); throw CalendarErrorFactory.GetException((int)CalendarError.InvalidParameter); } if (_type == (int)Type.Utc) return UtcTime.CompareTo(other.UtcTime); else return LocalTime.CompareTo(other.LocalTime); } /// /// Equals the CalendarTime. /// /// 4 /// The CalendarTime to be compared. /// /// A 32-bit signed integer that indicates the relative order of the objects being compared. /// public override bool Equals(object obj) { var other = obj as CalendarTime; if (_type != other._type) { Log.Error(Globals.LogTag, "Not to compare with different type"); return false; } if (_type == (int)Type.Utc) return UtcTime.Equals(other.UtcTime); else return LocalTime.Equals(other.LocalTime); } /// /// The GetHashCode for the CalendarTime. /// /// 4 /// /// A hash code for the current object. /// public override int GetHashCode() { if (_type == (int)Type.Utc) return this.UtcTime.GetHashCode(); else return this.LocalTime.GetHashCode(); } } }