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

SerializeToString() public method

public SerializeToString ( object obj ) : string
obj object
return string
        public override string SerializeToString(object obj)
        {            
            if (obj is IDateTime)
            {
                IDateTime dt = ((IDateTime)obj).Copy<IDateTime>();

                // Assign the TZID for the date/time value.
                if (dt.TZID != null)
                    dt.Parameters.Set("TZID", dt.TZID);

                // FIXME: what if DATE is the default value type for this?
                // Also, what if the DATE-TIME value type is specified on something
                // where DATE-TIME is the default value type?  It should be removed
                // during serialization, as it's redundant...
                if (!dt.HasTime)
                    dt.SetValueType("DATE");
                else 
                {
                    // Remove the 'VALUE' parameter, as it's already at
                    // its default value
                    if (dt.Parameters.ContainsKey("VALUE"))
                    {
                        dt.Parameters.Remove("VALUE");
                    }
                }

                string value = string.Format("{0:0000}{1:00}{2:00}", dt.Year, dt.Month, dt.Day);
                if (dt.HasTime)
                {
                    value += string.Format("T{0:00}{1:00}{2:00}", dt.Hour, dt.Minute, dt.Second);
                    if (dt.IsUniversalTime)
                        value += "Z";
                }

                // Encode the value as necessary
                return Encode(dt, value);
            }
            return null;
        }