/// <summary> /// This helper method can be used to set a new time zone in the passed date/time property without /// modifying the date/time value. /// </summary> /// <param name="dateProp">The date/time property to check</param> /// <param name="vTimeZone">The new time zone component to use</param> /// <remarks>If the property's current time zone ID does not match the one in the new time zone, it is /// updated with the new ID. The date/time value is not changed.</remarks> protected static void SetPropertyTimeZone(BaseDateTimeProperty dateProp, VTimeZone vTimeZone) { if(dateProp != null && (vTimeZone == null || dateProp.TimeZoneId != vTimeZone.TimeZoneId.Value)) { // If the time zone is null, just clear the time zone ID if(vTimeZone == null) dateProp.TimeZoneId = null; else dateProp.TimeZoneId = vTimeZone.TimeZoneId.Value; } }
/// <summary> /// This helper method can be used to update a time zone ID in the passed date/time property /// </summary> /// <param name="dateProp">The date/time property to check</param> /// <param name="oldId">The old ID being replaced</param> /// <param name="newId">The new ID to use</param> /// <remarks>If the property's current time zone ID matches the old ID, it is replaced with the new ID</remarks> protected static void UpdatePropertyTimeZoneId(BaseDateTimeProperty dateProp, string oldId, string newId) { if(dateProp != null && dateProp.TimeZoneId == oldId) dateProp.TimeZoneId = newId; }
/// <summary> /// This helper method can be used to apply a new time zone to the passed date/time property /// </summary> /// <param name="dateProp">The date/time property to check</param> /// <param name="vTimeZone">The new time zone component to use</param> /// <remarks>If the property's current time zone ID does not match the one in the new time zone, it is /// updated with the new ID and the date/time is adjusted to the new time zone.</remarks> protected static void ApplyPropertyTimeZone(BaseDateTimeProperty dateProp, VTimeZone vTimeZone) { if(dateProp != null && (vTimeZone == null || dateProp.TimeZoneId != vTimeZone.TimeZoneId.Value)) { // If the time zone is null, just clear the time zone ID if(vTimeZone == null) { dateProp.TimeZoneId = null; return; } DateTimeInstance dti = VCalendar.TimeZoneToTimeZone(dateProp.TimeZoneDateTime, dateProp.TimeZoneId, vTimeZone.TimeZoneId.Value); dateProp.TimeZoneDateTime = dti.StartDateTime; dateProp.TimeZoneId = vTimeZone.TimeZoneId.Value; } }
/// <summary> /// This helper method can be used to add a time zone ID to the string collection when one is used on the /// passed property. /// </summary> /// <param name="dateProp">The date/time property to check.</param> /// <param name="timeZoneIds">The string collection to which the time zone ID is added if there is one on /// the date/time property and it is not already in the collection.</param> /// <remarks>If the date/time property has no time zone ID or if it is set to <see cref="DateTime.MinValue"/>, /// the collection is not modified.</remarks> protected static void AddTimeZoneIfUsed(BaseDateTimeProperty dateProp, StringCollection timeZoneIds) { if(dateProp != null && dateProp.TimeZoneDateTime != DateTime.MinValue) { string tzId = dateProp.TimeZoneId; if(tzId != null && !timeZoneIds.Contains(tzId)) timeZoneIds.Add(tzId); } }