Skip to content

Calender.GetWeekOfYear is not compatible with ISO 8601 and date Unix utility #25762

Closed

Description

@iSazonov

System.Threading.Thread.CurrentThread.CurrentCulture.Calendar.GetWeekOfYear() return values that are not compatible with ISO 8601 and date Unix utility in some edge cases.

ISO related link

The issue was discovered in PowerShell repo PowerShell/PowerShell#6542 (You should use the build if you want tests with PowerShell Core Get-Date cmdlet).

If it is on a Sunday, it is part of week 52 of the previous year.

#'2017-01-01' is 'Sunday, January 1, 2017 12:00:00 AM'
date -d 2017-01-01 +%V #return 52 - right
Get-date 2017-01-01 -UFormat "%V" #return 1 - bug

If 31 December is on a Monday, Tuesday or Wednesday, it is in week 01 of the next year.

#'2007-12-31' is 'Monday, December 31, 2007 12:00:00 AM'
date -d 2011-12-31 +%V #return 01 - right
Get-date 2011-12-31 -UFormat "%V" #return 53 - bug

Activity

  1. tarekgh commented on Apr 4, 2018

    @tarekgh
    Member

    Yes, we are not fully compatible with ISO 8601, you may look at the blog https://blogs.msdn.microsoft.com/shawnste/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net/ for more info which also suggests how you can get the compatible ISO 8601 behavior.

    If you want the framework support ISO 8601, please feel free to open new API proposal issue for that. Thanks for reporting the issue.

  2. iSazonov commented on Apr 9, 2018

    @iSazonov
    ContributorAuthor

    @tarekgh Thank for great link!

    Issue for API proposal dotnet/corefx#28933

  3. transferred this issue fromdotnet/corefxon Jan 31, 2020
  4. added this to the 2.1.0 milestone on Jan 31, 2020
  5. ghost locked as resolved and limited conversation to collaborators on Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.GlobalizationquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions