Exemplo n.º 1
0
        public static Date FindNearest(Date date, SkipQuantumEnum skip)
        {
            Date result;

            switch (skip)
            {
            case SkipQuantumEnum.DAYS:
                return(date);

            case SkipQuantumEnum.WEEKS:
                result = date;
                while (result.DayOfWeek != TimesCommon.Current.StartToWeek)
                {
                    result = result.AddDays(-1);
                }
                return(result);

            case SkipQuantumEnum.MONTHS:
                return(new Date(date.Year, date.Month, 1));

            case SkipQuantumEnum.QUARTERS:
                result = new Date(date.Year, date.Month, 1);
                while (result.Month != 1 && result.Month != 4 && result.Month != 7 && result.Month != 10)
                {
                    result = result.AddMonths(-1);
                }
                return(result);

            case SkipQuantumEnum.YEARS:
                return(new Date(date.Year, 1, 1));

            default:
                throw new NotSupportedException(String.Format("Unsupported option: {0}", skip));
            }
        }
Exemplo n.º 2
0
        private static Date Add(Date date, int length, SkipQuantumEnum quantum)
        {
            switch (quantum)
            {
            case SkipQuantumEnum.DAYS:
                return(date.AddDays(length));

            case SkipQuantumEnum.WEEKS:
                return(date.AddDays(length * 7));

            case SkipQuantumEnum.MONTHS:
                return(date.AddMonths(length));

            case SkipQuantumEnum.QUARTERS:
                return(date.AddMonths(length * 3));

            case SkipQuantumEnum.YEARS:
                return(date.AddYears(length));

            default:
                throw new NotSupportedException(String.Format("Unsupported option: {0}", quantum));
            }
        }
Exemplo n.º 3
0
 public DateDuration(SkipQuantumEnum quantum, int length)
 {
     Quantum = quantum;
     Length  = length;
 }