Inheritance: WeekTimeRange
        public WeekOverviewViewModel()
        {
            _dataService = new MainDataService();
            _currentUserName = _dataService.UserName;

            CurrentFirstDayOfWeek = new Week(DateTime.Now).FirstDayOfWeek;
        }
Beispiel #2
0
 public void EnAuCultureTest()
 {
     CultureInfo cultureInfo = new CultureInfo( "en-AU" );
     //	cultureInfo.DateTimeFormat.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek;
     TimeCalendar calendar = new TimeCalendar( new TimeCalendarConfig { Culture = cultureInfo } );
     Week week = new Week( new DateTime( 2011, 4, 1, 9, 0, 0 ), calendar );
     Assert.AreEqual( week.Start, new DateTime( 2011, 3, 28 ) );
 }
Beispiel #3
0
        public void DanishUsCultureTest()
        {
            CultureInfo danishCulture = new CultureInfo( "da-DK" );
            Week danishWeek = new Week( 2011, 36, new TimeCalendar( new TimeCalendarConfig { Culture = danishCulture } ) );
            Assert.AreEqual( danishWeek.Start.Date, new DateTime( 2011, 9, 5 ) );
            Assert.AreEqual( danishWeek.End.Date, new DateTime( 2011, 9, 11 ) );

            CultureInfo usCulture = new CultureInfo( "en-US" );
            usCulture.DateTimeFormat.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek;
            Week usWeek = new Week( 2011, 36, new TimeCalendar( new TimeCalendarConfig { Culture = usCulture } ) );
            Assert.AreEqual( usWeek.Start.Date, new DateTime( 2011, 9, 4 ) );
            Assert.AreEqual( usWeek.End.Date, new DateTime( 2011, 9, 10 ) );
        }
        } // CalculateEnd

        // ----------------------------------------------------------------------
        private Week FindNextWeek(Week current)
        {
            if (ExcludePeriods.Count == 0)
            {
                return(current.GetNextWeek());
            }

            TimeRange limits = new TimeRange(current.End.AddTicks(1), DateTime.MaxValue);
            TimeGapCalculator <TimeRange> gapCalculator    = new TimeGapCalculator <TimeRange> (calendar);
            ITimePeriodCollection         remainingPeriods = gapCalculator.GetGaps(ExcludePeriods, limits);

            return(remainingPeriods.Count > 0 ? new Week(remainingPeriods[0].Start) : null);
        } // FindNextWeek
Beispiel #5
0
 // ----------------------------------------------------------------------
 public static void ShowWeek( Week week, string caption = "Week" )
 {
     WriteLine( "{0}: {1}", caption, week );
     WriteIndentLine( "MultipleCalendarYears: {0}", week.MultipleCalendarYears );
     WriteIndentLine( "FirstDayStart: {0}", Format( week.FirstDayStart ) );
     WriteIndentLine( "FirstDayOfWeek: {0}", week.FirstDayOfWeek );
     WriteIndentLine( "LastDayStart: {0}", Format( week.LastDayStart ) );
     WriteIndentLine( "LastDayOfWeek: {0}", Format( week.LastDayOfWeek ) );
     WriteIndentLine( "LastDayOfWeek: {0}", week.LastDayOfWeek );
     WriteIndentLine( "WeekOfYear: {0}", week.WeekOfYear );
     WriteIndentLine( "WeekOfYearName: {0}", week.WeekOfYearName );
     WriteLine();
 }
        } // FindNextWeek

        // ----------------------------------------------------------------------
        private Week FindPreviousWeek(Week current)
        {
            if (ExcludePeriods.Count == 0)
            {
                return(current.GetPreviousWeek());
            }

            TimeRange limits = new TimeRange(DateTime.MinValue, current.Start.AddTicks(-1));
            TimeGapCalculator <TimeRange> gapCalculator    = new TimeGapCalculator <TimeRange> (calendar);
            ITimePeriodCollection         remainingPeriods = gapCalculator.GetGaps(ExcludePeriods, limits);

            return(remainingPeriods.Count > 0 ? new Week(remainingPeriods[remainingPeriods.Count - 1].End) : null);
        } // FindPreviousWeek
        }         // Add

        // ----------------------------------------------------------------------
        protected DateTime?CalculateEnd(DateTime start, TimeSpan offset,
                                        SeekDirection seekDirection, SeekBoundaryMode seekBoundaryMode)
        {
            if (offset < TimeSpan.Zero)
            {
                throw new InvalidOperationException("time span must be positive");
            }

            DateTime?endDate   = null;
            DateTime moment    = start;
            TimeSpan?remaining = offset;
            Week     week      = new Week(start, calendar);

            // search end date, iteraring week by week
            while (week != null)
            {
                base.IncludePeriods.Clear();
                base.IncludePeriods.AddAll(GetAvailableWeekPeriods(week));

                endDate = CalculateEnd(moment, remaining.Value, seekDirection, seekBoundaryMode, out remaining);
                if (endDate != null || !remaining.HasValue)
                {
                    break;
                }

                switch (seekDirection)
                {
                case SeekDirection.Forward:
                    week = FindNextWeek(week);
                    if (week != null)
                    {
                        moment = week.Start;
                    }
                    break;

                case SeekDirection.Backward:
                    week = FindPreviousWeek(week);
                    if (week != null)
                    {
                        moment = week.End;
                    }
                    break;
                }
            }

            return(endDate);
        }         // CalculateEnd
