2 * Copyright (c) 2017 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.
19 namespace Tizen.Context.AppHistory
22 /// Base class for application statistics.
24 /// <since_tizen> 4 </since_tizen>
25 public abstract class AppStatistics
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;
36 internal AppStatistics()
40 internal static long ConvertDateTimeToUnixTimestamp(DateTime dateTime)
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;
47 internal static DateTime ConvertUnixTimestampToDateTime(long unixTime)
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();
54 internal static void CheckTimeSpan(DateTime startTime, DateTime endTime)
56 if (startTime > endTime)
58 Log.Error(AppHistoryErrorFactory.LogTag, "endTime should be greater than startTime");
59 throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.InvalidParameter, "endTime should be greater than startTime");
63 internal static void CheckResultSize(uint resultSize)
67 Log.Error(AppHistoryErrorFactory.LogTag, "resultSize should be greater than 0");
68 throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.InvalidParameter, "resultSize should be greater than 0");
72 internal abstract string ConvertSortOrderToString(int order);