DDay.iCal.Serialization.iCalendar.DateTimeSerializer.CoerceDateTime C# (CSharp) Method

CoerceDateTime() private method

private CoerceDateTime ( int year, int month, int day, int hour, int minute, int second, DateTimeKind kind ) : System.DateTime
year int
month int
day int
hour int
minute int
second int
kind DateTimeKind
return System.DateTime
        private DateTime CoerceDateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind)
        {
            DateTime dt = DateTime.MinValue;

            // NOTE: determine if a date/time value exceeds the representable date/time values in .NET.
            // If so, let's automatically adjust the date/time to compensate.
            // FIXME: should we have a parsing setting that will throw an exception
            // instead of automatically adjusting the date/time value to the
            // closest representable date/time?
            try
            {
                if (year > 9999)
                    dt = DateTime.MaxValue;
                else if (year > 0)
                    dt = new DateTime(year, month, day, hour, minute, second, kind);
            }
            catch
            {
            }

            return dt;
        }