Beispiel #8
0
        // ----------------------------------------------------------------------
        public static void ShowAll( int periodCount, int year, int weekOfYear, TimeCalendarConfig calendarConfig )
        {
            WriteLine( "Input: year={0}, week={1}", year, weekOfYear );
            WriteLine();

            WeekTimeRange weekTimeRange;
            if ( periodCount == 1 )
            {
                Week week = new Week( year, weekOfYear, new TimeCalendar( calendarConfig ) );
                weekTimeRange = week;

                Week previousWeek = week.GetPreviousWeek();
                Week nextWeek = week.GetNextWeek();

                ShowWeek( week );
                ShowCompactWeek( previousWeek, "Previous Week" );
                ShowCompactWeek( nextWeek, "Next Week" );
                WriteLine();
            }
            else
            {
                Weeks weeks = new Weeks( year, weekOfYear, periodCount, new TimeCalendar( calendarConfig ) );
                weekTimeRange = weeks;

                ShowWeeks( weeks );
                WriteLine();

                foreach ( Week week in weeks.GetWeeks() )
                {
                    ShowCompactWeek( week );
                }
                WriteLine();
            }

            foreach ( Day day in weekTimeRange.GetDays() )
            {
                DayDemo.ShowCompactDay( day );
            }
            WriteLine();
        }
