Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rolfbjarne opened this issue May 18, 2022 · 16 comments
Closed

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

rolfbjarne opened this issue May 18, 2022 · 16 comments
Assignees
Labels
Milestone

Comments

@rolfbjarne
Copy link
Member

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@912d149
SQLite: xamarin/sqlite@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_
@rolfbjarne
Copy link
Member Author

From @dotMorten on Tue, 17 May 2022 22:50:02 GMT

@spouliot theorized here that this might be an issue: xamarin/xamarin-macios#14740 (comment)

@rolfbjarne
Copy link
Member Author

From @spouliot on Tue, 17 May 2022 22:53:26 GMT

hmm... did I theorized or terrorized ? 🦖

@rolfbjarne
Copy link
Member Author

From @dotMorten on Tue, 17 May 2022 23:37:37 GMT

@spouliot well you didn't follow up on your hunch so... 🔥 😁

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label May 18, 2022
@rolfbjarne
Copy link
Member Author

From @spouliot on Tue, 17 May 2022 23:51:08 GMT

I knew it 🦖 would bite me soon enough 😈

@rolfbjarne
Copy link
Member Author

From @rolfbjarne on Wed, 18 May 2022 13:30:23 GMT

I can reproduce this on:

  • iOS device

I can not reproduce this on:

  • iOS simulator
  • Mac Catalyst
  • macOS

@rolfbjarne
Copy link
Member Author

From @rolfbjarne on Wed, 18 May 2022 13:32:44 GMT

This is not a duplicate of xamarin/xamarin-macios#14740, because setting LANG=es_ES works around xamarin/xamarin-macios#14740, but does not work for this issue.

@rolfbjarne
Copy link
Member Author

@dalexsoto FYI this might be an important bug/fix to get out asap.

@akoeplinger
Copy link
Member

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

@ghost
Copy link

ghost commented May 18, 2022

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

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@912d149
SQLite: xamarin/sqlite@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_

<table>
  <tr>
    <th align="left">Author:</th>
    <td>rolfbjarne</td>
  </tr>
  <tr>
    <th align="left">Assignees:</th>
    <td>-</td>
  </tr>
  <tr>
    <th align="left">Labels:</th>
    <td>

`area-System.Runtime`, `untriaged`

</td>
  </tr>
  <tr>
    <th align="left">Milestone:</th>
    <td>-</td>
  </tr>
</table>
</details>

@steveisok steveisok added the os-ios Apple iOS label May 18, 2022
@ghost
Copy link

ghost commented May 18, 2022

Tagging subscribers to 'os-ios': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

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@912d149
SQLite: xamarin/sqlite@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_

<table>
  <tr>
    <th align="left">Author:</th>
    <td>rolfbjarne</td>
  </tr>
  <tr>
    <th align="left">Assignees:</th>
    <td>-</td>
  </tr>
  <tr>
    <th align="left">Labels:</th>
    <td>

`area-System.Runtime`, `untriaged`, `os-ios`

</td>
  </tr>
  <tr>
    <th align="left">Milestone:</th>
    <td>-</td>
  </tr>
</table>
</details>

@steveisok steveisok added the os-tvos Apple tvOS label May 18, 2022
@rolfbjarne
Copy link
Member Author

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

Yeah, that worked.

@dotMorten
Copy link

dotMorten commented May 18, 2022

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

@rolfbjarne
Copy link
Member Author

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 ();

@steveisok steveisok removed the untriaged New issue has not been triaged by the area owner label May 18, 2022
@steveisok steveisok added this to the 6.0.x milestone May 18, 2022
@steveisok
Copy link
Member

Looks like we purposefully use UTC if we can't figure out the local time zone.

// If it's empty, use UTC (TryGetLocalTzFile() should return false).
if (tzVariable.Length == 0)
{
return false;
}

We'll need to instead grab the local time zone name off of the device.

@steveisok
Copy link
Member

Fixed by #70149

@ghost ghost locked as resolved and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants