예제 #1
0
        }         // GetDuration

        #endregion

        #region Period

        // ----------------------------------------------------------------------
        public virtual string GetPeriod(DateTime start, DateTime end, TimeSpan duration)
        {
            if (end < start)
            {
                throw new ArgumentOutOfRangeException("end");
            }

            bool startHasTimeOfDay = TimeTool.HasTimeOfDay(start);

            // no duration - schow start date (optionally with the time part)
            if (duration == TimeSpec.MinPeriodDuration)
            {
                return(startHasTimeOfDay ? GetDateTime(start) : GetShortDate(start));
            }

            // within one day: show full start, end time and suration
            if (TimeCompare.IsSameDay(start, end))
            {
                return(GetDateTime(start) + startEndSeparator + GetLongTime(end) + durationSeparator + GetDuration(duration));
            }

            // show start date, end date and duration (optionally with the time part)
            bool   endHasTimeOfDay = TimeTool.HasTimeOfDay(start);
            bool   hasTimeOfDays   = startHasTimeOfDay || endHasTimeOfDay;
            string startPart       = hasTimeOfDays ? GetDateTime(start) : GetShortDate(start);
            string endPart         = hasTimeOfDays ? GetDateTime(end) : GetShortDate(end);

            return(startPart + startEndSeparator + endPart + durationSeparator + GetDuration(duration));
        }         // GetPeriod
예제 #2
0
        }         // CalcMonths

        // ----------------------------------------------------------------------
        private int CalcWeeks()
        {
            if (TimeCompare.IsSameDay(date1, date2))
            {
                return(0);
            }

            DateTime week1 = TimeTool.GetStartOfWeek(date1, firstDayOfWeek);
            DateTime week2 = TimeTool.GetStartOfWeek(date2, firstDayOfWeek);

            if (week1.Equals(week2))
            {
                return(0);
            }

            return((int)(week2.Subtract(week1).TotalDays / TimeSpec.DaysPerWeek));
        }         // CalcWeeks
예제 #3
0
        }         // CalcQuarters

        // ----------------------------------------------------------------------
        private int CalcMonths()
        {
            if (TimeCompare.IsSameDay(date1, date2))
            {
                return(0);
            }

            int compareDay          = date2.Day;
            int compareDaysPerMonth = calendar.GetDaysInMonth(Year1, Month1);

            if (compareDay > compareDaysPerMonth)
            {
                compareDay = compareDaysPerMonth;
            }

            DateTime compareDate = new DateTime(Year1, Month1, compareDay,
                                                date2.Hour, date2.Minute, date2.Second, date2.Millisecond);

            if (date2 > date1)
            {
                if (compareDate < date1)
                {
                    compareDate = compareDate.AddMonths(1);
                }
            }
            else
            {
                if (compareDate > date1)
                {
                    compareDate = compareDate.AddMonths(-1);
                }
            }
            return
                (((Year2 * TimeSpec.MonthsPerYear) + Month2) -
                 ((calendar.GetYear(compareDate) * TimeSpec.MonthsPerYear) + calendar.GetMonth(compareDate)));
        }         // CalcMonths
예제 #4
0
        }         // GetCalendarPeriod

        #endregion

        #region Interval

        // ----------------------------------------------------------------------
        public string GetInterval(DateTime start, DateTime end,
                                  IntervalEdge startEdge, IntervalEdge endEdge, TimeSpan duration)
        {
            if (end < start)
            {
                throw new ArgumentOutOfRangeException("end");
            }

            StringBuilder sb = new StringBuilder();

            // interval start
            switch (startEdge)
            {
            case IntervalEdge.Closed:
                sb.Append(IntervalStartClosed);
                break;

            case IntervalEdge.Open:
                sb.Append(UseIsoIntervalNotation ? intervalStartOpenIso : intervalStartOpen);
                break;
            }

            bool addDuration       = true;
            bool startHasTimeOfDay = TimeTool.HasTimeOfDay(start);

            // no duration - schow start date (optionally with the time part)
            if (duration == TimeSpec.MinPeriodDuration)
            {
                sb.Append(startHasTimeOfDay ? GetDateTime(start) : GetShortDate(start));
                addDuration = false;
            }
            // within one day: show full start, end time and suration
            else if (TimeCompare.IsSameDay(start, end))
            {
                sb.Append(GetDateTime(start));
                sb.Append(startEndSeparator);
                sb.Append(GetLongTime(end));
            }
            else
            {
                bool endHasTimeOfDay = TimeTool.HasTimeOfDay(start);
                bool hasTimeOfDays   = startHasTimeOfDay || endHasTimeOfDay;
                if (hasTimeOfDays)
                {
                    sb.Append(GetDateTime(start));
                    sb.Append(startEndSeparator);
                    sb.Append(GetDateTime(end));
                }
                else
                {
                    sb.Append(GetShortDate(start));
                    sb.Append(startEndSeparator);
                    sb.Append(GetShortDate(end));
                }
            }

            // interval end
            switch (endEdge)
            {
            case IntervalEdge.Closed:
                sb.Append(IntervalEndClosed);
                break;

            case IntervalEdge.Open:
                sb.Append(UseIsoIntervalNotation ? IntervalEndOpenIso : IntervalEndOpen);
                break;
            }

            // duration
            if (addDuration)
            {
                sb.Append(durationSeparator);
                sb.Append(GetDuration(duration));
            }

            return(sb.ToString());
        }         // GetInterval