Beispiel #9
0
        public void DefaultCalendarTest()
        {
            const int startWeek = 1;
            int currentYear = ClockProxy.Clock.Now.Year;
            CultureTestData cultures = new CultureTestData();
            foreach ( CultureInfo culture in cultures )
            {
                foreach ( YearWeekType yearWeekType in Enum.GetValues( typeof( YearWeekType ) ) )
                {
                    int weeksOfYear = TimeTool.GetWeeksOfYear( currentYear, culture, yearWeekType );
                    for ( int weekOfYear = startWeek; weekOfYear < weeksOfYear; weekOfYear++ )
                    {
                        Week week = new Week( currentYear, weekOfYear, TimeCalendar.New( culture, YearMonth.January, yearWeekType ) );
                        Assert.AreEqual( week.Year, currentYear );

                        DateTime weekStart = TimeTool.GetStartOfYearWeek( currentYear, weekOfYear, culture, yearWeekType );
                        DateTime weekEnd = weekStart.AddDays( TimeSpec.DaysPerWeek );
                        Assert.AreEqual( week.Start, weekStart.Add( week.Calendar.StartOffset ) );
                        Assert.AreEqual( week.End, weekEnd.Add( week.Calendar.EndOffset ) );
                    }
                }
            }
        }
        // ----------------------------------------------------------------------
        private void SelectPeriod( PeriodSelectType periodSelectType )
        {
            int offset = 0;
            switch ( periodSelectType )
            {
                case PeriodSelectType.Previous:
                    offset = -1;
                    break;
                case PeriodSelectType.Current:
                    ResetWorkingPeriod();
                    return;
                case PeriodSelectType.Next:
                    offset = 1;
                    break;
            }

            switch ( WorkingTimePeriod )
            {
                case TimePeriodMode.Year:
                    Year year = new Year( WorkingPeriodStartDate );
                    SetWorkingPeriod( year.AddYears( offset ) );
                    break;
                case TimePeriodMode.Halfyear:
                    Halfyear halfyear = new Halfyear( WorkingPeriodStartDate );
                    SetWorkingPeriod( halfyear.AddHalfyears( offset ) );
                    break;
                case TimePeriodMode.Quarter:
                    Quarter quarter = new Quarter( WorkingPeriodStartDate );
                    SetWorkingPeriod( quarter.AddQuarters( offset ) );
                    break;
                case TimePeriodMode.Month:
                    Month month = new Month( WorkingPeriodStartDate );
                    SetWorkingPeriod( month.AddMonths( offset ) );
                    break;
                case TimePeriodMode.Week:
                    Week week = new Week( WorkingPeriodStartDate );
                    SetWorkingPeriod( week.AddWeeks( offset ) );
                    break;
                case TimePeriodMode.Day:
                    Day day = new Day( WorkingPeriodStartDate );
                    SetWorkingPeriod( day.AddDays( offset ) );
                    break;
            }
        }
 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
     }
 }
 public void WeekStartEndSample()
 {
     Week week = new Week( new DateTime( 2012, 6, 1 ) );
     while ( week.Start.Month < 7 )
     {
         Console.WriteLine( "week : " + week );
         week = week.GetNextWeek();
     }
     // > week : w/c 22 2012; 28.05.2012 - 03.06.2012 | 6.23:59
     // > week : w/c 23 2012; 04.06.2012 - 10.06.2012 | 6.23:59
     // > week : w/c 24 2012; 11.06.2012 - 17.06.2012 | 6.23:59
     // > week : w/c 25 2012; 18.06.2012 - 24.06.2012 | 6.23:59
     // > week : w/c 26 2012; 25.06.2012 - 01.07.2012 | 6.23:59
 }
 // ----------------------------------------------------------------------
 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();
 }
Beispiel #14
0
 // ----------------------------------------------------------------------
 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 int CountWorkingDays( DateTime start, DateTime end, IList<DayOfWeek> workingDays )
        {
            if ( workingDays.Count == 0 )
            {
                return 0;
            }

            Week startWeek = new Week( start );
            Week endWeek = new Week( end );
            int dayCount = 0;

            // start week
            DateTime currentDay = start.Date;
            while ( currentDay < startWeek.End )
            {
                if ( workingDays.Contains( currentDay.DayOfWeek ) )
                {
                    dayCount++;
                }
                currentDay = currentDay.AddDays( 1 );
            }

            // between weeks
            DateDiff inBetweenWeekDiff = new DateDiff( startWeek.End, endWeek.Start );
            dayCount += inBetweenWeekDiff.Weeks * workingDays.Count;

            // end week
            currentDay = endWeek.Start.Date;
            while ( currentDay < end )
            {
                if ( workingDays.Contains( currentDay.DayOfWeek ) )
                {
                    dayCount++;
                }
                currentDay = currentDay.AddDays( 1 );
            }

            return dayCount;
        }
Beispiel #16
0
        // ----------------------------------------------------------------------
        private Week FindPreviousWeek( Week current )
        {
            if ( ExcludePeriods.Count == 0 )
            {
                return current.GetPreviousWeek();
            }

            TimeRange limits = new TimeRange( DateTime.MinValue, current.Start.AddTicks( -1 ) );
            TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<TimeRange>( calendar );
            ITimePeriodCollection remainingPeriods = gapCalculator.GetGaps( ExcludePeriods, limits );
            return remainingPeriods.Count > 0 ? new Week( remainingPeriods[ remainingPeriods.Count - 1 ].End ) : null;
        }
Beispiel #17
0
        // ----------------------------------------------------------------------
        private Week FindNextWeek( Week current )
        {
            if ( ExcludePeriods.Count == 0 )
            {
                return current.GetNextWeek();
            }

            TimeRange limits = new TimeRange( current.End.AddTicks( 1 ), DateTime.MaxValue );
            TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<TimeRange>( calendar );
            ITimePeriodCollection remainingPeriods = gapCalculator.GetGaps( ExcludePeriods, limits );
            return remainingPeriods.Count > 0 ? new Week( remainingPeriods[ 0 ].Start ) : null;
        }
