[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.Context / Tizen.Context.AppHistory / AppStatistics.cs
1 /*
2  * Copyright (c) 2017 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.Context.AppHistory
20 {
21     /// <summary>
22     /// The Base class for application statistics.
23     /// </summary>
24     /// <since_tizen> 4 </since_tizen>
25     public abstract class AppStatistics
26     {
27         internal const string AppStatsQueryResult = "QueryResult";
28         internal const string AppStatsStartTime = "StartTime";
29         internal const string AppStatsEndTime = "EndTime";
30         internal const string AppStatsResultSize = "ResultSize";
31         internal const string AppStatsAppId = "AppId";
32         internal const int DefaultResultSize = 10;
33
34         internal string Uri;
35
36         internal AppStatistics()
37         {
38         }
39
40         internal static long ConvertDateTimeToUnixTimestamp(DateTime dateTime)
41         {
42             DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
43             long unixTimestampInTicks = (dateTime.ToUniversalTime() - unixStart).Ticks;
44             return unixTimestampInTicks / TimeSpan.TicksPerSecond;
45         }
46
47         internal static DateTime ConvertUnixTimestampToDateTime(long unixTime)
48         {
49             DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
50             long unixTimeStampInTicks = unixTime * TimeSpan.TicksPerSecond;
51             return new DateTime(unixStart.Ticks + unixTimeStampInTicks, System.DateTimeKind.Utc).ToLocalTime();
52         }
53
54         internal static void CheckTimeSpan(DateTime startTime, DateTime endTime)
55         {
56             if (startTime > endTime)
57             {
58                 Log.Error(AppHistoryErrorFactory.LogTag, "endTime should be greater than startTime");
59                 throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.InvalidParameter, "endTime should be greater than startTime");
60             }
61         }
62
63         internal static void CheckResultSize(uint resultSize)
64         {
65             if (resultSize <= 0)
66             {
67                 Log.Error(AppHistoryErrorFactory.LogTag, "resultSize should be greater than 0");
68                 throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.InvalidParameter, "resultSize should be greater than 0");
69             }
70         }
71
72         internal abstract string ConvertSortOrderToString(int order);
73     }
74 }