Exemplo n.º 1
0
        private void UpdateTime(CalendarItem item, DateTime now)
        {
            // todo: Extrahieren, globale funktion...

            var mnth = new string[] { "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember" };

            var dt          = item.Start;
            var nowDay      = new DateTime(now.Year, now.Month, now.Day);
            var nowDayEnd   = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);
            var nowMonth    = new DateTime(now.Year, now.Month, 1);
            var nowMonthEnd = new DateTime(now.Year, now.Month + 1, 1).AddSeconds(-1);
            var nowYear     = new DateTime(now.Year, 1, 1);
            var nowYearEnd  = new DateTime(now.Year + 1, 1, 1).AddSeconds(-1);

            if (dt < now.AddMinutes(-1))
            {
                item.Time      = string.Format("vor {0} Minuten", (int)(now - dt).TotalMinutes);
                item.TimeBrush = "#ffFF3333";
            }
            else if (dt < now.AddMinutes(1) && dt > now.AddMinutes(-1))
            {
                item.Time      = "Jetzt";
                item.TimeBrush = "#ffFF3333";
            }
            else if (dt < now.AddHours(1))
            {
                item.Time = string.Format("in {0} Minuten", (int)(dt - now).TotalMinutes);
            }
            else if (dt < now.AddHours(6) || dt < nowDayEnd)
            {
                item.Time = string.Format("in {0} Stunden", (int)(dt - now).TotalHours);
            }
            else if (dt < nowDayEnd.AddDays(1))
            {
                item.Time = string.Format("Morgen um {0:HH}:{0:mm}", dt);
            }
            else if (dt < nowDayEnd.AddDays(2))
            {
                item.Time = string.Format("Übermorgen um {0:HH}:{0:mm}", dt);
            }
            else if (dt < nowDayEnd.AddDays(6))
            {
                item.Time = string.Format("{0:dddd} um {0:HH}:{0:mm}", dt);
            }
            else if (dt < nowDayEnd.AddDays(15) || dt < nowMonthEnd)
            {
                item.Time = string.Format("in {0} Tagen", (int)(dt - nowDay).TotalDays);
            }
            else if (dt < nowMonthEnd.AddMonths(1))
            {
                item.Time = string.Format("nächsten Monat");
            }
            else if (dt < nowMonthEnd.AddMonths(6) || dt < nowYearEnd)
            {
                item.Time = string.Format("in {0} Monaten", nowYear.Year == dt.Year ? dt.Month - now.Month : 12 - now.Month + dt.Month);
            }
            else if (dt.Year - now.Year == 1)
            {
                //item.Time = string.Format("nächstes Jahr im {0:MMMM}", dt);
                item.Time = string.Format("nächstes Jahr im {0}", mnth[dt.Month - 1]);
            }
            else
            {
                item.Time = string.Format("in {0} Jahren", dt.Year - now.Year);
            }
        }
Exemplo n.º 2
0
        public CalendarItem Copy()
        {
            CalendarItem c = this.MemberwiseClone() as CalendarItem;

            return(c);
        }
Exemplo n.º 3
0
        private void UpdateTime(CalendarItem item, DateTime now)
        {
            // todo: Extrahieren, globale funktion...

            var dt = item.Start;
            var nowDay = new DateTime(now.Year, now.Month, now.Day);
            var nowDayEnd = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);
            var nowMonth = new DateTime(now.Year, now.Month, 1);
            var nowMonthEnd = new DateTime(now.Year, now.Month + 1, 1).AddSeconds(-1);
            var nowYear = new DateTime(now.Year, 1, 1);
            var nowYearEnd = new DateTime(now.Year + 1, 1, 1).AddSeconds(-1);

            if (dt < now.AddMinutes(-1))
            {
                item.Time = string.Format("vor {0} Minuten", (int)(now - dt).TotalMinutes);
                item.TimeBrush = "#ffFF3333";
            }
            else if (dt < now.AddMinutes(1) && dt > now.AddMinutes(-1))
            {
                item.Time = "Jetzt";
                item.TimeBrush = "#ffFF3333";
            }
            else if (dt < now.AddHours(1))
                item.Time = string.Format("in {0} Minuten", (int)(dt - now).TotalMinutes);
            else if (dt < now.AddHours(6) || dt < nowDayEnd)
                item.Time = string.Format("in {0} Stunden", (int)(dt - now).TotalHours);
            else if (dt < nowDayEnd.AddDays(1))
                item.Time = string.Format("Morgen um {0:HH}:{0:mm}", dt);
            else if (dt < nowDayEnd.AddDays(2))
                item.Time = string.Format("Übermorgen um {0:HH}:{0:mm}", dt);
            else if (dt < nowDayEnd.AddDays(6))
                item.Time = string.Format("{0:dddd} um {0:HH}:{0:mm}", dt);
            else if (dt < nowDayEnd.AddDays(15) || dt < nowMonthEnd)
                item.Time = string.Format("in {0} Tagen", (int)(dt - nowDay).TotalDays);
            else if (dt < nowMonthEnd.AddMonths(1))
                item.Time = string.Format("nächsten Monat");
            else if (dt < nowMonthEnd.AddMonths(6) || dt < nowYearEnd)
                item.Time = string.Format("in {0} Monaten", nowYear.Year == dt.Year ? dt.Month - now.Month : 12 - now.Month + dt.Month);
            else if (dt.Year - now.Year == 1)
                item.Time = string.Format("nächstes Jahr im {0:MMMM}", dt);
            else
                item.Time = string.Format("in {0} Jahren", dt.Year - now.Year);
        }