Пример #1
0
        /// <summary>以指定的比较类型比较指定日期早于、等于或晚于当前指定的日期</summary>
        /// <param name="t1">当前指定的日期</param>
        /// <param name="t2">要比较的日期</param>
        /// <param name="compareType">比较类型</param>
        /// <returns>以 -1、0、1 表示的早于、等于或晚于当前指定的日期</returns>
        public static int CompareTo_(this DateTime t1, DateTime t2, DateTimeCompareType compareType = DateTimeCompareType.None)
        {
            if (compareType == DateTimeCompareType.None)
            {
                return(t1.CompareTo(t2));
            }

            DateTime d1, d2;
            int      y1 = t1.Year, y2 = t2.Year;

            switch (compareType)
            {
            case DateTimeCompareType.ByYear:
                d1 = new DateTime(y1, 1, 1);
                d2 = new DateTime(y2, 1, 1);
                break;

            case DateTimeCompareType.ByHalfYear:
                d1 = new DateTime(y1, t1.GetHalfYear_(), 1);
                d2 = new DateTime(y2, t2.GetHalfYear_(), 1);
                break;

            case DateTimeCompareType.ByQuarter:
                d1 = new DateTime(y1, t1.GetQuarter_(), 1);
                d2 = new DateTime(y2, t2.GetQuarter_(), 1);
                break;

            case DateTimeCompareType.ByMonth:
                d1 = new DateTime(y1, t1.Month, 1);
                d2 = new DateTime(y2, t2.Month, 1);
                break;

            case DateTimeCompareType.ByWeek:
                if (y1 != y2)
                {
                    return(y1.CompareTo(y2));
                }
                return(t1.GetWeekOfYear_().CompareTo(t2.GetWeekOfYear_()));

            case DateTimeCompareType.ByDay:
                return(t1.Date.CompareTo(t2.Date));

            case DateTimeCompareType.ByHour:
                d1 = new DateTime(y1, t1.Month, t1.Day, t1.Hour, 0, 0);
                d2 = new DateTime(y2, t2.Month, t2.Day, t2.Hour, 0, 0);
                break;

            case DateTimeCompareType.ByMinute:
                d1 = new DateTime(y1, t1.Month, t1.Day, t1.Hour, t1.Minute, 0);
                d2 = new DateTime(y2, t2.Month, t2.Day, t2.Hour, t2.Minute, 0);
                break;

            default:
                d1 = new DateTime(y1, t1.Month, t1.Day, t1.Hour, t1.Minute, t1.Second);
                d2 = new DateTime(y2, t2.Month, t2.Day, t2.Hour, t2.Minute, t2.Second);
                break;
            }

            return(d1.CompareTo(d2));
        }
Пример #2
0
 public Alarm(DateTime time, AudioClip sound, int AnimNum, DateTimeCompareType type)
 {
     this.time    = time;
     this.sound   = sound;
     this.AnimNum = AnimNum;
     this.type    = type;
 }
