Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.WatchApplication / Tizen.Applications / WatchTime.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace Tizen.Applications
20 {
21     /// <summary>
22     /// The information of Watch Time
23     /// </summary>
24     public class WatchTime
25     {
26         private readonly SafeWatchTimeHandle _handle;
27         private static readonly string LOGTAG = "Tizen.Applications.WatchApplication";
28
29         internal WatchTime(SafeWatchTimeHandle handle)
30         {
31             _handle = handle;
32         }
33
34         /// <summary>
35         /// The information of year
36         /// </summary>
37         public int Year
38         {
39             get
40             {
41                 int year;
42                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetYear(_handle, out year);
43
44                 if (err != Interop.Watch.ErrorCode.None)
45                 {
46                     Log.Error(LOGTAG, "Failed to get Year err : " + err);
47                 }
48                 return year;
49             }
50         }
51
52         /// <summary>
53         /// The information fo month
54         /// </summary>
55         public int Month
56         {
57             get
58             {
59                 int month;
60                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetMonth(_handle, out month);
61
62                 if (err != Interop.Watch.ErrorCode.None)
63                 {
64                     Log.Error(LOGTAG, "Failed to get Month err : " + err);
65                 }
66                 return month;
67             }
68         }
69
70         /// <summary>
71         /// The information of day
72         /// </summary>
73         public int Day
74         {
75             get
76             {
77                 int day;
78                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetDay(_handle, out day);
79
80                 if (err != Interop.Watch.ErrorCode.None)
81                 {
82                     Log.Error(LOGTAG, "Failed to get Day err : " + err);
83                 }
84                 return day;
85             }
86         }
87
88         /// <summary>
89         /// The information of day of week
90         /// </summary>
91         public int DayOfWeek
92         {
93             get
94             {
95                 int dayOfWeek;
96                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetDayOfWeek(_handle, out dayOfWeek);
97
98                 if (err != Interop.Watch.ErrorCode.None)
99                 {
100                     Log.Error(LOGTAG, "Failed to get Second err : " + err);
101                 }
102                 return dayOfWeek;
103             }
104         }
105
106         /// <summary>
107         /// The information of hour
108         /// </summary>
109         public int Hour
110         {
111             get
112             {
113                 int hour;
114                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetHour(_handle, out hour);
115
116                 if (err != Interop.Watch.ErrorCode.None)
117                 {
118                     Log.Error(LOGTAG, "Failed to get Hour err : " + err);
119                 }
120                 return hour;
121             }
122         }
123
124         /// <summary>
125         /// The information of hour for 24 hour form
126         /// </summary>
127         public int Hour24
128         {
129             get
130             {
131                 int hour24;
132                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetHour24(_handle, out hour24);
133
134                 if (err != Interop.Watch.ErrorCode.None)
135                 {
136                     Log.Error(LOGTAG, "Failed to get Hour24 err : " + err);
137                 }
138                 return hour24;
139             }
140         }
141
142         /// <summary>
143         /// The information of Minute
144         /// </summary>
145         public int Minute
146         {
147             get
148             {
149                 int minute;
150                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetMinute(_handle, out minute);
151
152                 if (err != Interop.Watch.ErrorCode.None)
153                 {
154                     Log.Error(LOGTAG, "Failed to get Minute err : " + err);
155                 }
156                 return minute;
157             }
158         }
159
160         /// <summary>
161         /// The information of second
162         /// </summary>
163         public int Second
164         {
165             get
166             {
167                 int second;
168                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetSecond(_handle, out second);
169
170                 if (err != Interop.Watch.ErrorCode.None)
171                 {
172                     Log.Error(LOGTAG, "Failed to get Second err : " + err);
173                 }
174                 return second;
175             }
176         }
177
178         /// <summary>
179         /// The information of millisecond
180         /// </summary>
181         public int Millisecond
182         {
183             get
184             {
185                 int ms;
186                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetMillisecond(_handle, out ms);
187
188                 if (err != Interop.Watch.ErrorCode.None)
189                 {
190                     Log.Error(LOGTAG, "Failed to get Second err : " + err);
191                 }
192                 return ms;
193             }
194         }
195
196         /// <summary>
197         /// The information of timezone
198         /// </summary>
199         public string TimeZone
200         {
201             get
202             {
203                 string zone;
204                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetTimeZone(_handle, out zone);
205
206                 if (err != Interop.Watch.ErrorCode.None)
207                 {
208                     Log.Error(LOGTAG, "Failed to get Second err : " + err);
209                 }
210                 return zone;
211             }
212         }
213
214         /// <summary>
215         /// The information of UTC time stamp
216         /// </summary>
217         public DateTime UtcTimestamp
218         {
219             get
220             {
221                 long ts = 0;
222
223                 Interop.Watch.ErrorCode err = Interop.Watch.WatchTimeGetUtcTimestamp(_handle, out ts);
224
225                 if (err != Interop.Watch.ErrorCode.None)
226                 {
227                     Log.Error(LOGTAG, "Failed to get UtcTimestamp err : " + err);
228                 }
229
230                 return (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(ts).ToLocalTime();
231             }
232         }
233     }
234 }