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