Beispiel #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DateRange" /> structure to the specified start and end date.
        /// </summary>
        /// <param name="startDate">A string that contains that first date in the date range.</param>
        /// <param name="endDate">A string that contains the last date in the date range.</param>
        /// <exception cref="System.ArgumentNullException">
        ///		endDate or startDate are <c>null</c>.
        /// </exception>
        /// <exception cref="System.FormatException">
        ///     endDate or startDate do not contain a vaild string representation of a date and time.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        ///		endDate is not greater than or equal to startDate
        /// </exception>
        public DateRange(string startDate, string endDate)
        {
            if (string.IsNullOrWhiteSpace(startDate))
            {
                throw new ArgumentNullException("startDate");
            }

            if (string.IsNullOrWhiteSpace(endDate))
            {
                throw new ArgumentNullException("endDate");
            }

            Start = DateTime.Parse(startDate);
            End   = DateTime.Parse(endDate);

            if (End.Hour == 0 && End.Minute == 0)
            {
                End.AddHours(23);
                End.AddMinutes(59);
                End.AddMilliseconds(999);
            }

            if (End < Start)
            {
                throw new ArgumentException("endDate must be greater than or equal to startDate");
            }
        }
Beispiel #2
0
        public DateRange()
        {
            Start = DateTime.Today;
            End   = DateTime.Today;

            End.AddHours(23);
            End.AddMinutes(59);
            End.AddMilliseconds(999);
        }
Beispiel #3
0
        public CalendarEvent(string icalbuddystring)
        {
            try
            {
                var input = icalbuddystring.Split(new[] { "_#_" }, StringSplitOptions.RemoveEmptyEntries);
                Title = input[1];
                Id    = input[2].Trim();

                Start = new DateTime(
                    int.Parse(input[0].Substring(0, 4)),
                    int.Parse(input[0].Substring(5, 2)),
                    int.Parse(input[0].Substring(8, 2)) //, 0, 0, 0, 0, DateTimeKind.Utc
                    );

                // If All-Day-Event -> New start/end
                if (!input[0].Contains(" at "))
                {
                    End = new DateTime(
                        int.Parse(input[0].Substring(13, 4)),
                        int.Parse(input[0].Substring(18, 2)),
                        int.Parse(input[0].Substring(21, 2)) //, 0, 0, 0, 0, DateTimeKind.Utc
                        );

                    Start = Start.AddHours(7);
                    End   = End.AddHours(18);
                }
                else
                {
                    End   = Start;
                    Start = Start.AddHours(int.Parse(input[0].Substring(14, 2)));
                    Start = Start.AddMinutes(int.Parse(input[0].Substring(17, 2)));

                    End = End.AddHours(int.Parse(input[0].Substring(22, 2)));
                    End = End.AddMinutes(int.Parse(input[0].Substring(25, 2)));
                }


                DateTimeIdentifier = CreateDateTimeIdentifiier(Start, End);
            }
            catch (Exception e)
            {
                // Using exceptions for control flow is not recommended, but for this simple case sufficient
                throw new HttpRequestException($"Could not parse event: {icalbuddystring}", e);
            }
        }
Beispiel #4
0
        public void MapStartTimes()
        {
            Start = DateTime.Today;
            End   = DateTime.Today;
            switch (Number)
            {
            case 1:
                Start = Start.AddHours(8);
                Start = Start.AddMinutes(0);
                End   = End.AddHours(9);
                End   = End.AddMinutes(20);
                break;

            case 2:
                Start = Start.AddHours(9);
                Start = Start.AddMinutes(30);
                End   = End.AddHours(10);
                End   = End.AddMinutes(50);
                break;

            case 3:
                Start = Start.AddHours(11);
                Start = Start.AddMinutes(10);
                End   = End.AddHours(12);
                End   = End.AddMinutes(30);
                break;

            case 4:
                Start = Start.AddHours(12);
                Start = Start.AddMinutes(40);
                End   = End.AddHours(14);
                End   = End.AddMinutes(0);
                break;

            case 5:
                Start = Start.AddHours(14);
                Start = Start.AddMinutes(10);
                End   = End.AddHours(15);
                End   = End.AddMinutes(30);
                break;

            case 6:
                Start = Start.AddHours(15);
                Start = Start.AddMinutes(40);
                End   = End.AddHours(17);
                End   = End.AddMinutes(0);
                break;

            case 7:
                Start = Start.AddHours(17);
                Start = Start.AddMinutes(20);
                End   = End.AddHours(18);
                End   = End.AddMinutes(40);
                break;

            case 8:
                Start = Start.AddHours(18);
                Start = Start.AddMinutes(50);
                End   = End.AddHours(20);
                End   = End.AddMinutes(10);
                break;

            default:
                break;
            }
        }