Пример #3
0
        /// <summary>以指定的比较类型比较指定日期早于、等于或晚于当前指定的日期</summary>
        /// <param name="t1">当前指定的日期</param>
        /// <param name="t2">要比较的日期</param>
        /// <param name="compareType">比较类型</param>
        /// <returns>以 -1、0、1 表示的早于、等于或晚于当前指定的日期</returns>
        public static int CompareTo_(this DateTime t1, DateTime t2, DateTimeCompareType compareType = DateTimeCompareType.None)
        {
            if(compareType == DateTimeCompareType.None)
                return t1.CompareTo(t2);

            DateTime d1, d2;
            int y1 = t1.Year, y2 = t2.Year;
            switch(compareType)
            {
                case DateTimeCompareType.ByYear:
                    d1 = new DateTime(y1, 1, 1);
                    d2 = new DateTime(y2, 1, 1);
                    break;
                case DateTimeCompareType.ByHalfYear:
                    d1 = new DateTime(y1, t1.GetHalfYear_(), 1);
                    d2 = new DateTime(y2, t2.GetHalfYear_(), 1);
                    break;
                case DateTimeCompareType.ByQuarter:
                    d1 = new DateTime(y1, t1.GetQuarter_(), 1);
                    d2 = new DateTime(y2, t2.GetQuarter_(), 1);
                    break;
                case DateTimeCompareType.ByMonth:
                    d1 = new DateTime(y1, t1.Month, 1);
                    d2 = new DateTime(y2, t2.Month, 1);
                    break;
                case DateTimeCompareType.ByWeek:
                    if(y1 != y2)
                        return y1.CompareTo(y2);
                    return t1.GetWeekOfYear_().CompareTo(t2.GetWeekOfYear_());
                case DateTimeCompareType.ByDay:
                    return t1.Date.CompareTo(t2.Date);
                case DateTimeCompareType.ByHour:
                    d1 = new DateTime(y1, t1.Month, t1.Day, t1.Hour, 0, 0);
                    d2 = new DateTime(y2, t2.Month, t2.Day, t2.Hour, 0, 0);
                    break;
                case DateTimeCompareType.ByMinute:
                    d1 = new DateTime(y1, t1.Month, t1.Day, t1.Hour, t1.Minute, 0);
                    d2 = new DateTime(y2, t2.Month, t2.Day, t2.Hour, t2.Minute, 0);
                    break;
                default:
                    d1 = new DateTime(y1, t1.Month, t1.Day, t1.Hour, t1.Minute, t1.Second);
                    d2 = new DateTime(y2, t2.Month, t2.Day, t2.Hour, t2.Minute, t2.Second);
                    break;
            }

            return d1.CompareTo(d2);
        }
Пример #4
0
 /// <summary>以指定的比较类型比较指定日期是否不晚于当前指定的日期</summary>
 /// <param name="t1">当前指定的日期</param>
 /// <param name="t2">要比较的日期</param>
 /// <param name="compareType">比较类型</param>
 /// <returns>指示是否不晚于当前指定的日期</returns>
 public static bool NotGreaterThan_(this DateTime t1, DateTime t2, DateTimeCompareType compareType = DateTimeCompareType.None)
 {
     return(t1.CompareTo_(t2, compareType) <= 0);
 }
Пример #5
0
 /// <summary>以指定的比较类型比较指定日期是否等于当前指定的日期</summary>
 /// <param name="t1">当前指定的日期</param>
 /// <param name="t2">要比较的日期</param>
 /// <param name="compareType">比较类型</param>
 /// <returns>指示是否等于当前指定的日期</returns>
 public static bool Equals_(this DateTime t1, DateTime t2, DateTimeCompareType compareType = DateTimeCompareType.None)
 {
     return(t1.CompareTo_(t2, compareType) == 0);
 }
Пример #6
0
 /// <summary>以指定的比较类型比较指定日期是否早于当前指定的日期</summary>
 /// <param name="t1">当前指定的日期</param>
 /// <param name="t2">要比较的日期</param>
 /// <param name="compareType">比较类型</param>
 /// <returns>指示是否早于当前指定的日期</returns>
 public static bool LessThan_(this DateTime t1, DateTime t2, DateTimeCompareType compareType = DateTimeCompareType.None)
 {
     return(t1.CompareTo_(t2, compareType) < 0);
 }
Пример #7
0
 /// <summary>以指定的比较类型比较指定日期是否等于当前指定的日期</summary>
 /// <param name="t1">当前指定的日期</param>
 /// <param name="t2">要比较的日期</param>
 /// <param name="compareType">比较类型</param>
 /// <returns>指示是否等于当前指定的日期</returns>
 public static bool Equals_(this DateTime t1, DateTime t2, DateTimeCompareType compareType = DateTimeCompareType.None)
 {
     return t1.CompareTo_(t2, compareType) == 0;
 }
