/// <summary> /// Gets the current UTC offset. /// </summary> /// <returns>The current UTC offset.</returns> public int GetCurrentUTCOffset() { //return TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours; Java.Util.TimeZone timeZone = Java.Util.TimeZone.Default; Java.Util.Date now = new Java.Util.Date(); int offsetFromUtc = timeZone.GetOffset(now.Time) / 3600000; return(offsetFromUtc); }
static void CompareTimeZoneData(TimeZone tz, TimeZoneInfo tzi, Java.Util.TimeZone jtz) { Console.WriteLine("## Comparing TimeZone Data:"); Console.WriteLine("# TimeZone: StandardName={0}; DaylightName={1}", tz.StandardName, tz.DaylightName); Console.WriteLine("# TimeZoneInfo: StandardName={0}; DaylightName={1}; DisplayName={2}; Id={3}", tzi.StandardName, tzi.DaylightName, tzi.DisplayName, tzi.Id); Console.WriteLine("# Java TimeZone: DisplayName={0}; ID={1}", jtz.DisplayName, jtz.ID); bool found_errors = false; for (int year = 2012; year < 2015; ++year) { if (tz != null) { var dst = tz.GetDaylightChanges(year); Console.WriteLine("Year: {0}; DST: {1} -> {2}", year, dst.Start.ToString("g"), dst.End.ToString("g")); } for (int month = 1; month <= 12; month++) { int lastDayInMonth = DateTime.DaysInMonth(year, month); for (int day = 1; day <= lastDayInMonth; day++) { var localtime = new DateTime(year, month, day, 10, 00, 00, DateTimeKind.Local); var utctime = localtime.ToUniversalTime(); var tz_offset = tz.GetUtcOffset(localtime); var tzi_offset = tzi.GetUtcOffset(localtime); var tz_dst = tz.IsDaylightSavingTime(localtime); var tzi_dst = tzi.IsDaylightSavingTime(localtime); using (var jd = ToDate(localtime)) { var jtz_dst = jtz.InDaylightTime(jd); var ms = (int)(localtime - new DateTime(year, month, day, 0, 0, 0, DateTimeKind.Local)).TotalMilliseconds; var jtz_offseti = jtz.GetOffset(1, year, month - 1, day, ((int)localtime.DayOfWeek) + 1, ms); var jtz_offset = TimeSpan.FromMilliseconds(jtz_offseti); if (tz_offset != tzi_offset || tz_offset != jtz_offset || tzi_offset != jtz_offset || tz_dst != tzi_dst || tz_dst != jtz_dst || tzi_dst != jtz_dst) { found_errors = true; Console.WriteLine("MISMATCH! @ {0} [{1}]", localtime, jd.ToLocaleString()); Console.WriteLine("\t TimeZone Offset: {0}", tz_offset); Console.WriteLine("\t TimeZoneInfo Offset: {0}", tzi_offset); Console.WriteLine("\tJava TimeZone Offset: {0}", jtz_offset); Console.WriteLine("\t TimeZone DST: {0}", tz_dst); Console.WriteLine("\t TimeZoneInfo DST: {0}", tzi_dst); Console.WriteLine("\t Java TimeZone DST: {0}", jtz_dst); } } } } } if (found_errors) { var rules = tzi.GetAdjustmentRules(); for (int i = 0; i < rules.Length; ++i) { var rule = rules [i]; Console.WriteLine("# AdjustmentRules[{0}]: DaylightDelta={1}; DateStart={2}; DateEnd={3}; DaylightTransitionStart={4}/{5} @ {6}; DaylightTransitionEnd={7}/{8} @ {9}", i, rule.DaylightDelta, rule.DateStart.ToString("yyyy-MM-dd"), rule.DateEnd.ToString("yyyy-MM-dd"), rule.DaylightTransitionStart.Month, rule.DaylightTransitionStart.Day, rule.DaylightTransitionStart.TimeOfDay.ToString("hh:mm:ss"), rule.DaylightTransitionEnd.Month, rule.DaylightTransitionEnd.Day, rule.DaylightTransitionEnd.TimeOfDay.ToString("hh:mm:ss")); } } Assert.IsFalse(found_errors, "TimeZoneData MISMATCH! See logcat output for details."); }
public static RaygunEnvironmentMessage Build() { RaygunEnvironmentMessage message = new RaygunEnvironmentMessage(); try { var metrics = Resources.System.DisplayMetrics; message.WindowBoundsWidth = metrics.WidthPixels; message.WindowBoundsHeight = metrics.HeightPixels; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("Error retrieving screen dimensions: {0}", ex.Message)); } try { Java.Util.TimeZone tz = Java.Util.TimeZone.Default; Java.Util.Date now = new Java.Util.Date(); message.UtcOffset = tz.GetOffset(now.Time) / 3600000.0; message.Locale = CultureInfo.CurrentCulture.DisplayName; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("Error retrieving time and locale: {0}", ex.Message)); } try { Context context = RaygunClient.Context; if (context != null) { IWindowManager windowManager = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); if (windowManager != null) { Display display = windowManager.DefaultDisplay; if (display != null) { switch (display.Rotation) { case SurfaceOrientation.Rotation0: message.CurrentOrientation = "Rotation 0 (Portrait)"; break; case SurfaceOrientation.Rotation180: message.CurrentOrientation = "Rotation 180 (Upside down)"; break; case SurfaceOrientation.Rotation270: message.CurrentOrientation = "Rotation 270 (Landscape right)"; break; case SurfaceOrientation.Rotation90: message.CurrentOrientation = "Rotation 90 (Landscape left)"; break; } } } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("Error retrieving orientation: {0}", ex.Message)); } try { Java.Lang.Runtime runtime = Java.Lang.Runtime.GetRuntime(); message.TotalPhysicalMemory = (ulong)runtime.TotalMemory(); message.AvailablePhysicalMemory = (ulong)runtime.FreeMemory(); message.OSVersion = Android.OS.Build.VERSION.Sdk; message.ProcessorCount = runtime.AvailableProcessors(); message.Architecture = Android.OS.Build.CpuAbi; message.Model = string.Format("{0} / {1}", Android.OS.Build.Model, Android.OS.Build.Brand); message.DeviceManufacturer = Android.OS.Build.Manufacturer; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("Error retrieving device info: {0}", ex.Message)); } return(message); }
public RaygunEnvironmentMessage() { #if WINRT //WindowBoundsHeight = Windows.UI.Xaml.Window.Current.Bounds.Height; //WindowBoundsWidth = Windows.UI.Xaml.Window.Current.Bounds.Width; PackageVersion = string.Format("{0}.{1}", Package.Current.Id.Version.Major, Package.Current.Id.Version.Minor); Cpu = Package.Current.Id.Architecture.ToString(); ResolutionScale = DisplayProperties.ResolutionScale.ToString(); CurrentOrientation = DisplayProperties.CurrentOrientation.ToString(); Location = Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion; DateTime now = DateTime.Now; UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours; SYSTEM_INFO systemInfo = new SYSTEM_INFO(); RaygunSystemInfoWrapper.GetNativeSystemInfo(ref systemInfo); Architecture = systemInfo.wProcessorArchitecture.ToString(); #elif WINDOWS_PHONE Locale = CultureInfo.CurrentCulture.DisplayName; OSVersion = Environment.OSVersion.Platform + " " + Environment.OSVersion.Version; object deviceName; DeviceExtendedProperties.TryGetValue("DeviceName", out deviceName); DeviceName = deviceName.ToString(); DateTime now = DateTime.Now; UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours; Deployment.Current.Dispatcher.BeginInvoke(() => { WindowBoundsWidth = Application.Current.RootVisual.RenderSize.Width; WindowBoundsHeight = Application.Current.RootVisual.RenderSize.Height; PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; if (frame != null) { CurrentOrientation = frame.Orientation.ToString(); } }); //ProcessorCount = Environment.ProcessorCount; // TODO: finish other values #elif ANDROID try { Java.Util.TimeZone tz = Java.Util.TimeZone.Default; Java.Util.Date now = new Java.Util.Date(); UtcOffset = tz.GetOffset(now.Time) / 3600000.0; OSVersion = Android.OS.Build.VERSION.Sdk; Locale = CultureInfo.CurrentCulture.DisplayName; var metrics = Resources.System.DisplayMetrics; WindowBoundsWidth = metrics.WidthPixels; WindowBoundsHeight = metrics.HeightPixels; Context context = RaygunClient.Context; if (context != null) { PackageManager manager = context.PackageManager; PackageInfo info = manager.GetPackageInfo(context.PackageName, 0); PackageVersion = info.VersionCode + " / " + info.VersionName; IWindowManager windowManager = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); if (windowManager != null) { Display display = windowManager.DefaultDisplay; if (display != null) { switch (display.Rotation) { case SurfaceOrientation.Rotation0: CurrentOrientation = "Rotation 0 (Portrait)"; break; case SurfaceOrientation.Rotation180: CurrentOrientation = "Rotation 180 (Upside down)"; break; case SurfaceOrientation.Rotation270: CurrentOrientation = "Rotation 270 (Landscape right)"; break; case SurfaceOrientation.Rotation90: CurrentOrientation = "Rotation 90 (Landscape left)"; break; } } } } DeviceName = RaygunClient.DeviceName; Java.Lang.Runtime runtime = Java.Lang.Runtime.GetRuntime(); TotalPhysicalMemory = (ulong)runtime.TotalMemory(); AvailablePhysicalMemory = (ulong)runtime.FreeMemory(); ProcessorCount = runtime.AvailableProcessors(); Architecture = Android.OS.Build.CpuAbi; Model = string.Format("{0} / {1} / {2}", Android.OS.Build.Model, Android.OS.Build.Brand, Android.OS.Build.Manufacturer); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error getting environment info {0}", ex.Message)); } #elif IOS UtcOffset = NSTimeZone.LocalTimeZone.GetSecondsFromGMT / 3600.0; OSVersion = UIDevice.CurrentDevice.SystemName + " " + UIDevice.CurrentDevice.SystemVersion; Architecture = GetStringSysCtl(ArchitecturePropertyName); Model = UIDevice.CurrentDevice.Model; ProcessorCount = (int)GetIntSysCtl(ProcessiorCountPropertyName); Locale = CultureInfo.CurrentCulture.DisplayName; UIApplication.SharedApplication.InvokeOnMainThread(() => { WindowBoundsWidth = UIScreen.MainScreen.Bounds.Width; WindowBoundsHeight = UIScreen.MainScreen.Bounds.Height; }); CurrentOrientation = UIDevice.CurrentDevice.Orientation.ToString(); TotalPhysicalMemory = GetIntSysCtl(TotalPhysicalMemoryPropertyName); AvailablePhysicalMemory = GetIntSysCtl(AvailablePhysicalMemoryPropertyName); DeviceName = UIDevice.CurrentDevice.Name; PackageVersion = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString(); #else WindowBoundsWidth = SystemInformation.VirtualScreen.Height; WindowBoundsHeight = SystemInformation.VirtualScreen.Width; ComputerInfo info = new ComputerInfo(); Locale = CultureInfo.CurrentCulture.DisplayName; DateTime now = DateTime.Now; UtcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(now).TotalHours; OSVersion = info.OSVersion; if (!RaygunSettings.Settings.MediumTrust) { try { Architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"); TotalPhysicalMemory = (ulong)info.TotalPhysicalMemory / 0x100000; // in MB AvailablePhysicalMemory = (ulong)info.AvailablePhysicalMemory / 0x100000; TotalVirtualMemory = info.TotalVirtualMemory / 0x100000; AvailableVirtualMemory = info.AvailableVirtualMemory / 0x100000; GetDiskSpace(); Cpu = GetCpu(); } catch (SecurityException) { System.Diagnostics.Trace.WriteLine("RaygunClient error: couldn't access environment variables. If you are running in Medium Trust, in web.config in RaygunSettings set mediumtrust=\"true\""); } } #endif }
internal TimeSpan GetUtcOffset(long ticks) { var millis = (ticks / TimeSpan.TicksPerMillisecond) - DateTime.EraDifferenceInMs; var offsetInMs = _timeZone.GetOffset(millis); return new TimeSpan(offsetInMs * TimeSpan.TicksPerMillisecond); }
public RaygunEnvironmentMessage() { try { Java.Util.TimeZone tz = Java.Util.TimeZone.Default; Java.Util.Date now = new Java.Util.Date(); UtcOffset = tz.GetOffset(now.Time) / 3600000.0; OSVersion = Android.OS.Build.VERSION.Sdk; Locale = CultureInfo.CurrentCulture.DisplayName; var metrics = Resources.System.DisplayMetrics; WindowBoundsWidth = metrics.WidthPixels; WindowBoundsHeight = metrics.HeightPixels; Context context = RaygunClient.Context; if (context != null) { PackageManager manager = context.PackageManager; PackageInfo info = manager.GetPackageInfo(context.PackageName, 0); PackageVersion = info.VersionCode + " / " + info.VersionName; IWindowManager windowManager = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); if (windowManager != null) { Display display = windowManager.DefaultDisplay; if (display != null) { switch (display.Rotation) { case SurfaceOrientation.Rotation0: CurrentOrientation = "Rotation 0 (Portrait)"; break; case SurfaceOrientation.Rotation180: CurrentOrientation = "Rotation 180 (Upside down)"; break; case SurfaceOrientation.Rotation270: CurrentOrientation = "Rotation 270 (Landscape right)"; break; case SurfaceOrientation.Rotation90: CurrentOrientation = "Rotation 90 (Landscape left)"; break; } } } } DeviceName = "Unknown"; Java.Lang.Runtime runtime = Java.Lang.Runtime.GetRuntime(); TotalPhysicalMemory = (ulong)runtime.TotalMemory(); AvailablePhysicalMemory = (ulong)runtime.FreeMemory(); ProcessorCount = runtime.AvailableProcessors(); Architecture = Android.OS.Build.CpuAbi; Model = string.Format("{0} / {1} / {2}", Android.OS.Build.Model, Android.OS.Build.Brand, Android.OS.Build.Manufacturer); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Error getting environment info {0}", ex.Message)); } }