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 public abstract class AppStatistics
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;
35 internal AppStatistics()
39 internal static long ConvertDateTimeToUnixTimestamp(DateTime dateTime)
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;
46 internal static DateTime ConvertUnixTimestampToDateTime(long unixTime)
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();
53 internal static void CheckTimeSpan(DateTime startTime, DateTime endTime)
55 if (startTime > endTime)
57 Log.Error(AppHistoryErrorFactory.LogTag, "endTime should be greater than startTime");
58 throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.InvalidParameter, "endTime should be greater than startTime");
62 internal static void CheckResultSize(uint resultSize)
66 Log.Error(AppHistoryErrorFactory.LogTag, "resultSize should be greater than 0");
67 throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.InvalidParameter, "resultSize should be greater than 0");
71 internal abstract string ConvertSortOrderToString(int order);