コード例 #1
0
        bool _HogeWeek( DateTime date, repeat_infoCondition condition, RepeatEventType repeatEventType )
        {
            // 曜日が違っていたら予定なし
            if( condition.weekSpecified )
            {
                if( (int)date.DayOfWeek != condition.week )
                {
                    return	false;
                }
            }

            // 何週目か
            var	weekIndex		= 0;
            var	lastWeekIndex	= 0;
            {
                // 最初の日
                var	firstDay	= new DateTime( date.Year, date.Month, 1 );
                var	lastDay	= firstDay.AddMonths( 1 ).AddDays( -1 );		// 次の月ー1日

                weekIndex		= (date.Day + (int)firstDay.DayOfWeek - 1) / 7;
                lastWeekIndex	= (lastDay.Day + (int)firstDay.DayOfWeek - 1) / 7;
            }

            switch( repeatEventType )
            {
            case	RepeatEventType.week:
                // 毎週
                break;
            case	RepeatEventType.Item1stweek:
                // 毎月第1週
                if( weekIndex != 0 )
                {
                    return	false;
                }
                break;
            case	RepeatEventType.Item2ndweek:
                // 毎月第2週
                if( weekIndex != 1 )
                {
                    return	false;
                }
                break;
            case	RepeatEventType.Item3rdweek:
                // 毎月第3週
                if( weekIndex != 2 )
                {
                    return	false;
                }
                break;
            case	RepeatEventType.Item4thweek:
                // 毎月第4週
                if( weekIndex != 3 )
                {
                    return	false;
                }
                break;
            case	RepeatEventType.lastweek:
                // 毎月最終
                if( weekIndex != lastWeekIndex )
                {
                    return	false;
                }
                break;
            default:
                Debug.Assert( false, "週以外のタイプが指定されています。" );
                break;
            }

            return	true;
        }
コード例 #2
0
        bool _HasSchedule( DateTime date, repeat_infoCondition condition )
        {
            // 開始日より前なら予定なし
            if( date < condition.start_date )
            {
                return	false;
            }
            // 期限より後なら予定なし
            if( condition.end_dateSpecified )
            {
                if( date > condition.end_date )
                {
                    return	false;
                }
            }

            switch( condition.type )
            {
            case	RepeatEventType.day:
                // 毎日
                break;
            case	RepeatEventType.weekday:
                // 平日(土日を除く)
                if( date.DayOfWeek == DayOfWeek.Saturday ||
                    date.DayOfWeek == DayOfWeek.Sunday )
                {
                    return	false;
                }
                break;
            case	RepeatEventType.week:
            case	RepeatEventType.Item1stweek:
            case	RepeatEventType.Item2ndweek:
            case	RepeatEventType.Item3rdweek:
            case	RepeatEventType.Item4thweek:
            case	RepeatEventType.lastweek:
                return	_HogeWeek( date, condition, condition.type );
            case	RepeatEventType.month:
                // 毎月
                {
                    // 日
                    if( condition.daySpecified )
                    {
                        if( date.Day != condition.day )
                        {
                            return	false;
                        }
                    }
                    else
                    {
                        // 月末
                        if( date.Month == date.AddDays( 1 ).Month )
                        {
                            return	false;
                        }
                    }
                }
                break;
            default:
                break;
            }

            return	true;
        }