Permalink
Browse files

Updated to version 1.0.2

Fixed a bug with XProperty3() unit test that rendered it ineffective at testing anything.
Fixed a bug with assignment of TZID within the FromSystemTimeZone() method.
Fixed a bug with the TimeZoneName property that was causing it to malfunction.
Added additional time-zone related code to iCalDateTime.
Fixed a bug with UTCOffset that caused it to return incorrect times.
  • Loading branch information...
1 parent d2d7d35 commit c4533e41365c27fb2798785c52781a6220568da2 dougday committed Oct 29, 2010
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.0.1.$WCREV$")]
-[assembly: AssemblyFileVersion("1.0.1.$WCREV$")]
+[assembly: AssemblyVersion("1.0.2.$WCREV$")]
+[assembly: AssemblyFileVersion("1.0.2.$WCREV$")]
@@ -1156,10 +1156,10 @@ public void XProperty3()
htmlBuilder.Append("<HTML><HEAD><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;charset=iso-8859-1\"></HEAD><BODY>");
htmlBuilder.Append("<B>Test</B>");
htmlBuilder.Append("</BODY></HTML>");
-
- // This adds the property to the event automatically
+
ICalendarProperty p = new CalendarProperty("X-ALT-DESC", htmlBuilder.ToString());
p.Parameters.Add(new CalendarParameter("FMTTYPE", "text/html"));
+ evt.Properties.Add(p);
iCalendarSerializer serializer = new iCalendarSerializer();
serializer.Serialize(iCal, @"Calendars\Serialization\XProperty3.ics");
View
Binary file not shown.
@@ -161,7 +161,7 @@ virtual public void AddProperty(string name, string value)
/// <summary>
/// Adds a property to this component.
/// </summary>
- virtual public void AddProperty(CalendarProperty p)
+ virtual public void AddProperty(ICalendarProperty p)
{
p.Parent = this;
Properties[p.Name] = p;
@@ -67,8 +67,9 @@ public static iCalTimeZone FromSystemTimeZone(System.TimeZoneInfo tzinfo, DateTi
var adjustmentRules = tzinfo.GetAdjustmentRules();
var utcOffset = tzinfo.BaseUtcOffset;
var dday_tz = new iCalTimeZone();
- IDateTime earliest = new iCalDateTime(earlistDateTimeToSupport);
+ dday_tz.TZID = tzinfo.Id;
+ IDateTime earliest = new iCalDateTime(earlistDateTimeToSupport);
foreach (var adjustmentRule in adjustmentRules)
{
// Only include historical data if asked to do so. Otherwise,
@@ -77,8 +78,6 @@ public static iCalTimeZone FromSystemTimeZone(System.TimeZoneInfo tzinfo, DateTi
continue;
var delta = adjustmentRule.DaylightDelta;
- dday_tz.TZID = tzinfo.Id;
-
var dday_tzinfo_standard = new DDay.iCal.iCalTimeZoneInfo();
dday_tzinfo_standard.Name = "STANDARD";
dday_tzinfo_standard.TimeZoneName = tzinfo.StandardName;
@@ -101,25 +101,14 @@ virtual public string TimeZoneName
{
get
{
- IList<string> tzNames = TimeZoneNames;
- if (tzNames != null &&
- tzNames.Count > 0)
- return tzNames[0];
+ if (TimeZoneNames.Count > 0)
+ return TimeZoneNames[0];
return null;
}
set
{
- IList<string> tzNames = TimeZoneNames;
- if (tzNames != null &&
- tzNames.Count > 0)
- tzNames[0] = value;
- else
- {
- if (value != null)
- tzNames = new List<string>(new string[] { value });
- else
- tzNames = null;
- }
+ TimeZoneNames.Clear();
+ TimeZoneNames.Add(value);
}
}
@@ -165,7 +154,7 @@ virtual public IList<string> TimeZoneNames
dt = new iCalDateTime(OffsetTo.ToUTC(dt.Value));
normalizedDt = OffsetTo.ToUTC(normalizedDt);
}
-
+
// Let's evaluate our time zone observances to find the
// observance that applies to this date/time value.
IEvaluator parentEval = Parent.GetService(typeof(IEvaluator)) as IEvaluator;
@@ -153,12 +153,12 @@ private DateTime Offset(DateTime dt, bool positive)
virtual public DateTime ToUTC(DateTime dt)
{
- return Offset(dt, !Positive);
+ return DateTime.SpecifyKind(Offset(dt, !Positive), DateTimeKind.Utc);
}
virtual public DateTime ToLocal(DateTime dt)
{
- return Offset(dt, Positive);
+ return DateTime.SpecifyKind(Offset(dt, Positive), DateTimeKind.Local);
}
#endregion
@@ -13,8 +13,7 @@ namespace DDay.iCal
/// The iCalendar equivalent of the .NET <see cref="DateTime"/> class.
/// <remarks>
/// In addition to the features of the <see cref="DateTime"/> class, the <see cref="iCalDateTime"/>
- /// class handles time zone differences, and integrates seamlessly into
- /// the iCalendar framework.
+ /// class handles time zone differences, and integrates seamlessly into the iCalendar framework.
/// </remarks>
/// </summary>
#if !SILVERLIGHT
@@ -66,6 +65,10 @@ public iCalDateTime(DateTime value, string tzid)
{
Initialize(value, tzid, null);
}
+ public iCalDateTime(DateTime value, TimeZoneObservance tzo)
+ {
+ Initialize(value, tzo);
+ }
public iCalDateTime(int year, int month, int day, int hour, int minute, int second)
{
Initialize(year, month, day, hour, minute, second, null, null);
@@ -110,6 +113,21 @@ private void Initialize(DateTime value, string tzid, IICalendar iCal)
this.AssociatedObject = iCal;
}
+ private void Initialize(DateTime value, TimeZoneObservance tzo)
+ {
+ if (value.Kind == DateTimeKind.Utc)
+ this.IsUniversalTime = true;
+
+ // Convert all incoming values to UTC.
+ this.Value = DateTime.SpecifyKind(value, DateTimeKind.Utc);
+ this.HasDate = true;
+ this.HasTime = (value.Second == 0 && value.Minute == 0 && value.Hour == 0) ? false : true;
+ if (tzo.TimeZoneInfo != null)
+ this.TZID = tzo.TimeZoneInfo.TZID;
+ this.TimeZoneObservance = tzo;
+ this.AssociatedObject = tzo.TimeZoneInfo;
+ }
+
private DateTime CoerceDateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind)
{
DateTime dt = DateTime.MinValue;
@@ -165,7 +183,6 @@ public override ICalendarObject AssociatedObject
if (!object.Equals(AssociatedObject, value))
{
base.AssociatedObject = value;
- _TimeZoneObservance = null;
}
}
}
@@ -209,16 +226,7 @@ public override int GetHashCode()
public override string ToString()
{
- string tz = TimeZoneName;
- if (!string.IsNullOrEmpty(tz))
- tz = " " + tz;
-
- if (HasTime && HasDate)
- return Value.ToString() + tz;
- else if (HasTime)
- return Value.TimeOfDay.ToString() + tz;
- else
- return Value.ToShortDateString() + tz;
+ return ToString(null, null);
}
#endregion
@@ -355,7 +363,7 @@ public DateTime UTC
}
/// <summary>
- /// Gets the <see cref="iCalTimeZoneInfo"/> object for the time
+ /// Gets/sets the <see cref="iCalTimeZoneInfo"/> object for the time
/// zone set by <see cref="TZID"/>.
/// </summary>
public TimeZoneObservance? TimeZoneObservance
@@ -367,6 +375,16 @@ public DateTime UTC
set
{
_TimeZoneObservance = value;
+ if (value != null &&
+ value.HasValue &&
+ value.Value.TimeZoneInfo != null)
+ {
+ this.TZID = value.Value.TimeZoneInfo.TZID;
+ }
+ else
+ {
+ this.TZID = null;
+ }
}
}
@@ -401,7 +419,7 @@ public DateTime Value
// fall within this time zone observance.
if (_TimeZoneObservance != null &&
_TimeZoneObservance.HasValue &&
- !_TimeZoneObservance.Value.Period.Contains(this))
+ !_TimeZoneObservance.Value.Contains(this))
_TimeZoneObservance = null;
}
@@ -428,7 +446,15 @@ public string TZID
if (!object.Equals(TZID, value))
{
Parameters.Set("TZID", value);
- _TimeZoneObservance = null;
+
+ // Set the time zone observance to null if the TZID
+ // doesn't match.
+ if (value != null &&
+ _TimeZoneObservance != null &&
+ _TimeZoneObservance.HasValue &&
+ _TimeZoneObservance.Value.TimeZoneInfo != null &&
+ !object.Equals(_TimeZoneObservance.Value.TimeZoneInfo.TZID, value))
+ _TimeZoneObservance = null;
}
}
}
@@ -488,7 +514,7 @@ public IDateTime FirstDayOfYear
get
{
IDateTime dt = Copy<IDateTime>();
- dt.Value = Value.AddDays(-Value.DayOfYear+1);
+ dt.Value = Value.AddDays(-Value.DayOfYear+1).Date;
return dt;
}
}
@@ -498,7 +524,7 @@ public IDateTime FirstDayOfMonth
get
{
IDateTime dt = Copy<IDateTime>();
- dt.Value = Value.AddDays(-Value.Day+1);
+ dt.Value = Value.AddDays(-Value.Day+1).Date;
return dt;
}
}
@@ -511,11 +537,29 @@ public DateTime Date
public TimeSpan TimeOfDay
{
get { return Value.TimeOfDay; }
- }
+ }
+
+ public IDateTime ToTimeZone(TimeZoneObservance tzo)
+ {
+ ITimeZoneInfo tzi = tzo.TimeZoneInfo;
+ if (tzi != null)
+ return new iCalDateTime(tzi.OffsetTo.ToLocal(UTC), tzo);
+ return null;
+ }
- public IDateTime ToTimeZone(ITimeZoneInfo tzi)
+ public IDateTime ToTimeZone(ITimeZone tz)
{
- return new iCalDateTime(tzi.OffsetTo.ToLocal(UTC));
+ if (tz != null)
+ {
+ TimeZoneObservance? tzi = tz.GetTimeZoneObservance(this);
+ if (tzi != null && tzi.HasValue)
+ return ToTimeZone(tzi.Value);
+
+ // FIXME: if the time cannot be resolved, should we
+ // just provide a copy? Is this always appropriate?
+ return Copy<IDateTime>();
+ }
+ else throw new ArgumentException("You must provide a valid time zone to the ToTimeZone() method", "tz");
}
public IDateTime ToTimeZone(string tzid)
@@ -526,22 +570,25 @@ public IDateTime ToTimeZone(string tzid)
{
ITimeZone tz = Calendar.GetTimeZone(tzid);
if (tz != null)
- {
- TimeZoneObservance? tzi = tz.GetTimeZoneObservance(this);
- if (tzi != null && tzi.HasValue)
- return ToTimeZone(tzi.Value.TimeZoneInfo);
- }
+ return ToTimeZone(tz);
+
// FIXME: sometimes a calendar is perfectly valid but the time zone
// could not be resolved. What should we do here?
//throw new Exception("The '" + tzid + "' time zone could not be resolved.");
-
return Copy<IDateTime>();
}
else throw new Exception("The iCalDateTime object must have an iCalendar associated with it in order to use TimeZones.");
}
else throw new ArgumentException("You must provide a valid TZID to the ToTimeZone() method", "tzid");
}
+ public IDateTime SetTimeZone(ITimeZone tz)
+ {
+ if (tz != null)
+ this.TZID = tz.TZID;
+ return this;
+ }
+
public IDateTime Add(TimeSpan ts)
{
return this + ts;
@@ -693,7 +740,18 @@ public string ToString(string format)
public string ToString(string format, IFormatProvider formatProvider)
{
- return Value.ToString(format, formatProvider);
+ string tz = TimeZoneName;
+ if (!string.IsNullOrEmpty(tz))
+ tz = " " + tz;
+
+ if (format != null)
+ return Value.ToString(format, formatProvider) + tz;
+ else if (HasTime && HasDate)
+ return Value.ToString() + tz;
+ else if (HasTime)
+ return Value.TimeOfDay.ToString() + tz;
+ else
+ return Value.ToShortDateString() + tz;
}
#endregion
@@ -235,7 +235,7 @@ private List<DateTime> GetDates(IDateTime seed, DateTime periodStart, DateTime p
IncrementDate(ref incremented, pattern, pattern.Interval);
}
}
-
+
bool?[] expandBehavior = RecurrenceUtil.GetExpandBehaviorList(pattern);
int invalidCandidateCount = 0;
@@ -89,6 +89,10 @@ public override void Clear()
public override IList<IPeriod> Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults)
{
+ // Ensure the reference date is associated with the time zone
+ if (referenceDate.AssociatedObject == null)
+ referenceDate.AssociatedObject = TimeZone;
+
List<ITimeZoneInfo> infos = new List<ITimeZoneInfo>(TimeZone.TimeZoneInfos);
// Evaluate extra time periods, without re-evaluating ones that were already evaluated
@@ -36,7 +36,13 @@ public CalendarPropertyList(ICalendarObject parent, bool caseInsensitive)
}
#endregion
+
+ #region Overrides
+
+
+ #endregion
+
#region Event Handlers
void CalendarPropertyList_ItemRemoved(object sender, ObjectEventArgs<ICalendarProperty> e)
@@ -59,12 +65,12 @@ virtual public void Set(string name, object value)
{
name = m_CaseInsensitive ? name.ToUpper() : name;
if (value != null)
- {
+ {
ICalendarProperty p = new CalendarProperty(name, value);
if (ContainsKey(name))
this[name] = p;
else
- Add(p);
+ Add(p);
}
else
{
Oops, something went wrong.

0 comments on commit c4533e4

Please sign in to comment.