Ejemplo n.º 1
0
        private DateTime GetDateTimeNotFixedDateRule(TimeZoneInfo.TransitionTime transitionTime, int year)
        {
            System.Globalization.Calendar calendar = _userConnection.CurrentUser.Culture.Calendar;
            DateTime firstDateOfMonth    = new DateTime(year, transitionTime.Month, 1);
            int      firstDayOfMounth    = (int)calendar.GetDayOfWeek(firstDateOfMonth);
            int      startDayOfWeek      = (transitionTime.Week * 7) - 6;
            int      transitionDayOfWeek = (int)transitionTime.DayOfWeek;
            int      transitionDay;

            if (firstDayOfMounth <= transitionDayOfWeek)
            {
                transitionDay = startDayOfWeek + (transitionDayOfWeek - firstDayOfMounth);
            }
            else
            {
                transitionDay = startDayOfWeek + (7 - firstDayOfMounth + transitionDayOfWeek);
            }
            if (transitionDay > calendar.GetDaysInMonth(year, transitionTime.Month))
            {
                transitionDay -= 7;
            }
            return(new DateTime(
                       year,
                       transitionTime.Month,
                       transitionDay,
                       transitionTime.TimeOfDay.Hour,
                       transitionTime.TimeOfDay.Minute,
                       transitionTime.TimeOfDay.Second,
                       DateTimeKind.Utc));
        }
Ejemplo n.º 2
0
 private void InitializeMe()
 {
     System.Globalization.Calendar c1 = _GetCalendar(_Calendar);
     if (_DateTime != null && _DateTime.Value.Year > 690)
     {
         Year      = c1.GetYear(_DateTime.Value);
         Month     = c1.GetMonth(_DateTime.Value);
         Day       = c1.GetDayOfMonth(_DateTime.Value);
         DayOfWeek = c1.GetDayOfWeek(_DateTime.Value);
     }
     else
     {
         _DateTime = null;
     }
 }
Ejemplo n.º 3
0
        public void Read(int year, int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int milli = 0)
        {
            _date = _calendar.ToDateTime(year, month, day, hour, minute, second, milli);

            Year        = year;
            Month       = month;
            Day         = day;
            DayOfWeek   = _calendar.GetDayOfWeek(_date);
            Hour        = hour;
            Minute      = minute;
            Second      = second;
            Millisecond = milli;

            DateChanged(this);
        }
Ejemplo n.º 4
0
        // TODO: Need more work to accept (") and (') and (%) and (\) characters.
        public static string ToCurrentCultureString(DateTime dt, string format, System.Globalization.DateTimeFormatInfo formatProvider)
        {
            // Some formats do not need to custom implementation like these
            string[] autoReplaces = new string[] {
                "fffffff", "ffffff", "fffff", "ffff", "fff", "ff", "f",
                "FFFFFFF", "FFFFFF", "FFFFF", "FFFF", "FFF", "FF", "F",
                "gg", "g",
                "hh", "HH", "mm", "ss", "tt", "t"
            };

            System.Globalization.Calendar cal = GetCurrentCalendar();
            int year  = cal.GetYear(dt);
            int month = cal.GetMonth(dt);
            int day   = cal.GetDayOfMonth(dt);

            DayOfWeek dayOfWeek = cal.GetDayOfWeek(dt);

            foreach (string autoReplace in autoReplaces)
            {
                format = format.Replace(autoReplace, dt.ToString(autoReplace, formatProvider));
            }

            format = format.Replace("dddd", formatProvider.GetDayName(dayOfWeek));
            format = format.Replace("ddd", formatProvider.GetAbbreviatedDayName(dayOfWeek));
            format = format.Replace("dd", ((int)dayOfWeek).ToString("00"));
            format = format.Replace("dd", dayOfWeek.ToString());
            format = format.Replace("MMMM", formatProvider.GetMonthName(month));
            format = format.Replace("MMM", formatProvider.GetAbbreviatedMonthName(month));
            format = format.Replace("MM", month.ToString("00"));
            format = format.Replace("M", month.ToString());
            format = format.Replace("yyyy", year.ToString("0000"));
            format = format.Replace("yyy", year.ToString("000"));
            format = format.Replace("yy", (year % 100).ToString("00"));
            format = format.Replace("y", (year % 100).ToString());

            return(format);
        }
