示例#1
0
        public void SetElementValue(decimal newValue, TimeVariableType type)
        {
            switch (type)
            {
            case TimeVariableType.Year:
            {
                TimeValidator.ValidateYear((int)newValue);
                ChangeYear((int)newValue);     // special method considering leap years
                break;
            }

            case TimeVariableType.Month:
            {
                TimeValidator.ValidateMonth((int)newValue);
                TimeValidator.ValidateDay(value.Day, (int)newValue, value.Day);
                value = new DateTime(value.Year, (int)newValue, value.Day);
                break;
            }

            case TimeVariableType.Day:
            {
                TimeValidator.ValidateDay(value.Day, value.Month, (int)newValue);
                value = new DateTime(value.Year, value.Month, (int)newValue);
                break;
            }

            case TimeVariableType.Hour:
            {
                TimeValidator.ValidateHour((int)newValue);
                TimeSpan ts = new TimeSpan((int)newValue, value.Minute, value.Second);
                value = value.Date + ts;
                break;
            }

            case TimeVariableType.Minute:
            {
                TimeValidator.ValidateMinute((int)newValue);
                TimeSpan ts = new TimeSpan(value.Hour, (int)newValue, value.Second);
                value = value.Date + ts;
                break;
            }

            case TimeVariableType.Second:
            {
                TimeValidator.ValidateSecond((int)newValue);
                TimeSpan ts = new TimeSpan(value.Hour, value.Minute, (int)newValue);
                value = value.Date + ts;
                break;
            }
            }
        }
        public override DateTime ToTime()
        {
            int hour   = (int)arg0.ToNumber();
            int minute = (int)arg1.ToNumber();

            TimeValidator.ValidateHour(hour);
            TimeValidator.ValidateMinute(minute);

            DateTime s  = DateTime.Now.AddDays(1);
            TimeSpan ts = new TimeSpan(hour, minute, 0);

            s = s.Date + ts;
            return(s);
        }
示例#3
0
        public override DateTime ToTime()
        {
            int hour   = (int)arg0.ToNumber();
            int minute = (int)arg1.ToNumber();
            int second = (int)arg2.ToNumber();

            TimeValidator.ValidateHour(hour);
            TimeValidator.ValidateMinute(minute);
            TimeValidator.ValidateSecond(second);

            DateTime s  = DateTime.Now;
            TimeSpan ts = new TimeSpan(hour, minute, second);

            s = s.Date + ts;
            return(s);
        }