IsSameDay() public static méthode

두 DateTime 값이 일(Day) 단위까지 같은지 판단합니다.
public static IsSameDay ( this left, System.DateTime right ) : bool
left this
right System.DateTime
Résultat bool
Exemple #1
0
        /// <summary>
        /// 시작-완료 | 기간 을 문자열로 표현합니다.
        /// </summary>
        public string GetPeriod(DateTime start, DateTime end, TimeSpan duration)
        {
            TimeTool.AssertValidPeriod(start, end);

            // no duration - start equals end
            if (duration == TimeSpec.MinPeriodDuration)
            {
                return(start.HasTimePart() ? GetDateTime(start) : GetShortDate(start));
            }

            // 날짜까지 같으니까, 중복된 부분을 뺀 완료 날짜를 제외한 시간만 표시한다.
            //
            if (TimeTool.IsSameDay(start, end))
            {
                return(string.Concat(GetDateTime(start), StartEndSeparator, GetLongTime(end), DurationSeparator, GetDuration(duration)));
            }

            // 시작 일자, 완료 일자, 기간(Duration)을 표현한다.
            //
            var hasTimeOfDays = start.HasTimePart() || end.HasTimePart();
            var startPart     = hasTimeOfDays ? GetDateTime(start) : GetShortDate(start);
            var endPart       = hasTimeOfDays ? GetDateTime(end) : GetShortDate(end);

            return(string.Concat(startPart, StartEndSeparator, endPart, DurationSeparator, GetDuration(duration)));
        }
Exemple #2
0
        /// <summary>
        /// 시간 간격을 문자열로 표현합니다.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="startEdge"></param>
        /// <param name="endEdge"></param>
        /// <param name="duration"></param>
        /// <returns></returns>
        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("[");
                break;

            case IntervalEdge.Open:
                sb.Append(UseIsoIntervalNotation ? "]" : "(");
                break;
            }

            bool addDuration       = true;
            bool startHasTimeOfDay = TimeTool.HasTimePart(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 (TimeTool.IsSameDay(start, end))
            {
                sb.Append(GetDateTime(start));
                sb.Append(StartEndSeparator);
                sb.Append(GetLongTime(end));
                sb.Append(GetShortDate(start));
            }
            else
            {
                bool endHasTimeOfDay = TimeTool.HasTimePart(start);
                bool hasTimeOfDays   = startHasTimeOfDay || endHasTimeOfDay;
                if (hasTimeOfDays)
                {
                    sb.Append(GetDateTime(start));
                    sb.Append(StartEndSeparator);
                    sb.Append(GetDateTime(start));
                }
                else
                {
                    sb.Append(GetShortDate(start));
                    sb.Append(StartEndSeparator);
                    sb.Append(GetShortDate(end));
                }
            }

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

            case IntervalEdge.Open:
                sb.Append(UseIsoIntervalNotation ? "[" : ")");
                break;
            }

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

            return(sb.ToString());
        }