Ejemplo n.º 5
0
            public State(View current_view, DateTime current_selected)
            {
                calendar = new System.Globalization.GregorianCalendar();

                view = current_view;

                // FIXME: perhaps, let end time be current_selected

                if (view == View.Year)
                {
                    start_time = new System.DateTime(current_selected.Year, 1, 1);
                    end_time = new System.DateTime(current_selected.Year, 12, calendar.GetDaysInMonth(current_selected.Year, 12));
                }
                else if (view == View.Month)
                {
                    start_time = new System.DateTime(current_selected.Year, current_selected.Month, 1);
                    // always start a week on a monday
                    start_time -= new System.TimeSpan(days_from_monday(calendar.GetDayOfWeek(start_time)), 0, 0, 0);

                    end_time = new System.DateTime(current_selected.Year, current_selected.Month, calendar.GetDaysInMonth(current_selected.Year, current_selected.Month));
                    // always end a week on a sunday
                    end_time += new System.TimeSpan(days_til_monday(calendar.GetDayOfWeek(end_time)), 0, 0, 0);

                    //System.Console.WriteLine("setting start: {0} - {1}, end: {2} - {3}",
                    //start_time, calendar.GetDayOfWeek(start_time), end_time, calendar.GetDayOfWeek(end_time));
                }
                else if (view == View.Week)
                {
                    start_time = current_selected;
                    // always start a week on a monday
                    start_time -= new System.TimeSpan(days_from_monday(calendar.GetDayOfWeek(start_time)), 0, 0, 0);
                    start_time = new DateTime(start_time.Year, start_time.Month, start_time.Day); // set time to 12am

                    end_time = current_selected;
                    // always end a week on a sunday

                    end_time += new System.TimeSpan(days_til_monday(calendar.GetDayOfWeek(end_time)), 0, 0, 0);
                    end_time = new DateTime(end_time.Year, end_time.Month, end_time.Day); // set time to 12am
                }
                else if (view == View.Day)
                {
                    start_time = new DateTime(current_selected.Year, current_selected.Month, current_selected.Day); // set time to 12am

                    end_time = current_selected;
                    end_time += new System.TimeSpan(1, 0, 0, 0);
                    end_time = new DateTime(end_time.Year, end_time.Month, end_time.Day); // set time to 12am
                }
                else
                {
                    Debug.Assert(false);
                    // should never happen
                    start_time = current_selected;
                    end_time = current_selected;
                }

                Debug.Assert(start_time != end_time);
            }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks whether RadCalendarDay object is associated with a DateTime that represents a recurring event.
        /// </summary>
        /// <param name="compareTime">the DateTime to compare.</param>
        /// <param name="processCalendar">the System.Globalization.Calendar object used to check whether the DateTime
        /// represents a recurring event.</param>
        /// <returns></returns>
        internal protected virtual RecurringEvents IsRecurring(DateTime compareTime, System.Globalization.Calendar processCalendar)
        {
            if (Recurring != RecurringEvents.None)
            {
                switch (Recurring)
                {
                case RecurringEvents.DayInMonth:
                {
                    int firstCompare  = processCalendar.GetDayOfMonth(compareTime);
                    int secondCompare = processCalendar.GetDayOfMonth(this.Date);
                    if (firstCompare.Equals(secondCompare))
                    {
                        return(Recurring);
                    }
                }
                break;

                case RecurringEvents.Today:
                    if (compareTime.Equals(DateTime.Today))
                    {
                        return(Recurring);
                    }
                    break;

                case RecurringEvents.DayAndMonth:
                {
                    int FirstCompare       = processCalendar.GetDayOfMonth(compareTime);
                    int SecondCompare      = processCalendar.GetDayOfMonth(this.Date);
                    int FirstMonthCompare  = processCalendar.GetMonth(compareTime);
                    int SecondMonthCompare = processCalendar.GetMonth(this.Date);
                    if (FirstCompare.Equals(SecondCompare) && FirstMonthCompare.Equals(SecondMonthCompare))
                    {
                        return(Recurring);
                    }
                }
                break;

                case RecurringEvents.WeekAndMonth:
                {
                    DayOfWeek FirstCompare       = processCalendar.GetDayOfWeek(compareTime);
                    DayOfWeek SecondCompare      = processCalendar.GetDayOfWeek(this.Date);
                    int       FirstMonthCompare  = processCalendar.GetMonth(compareTime);
                    int       SecondMonthCompare = processCalendar.GetMonth(this.Date);
                    if (FirstCompare.Equals(SecondCompare) && FirstMonthCompare.Equals(SecondMonthCompare))
                    {
                        return(Recurring);
                    }
                    break;
                }

                case RecurringEvents.Week:
                {
                    DayOfWeek FirstCompare  = processCalendar.GetDayOfWeek(compareTime);
                    DayOfWeek SecondCompare = processCalendar.GetDayOfWeek(this.Date);
                    if (FirstCompare.Equals(SecondCompare))
                    {
                        return(Recurring);
                    }
                    break;
                }

                default:
                    break;
                }
            }
            return(RecurringEvents.None);
        }