Пример #8
0
 /// <summary>以指定的比较类型比较指定日期是否不早于当前指定的日期</summary>
 /// <param name="t1">当前指定的日期</param>
 /// <param name="t2">要比较的日期</param>
 /// <param name="compareType">比较类型</param>
 /// <returns>指示是否不早于当前指定的日期</returns>
 public static bool NotLessThan_(this DateTime t1, DateTime t2, DateTimeCompareType compareType = DateTimeCompareType.None)
 {
     return t1.CompareTo_(t2, compareType) >= 0;
 }
Пример #9
0
 /// <summary>以指定的比较类型比较指定日期是否晚于当前指定的日期</summary>
 /// <param name="t1">当前指定的日期</param>
 /// <param name="t2">要比较的日期</param>
 /// <param name="compareType">比较类型</param>
 /// <returns>指示是否晚于当前指定的日期</returns>
 public static bool GreaterThan_(this DateTime t1, DateTime t2, DateTimeCompareType compareType = DateTimeCompareType.None)
 {
     return t1.CompareTo_(t2, compareType) > 0;
 }
Пример #10
0
    public static bool Compare(DateTime t1, DateTime t2, DateTimeCompareType type)
    {
        bool value = false;

        switch (type)
        {
        case DateTimeCompareType.Second:
            value = SecondCompare(t1, t2);
            break;

        case DateTimeCompareType.Minute:
            value = MinuteCompare(t1, t2);
            break;

        case DateTimeCompareType.Hour:
            value = HourCompare(t1, t2);
            break;

        case DateTimeCompareType.Day:
            value = DayCompare(t1, t2);
            break;

        case DateTimeCompareType.Month:
            value = MonthCompare(t1, t2);
            break;

        case DateTimeCompareType.Year:
            value = YearCompare(t1, t2);
            break;

        case DateTimeCompareType.MinuteSecond:
            value = MinuteSecondCompare(t1, t2);
            break;

        case DateTimeCompareType.HourMinute:
            value = HourMinuteCompare(t1, t2);
            break;

        case DateTimeCompareType.HourMinuteSecond:
            value = HourMinuteSecondCompare(t1, t2);
            break;

        case DateTimeCompareType.DayHour:
            value = DayHourCompare(t1, t2);
            break;

        case DateTimeCompareType.DayHourMinute:
            value = DayHourMinuteCompare(t1, t2);
            break;

        case DateTimeCompareType.DayHourMinuteSecond:
            value = DayHourMinuteSecondCompare(t1, t2);
            break;

        case DateTimeCompareType.MonthDay:
            value = MonthDayCompare(t1, t2);
            break;

        case DateTimeCompareType.MonthDayHour:
            value = MonthDayHourCompare(t1, t2);
            break;

        case DateTimeCompareType.MonthDayHourMinute:
            value = MonthDayHourMinuteCompare(t1, t2);
            break;

        case DateTimeCompareType.MonthDayHourMinuteSecond:
            value = MonthDayHourMinuteSecondCompare(t1, t2);
            break;

        case DateTimeCompareType.YearMonthDay:
            value = YearDayCompare(t1, t2);
            break;

        case DateTimeCompareType.YearMonthDayHour:
            value = YearDayHourCompare(t1, t2);
            break;

        case DateTimeCompareType.YearMonthDayHourMinute:
            value = YearDayHourMinuteCompare(t1, t2);
            break;

        case DateTimeCompareType.YearMonthDayHourMinuteSecond:
            value = YearDayHourMinuteSecondCompare(t1, t2);
            break;
        }
        return(value);
    }
Пример #11
0
    public void AddAlarm(DateTime time, AudioClip sound, int AnimNum, DateTimeCompareType type)
    {
        var alarm = new Alarm(time, sound, AnimNum, type);

        AlarmList.Add(alarm);
    }