public static GetWeekOfYear ( this moment, CultureInfo culture, CalendarWeekRule weekRule, DayOfWeek firstDayOfWeek, WeekOfYearRuleKind weekOfYearRule ) : YearAndWeek | ||
moment | this | |
culture | CultureInfo | |
weekRule | CalendarWeekRule | |
firstDayOfWeek | DayOfWeek | |
weekOfYearRule | WeekOfYearRuleKind | |
return | YearAndWeek |
/// <summary> /// 지정된 일자의 주차(Week of Year)를 반환합니다. (<see cref="CalendarWeekRule"/>, <see cref="ITimeCalendar.FirstDayOfWeek"/>에 따라 달라집니다) /// </summary> /// <param name="time"></param> /// <returns></returns> public int GetWeekOfYear(DateTime time) { int year, weekOfYear; TimeTool.GetWeekOfYear(time, Culture, WeekOfYearRule, out year, out weekOfYear); return(weekOfYear); }
public void WeekOfYearIso8601Test() { var moment = new DateTime(2007, 12, 31); CultureTestData.Default .RunEach(culture => { if (culture.DateTimeFormat.CalendarWeekRule != CalendarWeekRule.FirstFourDayWeek || culture.DateTimeFormat.FirstDayOfWeek != DayOfWeek.Monday) { return; } TimeTool.GetWeekOfYear(moment, culture, WeekOfYearRuleKind.Iso8601).Week.Should().Be(1); }); }
public void WeekOfYearCalendarTest() { var period = new TimeRange(new DateTime(2007, 12, 31), new DateTime(2009, 12, 31)); var moments = TimeTool.ForEachDays(period) #if !SILVERLIGHT .AsParallel() .AsOrdered() #endif .Select(p => p.Start); foreach (var culture in CultureTestData.Default) { var rule = WeekTool.GetWeekOfYearRuleKind(culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek); if (rule == WeekOfYearRuleKind.Iso8601) { continue; } foreach (var moment in moments) { var calendarWeekOfYear = culture.Calendar.GetWeekOfYear(moment, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek); var yearAndWeek = TimeTool.GetWeekOfYear(moment, culture, WeekOfYearRuleKind.Calendar); Assert.AreEqual(calendarWeekOfYear, yearAndWeek.Week, "calendar WeekOfYear=[{0}], yearAndWeek=[{1}], culture=[{2}], momnent=[{3}], weekRule=[{4}], FirstDayOfWeek=[{5}]", calendarWeekOfYear, yearAndWeek, culture, moment, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek); } } }