// ---------------------------------------------------------------------- private void UpdateSelectedPeriodInfo() { TimeCalendar timeCalendar = TimeCalendar.New( SelectedYearBaseMonth ); switch ( SelectedPeriodMode ) { case TimePeriodMode.Year: Year year = new Year( WorkingDate, timeCalendar ); periodInfo.Clear(); periodInfo.AddItem( "Year", year ); periodInfo.AddItem( "YearBaseMonth", year.YearBaseMonth ); periodInfo.AddItem( "IsCalendarYear", year.IsCalendarYear ); periodInfo.AddItem( "StartYear", year.StartYear ); periodInfo.AddItem( "FirstDayStart", year.FirstDayStart ); periodInfo.AddItem( "LastDayStart", year.LastDayStart ); periodInfo.AddItem( "LastMonthStart", year.LastMonthStart ); periodInfo.AddItem( "YearName", year.YearName ); periodInfo.AddSection( "Previous/Next" ); periodInfo.AddItem( "Previous", year.GetPreviousYear() ); periodInfo.AddItem( "Next", year.GetNextYear() ); periodInfo.AddSubitems( "Halfyears", year.GetHalfyears() ); periodInfo.AddSubitems( "Quarters", year.GetQuarters() ); periodInfo.AddSubitems( "Months", year.GetMonths() ); SelectedPeriodInfo = periodInfo.ToString(); break; case TimePeriodMode.Halfyear: Halfyear halfyear = new Halfyear( WorkingDate, timeCalendar ); periodInfo.Clear(); periodInfo.AddItem( "Halfyear", halfyear ); periodInfo.AddItem( "YearBaseMonth", halfyear.YearBaseMonth ); periodInfo.AddItem( "StartMonth", halfyear.StartMonth ); periodInfo.AddItem( "Year", halfyear.Year ); periodInfo.AddItem( "YearHalfyear", halfyear.YearHalfyear ); periodInfo.AddItem( "IsCalendarHalfyear", halfyear.IsCalendarHalfyear ); periodInfo.AddItem( "MultipleCalendarYears", halfyear.MultipleCalendarYears ); periodInfo.AddItem( "HalfyearName", halfyear.HalfyearName ); periodInfo.AddItem( "HalfyearOfYearName", halfyear.HalfyearOfYearName ); periodInfo.AddItem( "LastDayStart", halfyear.LastDayStart ); periodInfo.AddItem( "LastMonthStart", halfyear.LastMonthStart ); periodInfo.AddSection( "Previous/Next" ); periodInfo.AddItem( "Previousr", halfyear.GetPreviousHalfyear() ); periodInfo.AddItem( "Next", halfyear.GetNextHalfyear() ); periodInfo.AddSubitems( "Quarters", halfyear.GetQuarters() ); periodInfo.AddSubitems( "Months", halfyear.GetMonths() ); SelectedPeriodInfo = periodInfo.ToString(); break; case TimePeriodMode.Quarter: Quarter quarter = new Quarter( WorkingDate, timeCalendar ); periodInfo.Clear(); periodInfo.AddItem( "Quarter", quarter ); periodInfo.AddItem( "YearBaseMonth", quarter.YearBaseMonth ); periodInfo.AddItem( "StartMonth", quarter.StartMonth ); periodInfo.AddItem( "Year", quarter.Year ); periodInfo.AddItem( "YearQuarter", quarter.YearQuarter ); periodInfo.AddItem( "IsCalendarQuarter", quarter.IsCalendarQuarter ); periodInfo.AddItem( "MultipleCalendarYears", quarter.MultipleCalendarYears ); periodInfo.AddItem( "QuarterName", quarter.QuarterName ); periodInfo.AddItem( "QuarterOfYearName", quarter.QuarterOfYearName ); periodInfo.AddItem( "LastDayStart", quarter.FirstDayStart ); periodInfo.AddItem( "LastMonthStart", quarter.LastDayStart ); periodInfo.AddSection( "Previous/Next" ); periodInfo.AddItem( "Previous", quarter.GetPreviousQuarter() ); periodInfo.AddItem( "Next", quarter.GetNextQuarter() ); periodInfo.AddSubitems( "Months", quarter.GetMonths() ); SelectedPeriodInfo = periodInfo.ToString(); break; case TimePeriodMode.Month: Month month = new Month( WorkingDate, timeCalendar ); periodInfo.Clear(); periodInfo.AddItem( "Month", month ); periodInfo.AddItem( "YearBaseMonth", month.YearMonth ); periodInfo.AddItem( "Year", month.Year ); periodInfo.AddItem( "DaysInMonth", month.DaysInMonth ); periodInfo.AddItem( "MonthName", month.MonthName ); periodInfo.AddItem( "MonthOfYearName", month.MonthOfYearName ); periodInfo.AddItem( "LastDayStart", month.FirstDayStart ); periodInfo.AddItem( "LastMonthStart", month.LastDayStart ); periodInfo.AddSection( "Previous/Next" ); periodInfo.AddItem( "Previous", month.GetPreviousMonth() ); periodInfo.AddItem( "Next", month.GetNextMonth() ); periodInfo.AddSubitems( "Days", month.GetDays() ); SelectedPeriodInfo = periodInfo.ToString(); break; case TimePeriodMode.Week: Week week = new Week( WorkingDate, timeCalendar ); periodInfo.Clear(); periodInfo.AddItem( "Week", week ); periodInfo.AddItem( "MultipleCalendarYears", week.MultipleCalendarYears ); periodInfo.AddItem( "FirstDayStart", week.FirstDayStart ); periodInfo.AddItem( "FirstDayOfWeek", week.FirstDayOfWeek ); periodInfo.AddItem( "LastDayStart", week.LastDayStart ); periodInfo.AddItem( "LastDayOfWeek", week.LastDayOfWeek ); periodInfo.AddItem( "WeekOfYear", week.WeekOfYear ); periodInfo.AddItem( "WeekOfYearName", week.WeekOfYearName ); periodInfo.AddSection( "Previous/Next" ); periodInfo.AddItem( "Previous", week.GetPreviousWeek() ); periodInfo.AddItem( "Next", week.GetNextWeek() ); periodInfo.AddSubitems( "Days", week.GetDays() ); SelectedPeriodInfo = periodInfo.ToString(); break; case TimePeriodMode.Day: Day day = new Day( WorkingDate, timeCalendar ); periodInfo.Clear(); periodInfo.AddItem( "Day", day ); periodInfo.AddItem( "Year", day.Year ); periodInfo.AddItem( "FirstDayStart", day.FirstDayStart ); periodInfo.AddItem( "Month", day.Month ); periodInfo.AddItem( "DayValue", day.DayValue ); periodInfo.AddItem( "DayOfWeek", day.DayOfWeek ); periodInfo.AddItem( "DayName", day.DayName ); periodInfo.AddItem( "FirstHourStart", day.FirstHourStart ); periodInfo.AddItem( "LastHourStart", day.LastHourStart ); periodInfo.AddSection( "Previous/Next" ); periodInfo.AddItem( "Previous", day.GetPreviousDay() ); periodInfo.AddItem( "Next", day.GetNextDay() ); periodInfo.AddSubitems( "Hours", day.GetHours() ); SelectedPeriodInfo = periodInfo.ToString(); break; case TimePeriodMode.Hour: Hour hour = new Hour( WorkingDate, timeCalendar ); periodInfo.Clear(); periodInfo.AddItem( "Hour", hour ); periodInfo.AddItem( "Year", hour.Year ); periodInfo.AddItem( "Month", hour.Month ); periodInfo.AddItem( "Day", hour.Day ); periodInfo.AddItem( "HourValue", hour.HourValue ); periodInfo.AddItem( "FirstMinuteStart", hour.FirstMinuteStart ); periodInfo.AddItem( "LastMinuteStart", hour.LastMinuteStart ); periodInfo.AddSection( "Previous/Next" ); periodInfo.AddItem( "Previous", hour.GetPreviousHour() ); periodInfo.AddItem( "Next", hour.GetNextHour() ); periodInfo.AddSubitems( "Minutes", hour.GetMinutes() ); SelectedPeriodInfo = periodInfo.ToString(); break; case TimePeriodMode.Minute: Minute minute = new Minute( WorkingDate, timeCalendar ); periodInfo.Clear(); periodInfo.AddItem( "Minute", minute ); periodInfo.AddItem( "Year", minute.Year ); periodInfo.AddItem( "Month", minute.Month ); periodInfo.AddItem( "Day", minute.Day ); periodInfo.AddItem( "Hour", minute.Hour ); periodInfo.AddItem( "MinuteValue", minute.MinuteValue ); periodInfo.AddSection( "Previous/Next" ); periodInfo.AddItem( "Previous", minute.GetPreviousMinute() ); periodInfo.AddItem( "Next", minute.GetNextMinute() ); SelectedPeriodInfo = periodInfo.ToString(); break; } }
// ---------------------------------------------------------------------- public ICalendarTimeRange FindLargestFreeTimeBlock( IEnumerable<ITimePeriod> reservations, ITimePeriod searchLimits = null, bool excludeWeekends = true) { TimePeriodCollection bookedPeriods = new TimePeriodCollection( reservations ); if ( searchLimits == null ) { searchLimits = bookedPeriods; // use boundary of reservations } if ( excludeWeekends ) { Week currentWeek = new Week( searchLimits.Start ); Week lastWeek = new Week( searchLimits.End ); do { ITimePeriodCollection days = currentWeek.GetDays(); foreach ( Day day in days ) { if ( !searchLimits.HasInside( day ) ) { continue; // outside of the search scope } if ( day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday ) { bookedPeriods.Add( day ); // // exclude weekend day } } currentWeek = currentWeek.GetNextWeek(); } while ( currentWeek.Start < lastWeek.Start ); } // calculate the gaps using the time calendar as period mapper TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<TimeRange>( new TimeCalendar() ); ITimePeriodCollection freeTimes = gapCalculator.GetGaps( bookedPeriods, searchLimits ); if ( freeTimes.Count == 0 ) { return null; } freeTimes.SortByDuration(); // move the largest gap to the start return new CalendarTimeRange( freeTimes[ 0 ] ); }
// ---------------------------------------------------------------------- private static DateTime GetDayOfCurrentWeek( DayOfWeek dayOfWeek ) { Week week = new Week(); foreach ( Day day in week.GetDays() ) { if ( day.DayOfWeek == dayOfWeek ) { return day.Start.Date; } } throw new InvalidOperationException(); }
public void DaysOfWeekSample() { Week week = new Week( 2012, 13 ); foreach ( Day day in week.GetDays() ) { Console.WriteLine( day ); } Console.WriteLine( "ISO 8601 Week" ); TimeCalendar calendarIso8601 = new TimeCalendar( new TimeCalendarConfig { YearWeekType = YearWeekType.Iso8601 } ); Week isoWeek = new Week( 2012, 13, calendarIso8601 ); foreach ( Day isoDay in isoWeek.GetDays() ) { Console.WriteLine( isoDay ); } }
public void WeekDaysSample() { Week week = new Week( new DateTime( 2011, 05, 13 ) ); foreach ( Day day in week.GetDays() ) { Console.WriteLine( "Day: {0}, DayOfWeek: {1}, Int: {2}", day, day.DayOfWeek, (int)day.DayOfWeek ); // > Day: Montag; 09.05.2011 | 0.23:59, DayOfWeek: Monday, Int: 1 // > Day: Dienstag; 10.05.2011 | 0.23:59, DayOfWeek: Tuesday, Int: 2 // > Day: Mittwoch; 11.05.2011 | 0.23:59, DayOfWeek: Wednesday, Int: 3 // > Day: Donnerstag; 12.05.2011 | 0.23:59, DayOfWeek: Thursday, Int: 4 // > Day: Freitag; 13.05.2011 | 0.23:59, DayOfWeek: Friday, Int: 5 // > Day: Samstag; 14.05.2011 | 0.23:59, DayOfWeek: Saturday, Int: 6 // > Day: Sonntag; 15.05.2011 | 0.23:59, DayOfWeek: Sunday, Int: 0 } }