-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Labels
HackathonIssues picked for HackathonIssues picked for Hackathonapi-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Globalizationhelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors
Milestone
Description
Rationale
.Net don't implement ISO 8601 standard - it have alternative scheme in:
System.Globalization.Calendar.GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek);
Unix date
utility implements ISO 8601:
date +%V
In PowerShell repo we use workaround described here (see Keno's comment) for:
Get-Date -UFormat %V
.Net should have parity and native implementation.
ISO 8601 is culture-independent so we can use static methods.
If we are going in the direction I believe it make sense consider all ISO8601 objects and compatibility with Unix date
utility.
https://en.wikipedia.org/wiki/ISO_week_date#Relation_with_the_Gregorian_calendar
- first week
- last week
- weeks per year
http://man7.org/linux/man-pages/man1/date.1.html
%g
last two digits of year of ISO week number (see %G)%G
year of ISO week number (see %V); normally useful only with %V%V
ISO week number, with Monday as first day of week (01..53)
Proposed API
namespace System.Globalization
{
public abstract class Calendar : ICloneable
{
public static class ISOWeek
{
public static int GetWeekOfYear(DateTime time);
public static int GetYear(DateTime time);
public static DateTime GetYearStart(int year);
public static DateTime GetYearEnd(int year);
public static int GetWeeksInYear(int year);
public static DateTime ToDateTime(int year, int week, DayOfWeek day);
}
}
Please note that the proposed API is a static and not instance member. The reason is ISO week is culture and calendar independent.
rubenprinsB-Art
Metadata
Metadata
Assignees
Labels
HackathonIssues picked for HackathonIssues picked for Hackathonapi-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Globalizationhelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors