runtime: net6-ios: DateTimeOffset.Local does not have local timezone

From @dotMorten on Tue, 17 May 2022 22:49:14 GMT

Steps to Reproduce

  1. With an iOS device where timezone is != UTC, compare DateTimeOffset.Now and DateTimeOffset.UtcNow and notice they are the same.
  2. DateTimeOffset.UtcNow.ToLocalTime() has no real effect, since it thinks that is already the local timezone.
  3. DateTimeOffset.Parse("12/30/1997 10:00:00 PM +00:00").ToLocal() fails to convert this UTC timestamp to local time zone.
  4. Debug.WriteLine($"UTC: {DateTimeOffset.UtcNow}\nLocal: {DateTimeOffset.Now}\nLocal Converted: {DateTimeOffset.UtcNow.ToLocalTime()); prints the same timestamp each time.

Note: This does not reproduce with legacy Xamarin.iOS on the same device.

I can’t think of a workaround, and this bug could lead to some major data input/output issues. Due to the data-corruption issues this could cause (people missing their flights, invalid data getting entered and bad decisions made because of it etc), I’d consider something like this a showstopper.

Expected Behavior

DateTime/DateTimeOffset APIs understands the local timezone

Actual Behavior

Time zone not set

Environment

.NET 6.0.300, VS2022 17.3p1, .NET MAUI RC3. iOS 14

Version information ``` Microsoft Visual Studio Enterprise 2022 Version 17.2.0 Preview 6.0 VisualStudio.17.Preview/17.2.0-pre.6.0+32427.441 Microsoft .NET Framework Version 4.8.04084

Installed Version: Enterprise

Visual C++ 2022 00476-80000-00000-AA015 Microsoft Visual C++ 2022

ASP.NET and Web Tools 2019 17.2.386.48104 ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0 17.2.386.48104 Azure App Service Tools v3.0.0

C# Tools 4.2.0-4.22220.5+432d17a83aa5623e4581756f4d642997048056bd C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.2.20 (482eb2a) Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.2.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.0.0.2218101+885a343b00bcab620a90c1550c37dafd730ce984 Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.0.62204.01010 Microsoft SQL Server Data Tools

Syntax Visualizer 1.0 An extension for visualizing Roslyn SyntaxTrees.

Test Adapter for Boost.Test 1.0 Enables Visual Studio’s testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio’s testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 17.0.10418.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.2.0-4.22220.5+432d17a83aa5623e4581756f4d642997048056bd Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.1.0-beta.22178.3+6da0245a7ce4bb8483b8d1f2993c8ecaea967ad9 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info

Xamarin 17.2.0.171 (d17-2@7554231) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.2.0.244 (remotes/origin/d17-2@197e1a0b7) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.2.15 (2e3b60e) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 12.3.0.3 (d17-2/bbba5a2) Xamarin.Android Reference Assemblies and MSBuild support. Mono: adf1bc4 Java.Interop: xamarin/java.interop/d17-2@9760f0a9 ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.38.2@7b1e016 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-2@fc3c2ac

Xamarin.iOS and Xamarin.Mac SDK 15.10.0.1 (568bdb24e) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

</details>

### Build Logs

<!--
1. How to get a build log: https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#build-logs
2. Place the cursor below this comment block.
3. Drag and drop the build log.
-->

### Example Project (If Possible)

<!--
1. Place cursor below this comment block.
2. Drag and drop the compressed project or files needed to reproduce.
-->

<!--
Switch to the "Preview" tab to ensure your issue renders correctly.
-->


_Copied from original issue xamarin/xamarin-macios#15055_

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 16 (14 by maintainers)

Most upvoted comments

Can you try setting the TZ environment variable, e.g. to Europe/Paris ?

How do you do that? I could use the workaround for now just to get my tests to pass again

Looks like this does it:

Environment.SetEnvironmentVariable ("TZ", "Europe/Paris");
TimeZoneInfo.ClearCachedData ();