Beispiel #18
0
        // ----------------------------------------------------------------------
        protected DateTime? CalculateEnd( DateTime start, TimeSpan offset,
			SeekDirection seekDirection, SeekBoundaryMode seekBoundaryMode )
        {
            if ( offset < TimeSpan.Zero )
            {
                throw new InvalidOperationException( "time span must be positive" );
            }

            DateTime? endDate = null;
            DateTime moment = start;
            TimeSpan? remaining = offset;
            Week week = new Week( start, calendar );

            // search end date, iteraring week by week
            while ( week != null )
            {
                base.IncludePeriods.Clear();
                base.IncludePeriods.AddAll( GetAvailableWeekPeriods( week ) );

                endDate = CalculateEnd( moment, remaining.Value, seekDirection, seekBoundaryMode, out remaining );
                if ( endDate != null || !remaining.HasValue )
                {
                    break;
                }

                switch ( seekDirection )
                {
                    case SeekDirection.Forward:
                        week = FindNextWeek( week );
                        if ( week != null )
                        {
                            moment = week.Start;
                        }
                        break;
                    case SeekDirection.Backward:
                        week = FindPreviousWeek( week );
                        if ( week != null )
                        {
                            moment = week.End;
                        }
                        break;
                }
            }

            return endDate;
        }
Beispiel #19
0
        // ----------------------------------------------------------------------
        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 ] );
        }
        public void WeekCultureSample()
        {
            Week currentCultureWeek = new Week( 2011, 1 );
            Console.WriteLine( "Week: {0}, Culture: {1}", currentCultureWeek, currentCultureWeek.Calendar.Culture.DisplayName );
            // > Week: w/c 1 2011; 03.01.2011 - 09.01.2011 | 6.23:59, Culture: German (Switzerland)

            Week enUsWeek = new Week( 2011, 1, new TimeCalendar( new TimeCalendarConfig { Culture = new CultureInfo( "en-US" ) } ) );
            Console.WriteLine( "Week: {0}, Culture: {1}", enUsWeek, enUsWeek.Calendar.Culture.DisplayName );
            // > Week: w/c 1 2011; 01.01.2011 - 07.01.2011 | 6.23:59, Culture: English (United States)

            Week deChWeek = new Week( 2011, 1, new TimeCalendar( new TimeCalendarConfig { Culture = new CultureInfo( "de-CH" ) } ) );
            Console.WriteLine( "Week: {0}, Culture: {1}", deChWeek, deChWeek.Calendar.Culture.DisplayName );
            // > Week: w/c 1 2011; 03.01.2011 - 09.01.2011 | 6.23:59, Culture: German (Switzerland)
        }
        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 );
            }
        }
Beispiel #22
0
 // ----------------------------------------------------------------------
 public static void ShowCompactWeek( Week week, string caption = "Week" )
 {
     WriteLine( "{0}: {1}", caption, week );
 }
        public void FiscalYearWeekCountSample()
        {
            TimeCalendar calendar = new TimeCalendar(
                new TimeCalendarConfig
                {
                    YearBaseMonth = YearMonth.April,  //  April year base month
                    //YearWeekType = YearWeekType.Iso8601, // ISO 8601 week numbering
                    YearType = YearType.FiscalYear// treat years as fiscal years
                } );

            bool countOnlyFullWeeks = true;
            Year year = new Year( 2012, calendar );
            foreach ( Month month in year.GetMonths() )
            {
                Month nextMonth = month.GetNextMonth();
                Week week = new Week( month.Start.Date );
                int weekCount = 0;
                while ( week.Start.Date < nextMonth.Start.Date )
                {
                    if ( countOnlyFullWeeks )
                    {
                        if ( month.HasInside( week ) )
                        {
                            weekCount++;
                        }
                    }
                    else
                    {
                        weekCount++;
                    }
                    week = week.GetNextWeek();
                }
                Console.WriteLine( "Month: " + month + ", Tot Weeks : " + weekCount );
            }
        }