-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Calender.GetWeekOfYear is not compatible with ISO 8601 and date Unix utility #25762
Description
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).
- See 'First week' in https://en.wikipedia.org/wiki/ISO_week_date#Relation_with_the_Gregorian_calendar
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