From 36117505ede8c292c8c0c1775fc1f73f5e52efa4 Mon Sep 17 00:00:00 2001 From: a-nijhara <114644593+a-nijhara@users.noreply.github.com> Date: Tue, 4 Oct 2022 10:58:31 +0530 Subject: [PATCH] [Stc] Fix datatype conversion issue (#4612) Co-authored-by: Seonah Moon Co-authored-by: Dohyun Pyun --- src/Tizen.Network.Stc/Interop/Interop.Stc.cs | 16 ++++++++++++++++ .../Tizen.Network.Stc/StcStatsFilter.cs | 15 ++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Tizen.Network.Stc/Interop/Interop.Stc.cs b/src/Tizen.Network.Stc/Interop/Interop.Stc.cs index 1a68715..a9b382c 100755 --- a/src/Tizen.Network.Stc/Interop/Interop.Stc.cs +++ b/src/Tizen.Network.Stc/Interop/Interop.Stc.cs @@ -56,6 +56,8 @@ internal static partial class Interop internal static extern int SetAppId(SafeFilterHandle filter, string appId); [DllImport(Libraries.Stc,EntryPoint = "stc_stats_rule_set_time_interval")] internal static extern int SetTimeInterval(SafeFilterHandle filter, Int32 from, Int32 to); + [DllImport(Libraries.Stc,EntryPoint = "stc_stats_rule_set_time_interval")] + internal static extern int SetTimeInterval64(SafeFilterHandle filter, Int64 from, Int64 to); [DllImport(Libraries.Stc,EntryPoint = "stc_stats_rule_set_iface_type")] internal static extern int SetInterfaceType(SafeFilterHandle filter, NetworkInterface ifaceType); [DllImport(Libraries.Stc,EntryPoint = "stc_stats_rule_set_time_period")] @@ -73,6 +75,8 @@ internal static partial class Interop internal static extern int GetInterfaceName(SafeStatsHandle info, out string IfaceName); [DllImport(Libraries.Stc,EntryPoint = "stc_stats_info_get_time_interval")] internal static extern int GetTimeInterval(SafeStatsHandle info, out Int32 from, out Int32 to); + [DllImport(Libraries.Stc,EntryPoint = "stc_stats_info_get_time_interval")] + internal static extern int GetTimeInterval64(SafeStatsHandle info, out Int64 from, out Int64 to); [DllImport(Libraries.Stc,EntryPoint = "stc_stats_info_get_iface_type")] internal static extern int GetInterfaceType(SafeStatsHandle info, out NetworkInterface ifaceType); [DllImport(Libraries.Stc,EntryPoint = "stc_stats_info_get_counter")] @@ -152,9 +156,21 @@ internal static partial class Interop return (Int32)((dateTime.ToUniversalTime() - epoch).TotalSeconds); } + internal static Int64 ConvertDateTimeToTimestamp64(DateTime dateTime) + { + DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + return (Int64)((dateTime.ToUniversalTime() - epoch).TotalSeconds); + } + internal static DateTime ConvertTimestampToDateTime(Int32 timestamp) { DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); return epoch.AddSeconds(timestamp).ToLocalTime(); } + + internal static DateTime ConvertTimestampToDateTime64(Int64 timestamp) + { + DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + return epoch.AddSeconds(timestamp).ToLocalTime(); + } } diff --git a/src/Tizen.Network.Stc/Tizen.Network.Stc/StcStatsFilter.cs b/src/Tizen.Network.Stc/Tizen.Network.Stc/StcStatsFilter.cs index 937caad..e9a8ab4 100755 --- a/src/Tizen.Network.Stc/Tizen.Network.Stc/StcStatsFilter.cs +++ b/src/Tizen.Network.Stc/Tizen.Network.Stc/StcStatsFilter.cs @@ -69,9 +69,18 @@ namespace Tizen.Network.Stc Interop.Stc.Filter.SetAppId(handle, AppId); if (From.HasValue && To.HasValue) { - Interop.Stc.Filter.SetTimeInterval(handle, - Interop.ConvertDateTimeToTimestamp(From.Value), - Interop.ConvertDateTimeToTimestamp(To.Value)); + if (Environment.Is64BitOperatingSystem) + { + Interop.Stc.Filter.SetTimeInterval64(handle, + Interop.ConvertDateTimeToTimestamp64(From.Value), + Interop.ConvertDateTimeToTimestamp64(To.Value)); + } + else + { + Interop.Stc.Filter.SetTimeInterval(handle, + Interop.ConvertDateTimeToTimestamp(From.Value), + Interop.ConvertDateTimeToTimestamp(To.Value)); + } } if (InterfaceType.HasValue) { -- 2.7.4