Ejemplo n.º 7
0
        public Image DrawSchema(out CoordsMaps coordsMaps, int colHeight, DateTime startDate, DateTime endDate, RowsFlags Pflags)
        {
            System.Globalization.CultureInfo UICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            System.Globalization.Calendar    cal       = UICulture.Calendar;
            ganttStart = startDate;
            ganttEnd   = endDate;

            int days     = endDate.Subtract(startDate).Days;
            int rowCount = 0;

            if ((Pflags & RowsFlags.NoYears) != RowsFlags.NoYears)
            {
                yearRow = (rowCount++) * rowsSize + top;
            }
            int startYear    = startDate.Year;
            int firstColYear = 0;

            if ((Pflags & RowsFlags.NoMonths) != RowsFlags.NoMonths)
            {
                monthRow = (rowCount++) * rowsSize + top;
            }
            int startMonth    = startDate.Month;
            int firstColMonth = 0;

            if ((Pflags & RowsFlags.NoWeeks) != RowsFlags.NoWeeks)
            {
                weekRow = (rowCount++) * rowsSize + top;
            }
            int startWeek    = cal.GetWeekOfYear(startDate, UICulture.DateTimeFormat.CalendarWeekRule, UICulture.DateTimeFormat.FirstDayOfWeek);
            int firstColWeek = 0;

            if ((Pflags & RowsFlags.NoDays) != RowsFlags.NoDays)
            {
                dayRow = (rowCount++) * rowsSize + top;
            }
            this.ganttHeight = colHeight + dayRow + 1;
            Image img = new Bitmap(days * dayColumnSize + 1, this.ganttHeight);

            g = Graphics.FromImage(img);
            g.Clear(Color.White);

            SolidBrush brush        = new SolidBrush(Color.Black);
            SolidBrush dayBrush     = new SolidBrush(Color.LightGray);
            SolidBrush weekendBrush = new SolidBrush(Color.DarkGray);

            sf = new StringFormat(StringFormatFlags.NoClip | StringFormatFlags.NoWrap | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.MeasureTrailingSpaces);
            Font yearFont = FontToFitVertical(new FontFamily("Arial"), FontStyle.Regular, rowsSize, sf);

            monthFont    = FontToFitVertical(new FontFamily("Arial"), FontStyle.Regular, rowsSize, sf);
            descFont     = FontToFitVertical(new FontFamily("Arial"), FontStyle.Regular, rowsSize, sf);
            descFontBold = FontToFitVertical(new FontFamily("Arial"), FontStyle.Bold, rowsSize, sf);
            monthDayFont = FontToFitHorizontal(new FontFamily("Arial"), FontStyle.Regular, dayColumnSize, sf);
            Pen pen = new Pen(Color.DarkGray, 1F);

            sf.Alignment        = StringAlignment.Center;
            sf.LineAlignment    = StringAlignment.Center;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            int        dayLeft = 0;
            Rectangle  ra      = new Rectangle();
            CoordsMaps cm      = new CoordsMaps();

            for (int i = 0; i <= days; i++)
            {
                int      currentPixel = i * dayColumnSize;
                DateTime todayDate    = cal.AddDays(startDate, i);
                if (yearRow != -1 && (todayDate.Year != startYear || i == days))
                {
                    ra = new Rectangle(left + firstColYear, yearRow, currentPixel - firstColYear, rowsSize);
                    g.DrawRectangle(pen, ra);
                    g.DrawString(startYear.ToString(), monthFont, brush, ra, sf);
                    cm.Add(new CoordsMap(RowTypes.Years, ra, startYear));
                    startYear    = todayDate.Year;
                    firstColYear = currentPixel;
                }
                if (monthRow != -1 && (todayDate.Day == 1 || i == days))
                {
                    ra = new Rectangle(left + firstColMonth, monthRow, currentPixel - firstColMonth, rowsSize);
                    string month = UICulture.DateTimeFormat.GetMonthName(startMonth);
                    if (yearRow == -1)
                    {
                        month += " " + todayDate.Year;
                    }
                    g.DrawRectangle(pen, ra);
                    if (g.MeasureString(month, monthFont, 100000, sf).Width < ra.Width + 4)
                    {
                        g.DrawString(month, monthFont, brush, ra, sf);
                    }
                    else if (g.MeasureString(UICulture.DateTimeFormat.GetMonthName(startMonth), monthFont, 100000, sf).Width < ra.Width + 4)
                    {
                        g.DrawString(UICulture.DateTimeFormat.GetMonthName(startMonth), monthFont, brush, ra, sf);
                    }

                    cm.Add(new CoordsMap(RowTypes.Months, ra, startMonth));
                    startMonth    = todayDate.Month;
                    firstColMonth = currentPixel;
                }
                if (weekRow != -1 && (todayDate.DayOfWeek == UICulture.DateTimeFormat.FirstDayOfWeek || i == days))
                {
                    ra = new Rectangle(left + firstColWeek, weekRow, currentPixel - firstColWeek, rowsSize);
                    g.DrawRectangle(pen, ra);
                    g.DrawString(startWeek.ToString(), monthFont, brush, ra, sf);
                    cm.Add(new CoordsMap(RowTypes.Weeks, ra, startWeek));
                    startWeek++;
                    firstColWeek = currentPixel;
                }
                if (dayRow != -1 && i != days)
                {
                    ra       = new Rectangle(left + dayLeft, dayRow, dayColumnSize, rowsSize);
                    dayLeft += (dayColumnSize);

                    Rectangle r = ra;
                    r.Height = colHeight;
                    if (todayDate.DayOfWeek == DayOfWeek.Sunday || todayDate.DayOfWeek == DayOfWeek.Saturday)
                    {
                        g.FillRectangle(dayBrush, r);
                    }
                    g.DrawRectangle(pen, r);
                    cm.Add(new CoordsMap(RowTypes.Days, r, i));

                    g.DrawString(cal.GetDayOfMonth(todayDate).ToString(), monthDayFont, brush, ra, sf);
                    Rectangle r2 = ra;
                    r2.Y += monthDayFont.Height;
                    g.DrawString(UICulture.DateTimeFormat.GetShortestDayName(cal.GetDayOfWeek(todayDate)).ToUpper().Substring(0, 1), monthDayFont, brush, r2, sf);
                    if (todayDate.ToShortDateString() == DateTime.Now.ToShortDateString())
                    {
                        g.DrawLine(new Pen(Color.Red), currentPixel, dayRow, currentPixel, dayRow + colHeight);
                    }
                }
            }
            dayRow    += monthDayFont.Height;
            coordsMaps = cm;
            return(img);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Updates list boxes showing daily, weekly, monthly events relative to selected date
        /// </summary>
        private void updateEventLists()
        {
            dayListBox.Items.Clear();
            weekListBox.Items.Clear();
            monthListBox.Items.Clear();

            DateTime selected = eventMonthCalendar.SelectionStart;

            foreach (Event e in eventListComboBox.Items)
            {
                //Daily:
                //Events that recur daily
                //or other recurring events that share the same day of the same month
                //or nonrecurring events that share the same exact date

                //Weekly:
                //Events that recur daily and weekly
                //or other recurring events that share the same week
                //going off the date it would fall on in that particular year and month
                //or nonrecurring events that share the same week

                //Monthly:
                //Events that recur daily and weekly and monthly
                //or other recurring events that share the same month
                //or nonrecurring events that share the same month

                //store this datetime so we can restore it
                //the listed dates will be modified to be relative to the selected date
                DateTime lastDate = e.eventDate;
                if (e.recurrence == Recur.Daily)
                {
                    e.eventDate = selected;
                    dayListBox.Items.Add(e);
                    weekListBox.Items.Add(e);
                    monthListBox.Items.Add(e);
                }
                else if (e.recurrence == Recur.Weekly)
                {
                    //Need to match month and year,
                    //and then figure out what day the same day of the week falls on
                    //relative to the selected
                    System.Globalization.Calendar cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
                    int dayOfWeek = (int)cal.GetDayOfWeek(e.eventDate);
                    e.eventDate = new DateTime(selected.Year, selected.Month, selected.Day);
                    e.eventDate = e.eventDate.Date.AddDays(-1 * (int)cal.GetDayOfWeek(selected) + dayOfWeek);


                    weekListBox.Items.Add(e);
                    monthListBox.Items.Add(e);
                    //add to daily if they share the same month
                    if (e.eventDate.Month == selected.Month && e.eventDate.Day == selected.Day)
                    {
                        dayListBox.Items.Add(e);
                    }
                }
                else if (e.recurrence == Recur.Monthly)
                {
                    //if there are fewer days in the selected month, the event cannot recur
                    //this should also allow us to create leap year recurrences
                    if (DateTime.DaysInMonth(selected.Year, selected.Month) < e.eventDate.Day)
                    {
                        continue;
                    }
                    e.eventDate = new DateTime(selected.Year, selected.Month, e.eventDate.Day);



                    monthListBox.Items.Add(e);
                    //add to daily if they share the same month and day
                    if (e.eventDate.Day == selected.Day)
                    {
                        dayListBox.Items.Add(e);
                    }
                    //add to weekly if they fall on the same week
                    //this is a great solution found on stack overflow modified to use a datetime relative to the selected date
                    System.Globalization.Calendar cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
                    if (e.eventDate.Date.AddDays(-1 * (int)cal.GetDayOfWeek(e.eventDate)).Day == selected.AddDays(-1 * (int)cal.GetDayOfWeek(selected)).Day)
                    {
                        weekListBox.Items.Add(e);
                    }
                }
                else if (e.recurrence == Recur.Annually)
                {
                    if (DateTime.DaysInMonth(selected.Year, e.eventDate.Month) < e.eventDate.Day)
                    {
                        continue;
                    }
                    e.eventDate = new DateTime(selected.Year, e.eventDate.Month, e.eventDate.Day);


                    //add to daily if they share the same month and day
                    if (e.eventDate.Month == selected.Month && e.eventDate.Day == selected.Day)
                    {
                        dayListBox.Items.Add(e);
                    }
                    //add to weekly if they fall on the same week
                    //this is a great solution found on stack overflow
                    System.Globalization.Calendar cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
                    if (e.eventDate.Date.AddDays(-1 * (int)cal.GetDayOfWeek(e.eventDate)).Day == selected.AddDays(-1 * (int)cal.GetDayOfWeek(selected)).Day)
                    {
                        weekListBox.Items.Add(e);
                    }
                    //add to monthly if they share the same month
                    if (e.eventDate.Month == selected.Month)
                    {
                        monthListBox.Items.Add(e);
                    }
                }
                //if the event is not repeated, we just need to know
                else
                {
                    //add to daily if they share the exact same date
                    if (e.eventDate.CompareTo(selected) == 0)
                    {
                        dayListBox.Items.Add(e);
                    }
                    //add to weekly if they share the same week
                    System.Globalization.Calendar cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
                    if (e.eventDate.Date.AddDays(-1 * (int)cal.GetDayOfWeek(e.eventDate)).Day == selected.AddDays(-1 * (int)cal.GetDayOfWeek(selected)).Day)
                    {
                        weekListBox.Items.Add(e);
                    }
                    //add to monthly if they share the same month
                    if (e.eventDate.Year == selected.Year && e.eventDate.Month == selected.Month)
                    {
                        monthListBox.Items.Add(e);
                    }
                }
                e.eventDate = lastDate;
            }
        }