38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
|
|
namespace ISO8601
|
|
{
|
|
public static class Calender
|
|
{
|
|
private static CultureInfo culture = CultureInfo.CurrentCulture;
|
|
|
|
private static int CalcDate(DateTime date)
|
|
{
|
|
return date.DayOfWeek != DayOfWeek.Sunday ? DayOfWeek.Thursday - date.DayOfWeek : (int)DayOfWeek.Tuesday - 7;
|
|
}
|
|
|
|
public static int GetYear(DateTime date)
|
|
{
|
|
date = date.AddDays(CalcDate(date));
|
|
return culture.Calendar.GetYear(date);
|
|
}
|
|
|
|
public static int GetMonth(DateTime date)
|
|
{
|
|
date = date.AddDays(CalcDate(date));
|
|
return culture.Calendar.GetMonth(date);
|
|
}
|
|
|
|
public static int GetWorkWeek(DateTime date)
|
|
{
|
|
date = date.AddDays(CalcDate(date));
|
|
return culture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
|
|
}
|
|
}
|
|
}
|