Author: stephane
Date: 2007-05-11 16:29:26 -0400 (Fri, 11 May 2007)
New Revision: 77257
Added:
trunk/mcs/class/System.Core/System/
trunk/mcs/class/System.Core/System/DateTimeOffset.cs
trunk/mcs/class/System.Core/System/InvalidTimeZoneException.cs
trunk/mcs/class/System.Core/System/TimeZoneInfo.AdjustmentRule.cs
trunk/mcs/class/System.Core/System/TimeZoneInfo.TransitionTime.cs
trunk/mcs/class/System.Core/System/TimeZoneInfo.cs
trunk/mcs/class/System.Core/System/TimeZoneNotFoundException.cs
Modified:
trunk/mcs/class/System.Core/ChangeLog
trunk/mcs/class/System.Core/Makefile
trunk/mcs/class/System.Core/System.Core.dll.sources
Log:
2007-05-11 Stephane Delcroix <[EMAIL PROTECTED]>
* System/DateTimeOffset.cs:
* System/InvalidTimeZoneException.cs:
* System/TimeZoneInfo.AdjustmentRules.cs:
* System/TimeZoneInfo.cs:
* System/TimeZoneInfo.TransitionTime.cs
* System/TimeZoneNotFoundException.cs: new TimeZoneInfo class
* System.Core.dll.sources: Added the above files
* Makefile: compile with -d:LIBC so TimeZoneInfo will look for libc
defined timezones
Modified: trunk/mcs/class/System.Core/ChangeLog
===================================================================
--- trunk/mcs/class/System.Core/ChangeLog 2007-05-11 20:14:05 UTC (rev
77256)
+++ trunk/mcs/class/System.Core/ChangeLog 2007-05-11 20:29:26 UTC (rev
77257)
@@ -1,3 +1,17 @@
+2007-05-11 Stephane Delcroix <[EMAIL PROTECTED]>
+
+ * System/DateTimeOffset.cs:
+ * System/InvalidTimeZoneException.cs:
+ * System/TimeZoneInfo.AdjustmentRules.cs:
+ * System/TimeZoneInfo.cs:
+ * System/TimeZoneInfo.TransitionTime.cs
+ * System/TimeZoneNotFoundException.cs: new TimeZoneInfo class
+
+ * System.Core.dll.sources: Added the above files
+
+ * Makefile: compile with -d:LIBC so TimeZoneInfo will look for libc
+ defined timezones
+
2007-03-29 Miguel de Icaza <[EMAIL PROTECTED]>
* Reapply the patch from Antonello, and rework the code to not use
Modified: trunk/mcs/class/System.Core/Makefile
===================================================================
--- trunk/mcs/class/System.Core/Makefile 2007-05-11 20:14:05 UTC (rev
77256)
+++ trunk/mcs/class/System.Core/Makefile 2007-05-11 20:29:26 UTC (rev
77257)
@@ -3,7 +3,7 @@
include ../../build/rules.make
LIBRARY = System.Core.dll
-LIB_MCS_FLAGS = -langversion:linq /r:$(corlib)
+LIB_MCS_FLAGS = -langversion:linq -d:LIBC /r:$(corlib)
NO_TEST = yes
# This is a .NET 2.0 only assembly
Added: trunk/mcs/class/System.Core/System/DateTimeOffset.cs
===================================================================
--- trunk/mcs/class/System.Core/System/DateTimeOffset.cs 2007-05-11
20:14:05 UTC (rev 77256)
+++ trunk/mcs/class/System.Core/System/DateTimeOffset.cs 2007-05-11
20:29:26 UTC (rev 77257)
@@ -0,0 +1,35 @@
+/*
+ * System.DateTimeOffset
+ *
+ * Author(s)
+ * Stephane Delcroix <[EMAIL PROTECTED]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+namespace System
+{
+ public class DateTimeOffset {
+ public DateTimeOffset ()
+ {
+ throw new NotImplementedException ();
+ }
+ }
+}
Added: trunk/mcs/class/System.Core/System/InvalidTimeZoneException.cs
===================================================================
--- trunk/mcs/class/System.Core/System/InvalidTimeZoneException.cs
2007-05-11 20:14:05 UTC (rev 77256)
+++ trunk/mcs/class/System.Core/System/InvalidTimeZoneException.cs
2007-05-11 20:29:26 UTC (rev 77257)
@@ -0,0 +1,44 @@
+/*
+ * System.InvalidimeZoneException
+ *
+ * Author(s)
+ * Stephane Delcroix <[EMAIL PROTECTED]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+namespace System
+{
+ public class InvalidTimeZoneException : Exception
+ {
+ public InvalidTimeZoneException () : base ()
+ {}
+
+ public InvalidTimeZoneException (string message) : base
(message)
+ {}
+
+ public InvalidTimeZoneException (string message, Exception e) :
base (message, e)
+ {}
+
+ protected InvalidTimeZoneException
(Runtime.Serialization.SerializationInfo info,
Runtime.Serialization.StreamingContext sc) : base (info, sc)
+ {}
+ }
+}
Added: trunk/mcs/class/System.Core/System/TimeZoneInfo.AdjustmentRule.cs
===================================================================
--- trunk/mcs/class/System.Core/System/TimeZoneInfo.AdjustmentRule.cs
2007-05-11 20:14:05 UTC (rev 77256)
+++ trunk/mcs/class/System.Core/System/TimeZoneInfo.AdjustmentRule.cs
2007-05-11 20:29:26 UTC (rev 77257)
@@ -0,0 +1,132 @@
+/*
+ * System.TimeZoneInfo.AdjustmentRule
+ *
+ * Author(s)
+ * Stephane Delcroix <[EMAIL PROTECTED]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+using System.Runtime.Serialization;
+
+namespace System
+{
+ public sealed partial class TimeZoneInfo {
+ [SerializableAttribute]
+ public sealed class AdjustmentRule :
IEquatable<TimeZoneInfo.AdjustmentRule>, ISerializable, IDeserializationCallback
+ {
+ DateTime dateEnd;
+ public DateTime DateEnd {
+ get { return dateEnd; }
+ }
+
+ DateTime dateStart;
+ public DateTime DateStart {
+ get { return dateStart; }
+ }
+
+ TimeSpan daylightDelta;
+ public TimeSpan DaylightDelta {
+ get { return daylightDelta; }
+ }
+
+ TransitionTime daylightTransitionEnd;
+ public TransitionTime DaylightTransitionEnd {
+ get { return daylightTransitionEnd; }
+ }
+
+ TransitionTime daylightTransitionStart;
+ public TransitionTime DaylightTransitionStart {
+ get { return daylightTransitionStart; }
+ }
+
+ public static AdjustmentRule CreateAdjustmentRule (
+ DateTime dateStart,
+ DateTime dateEnd,
+ TimeSpan daylightDelta,
+ TransitionTime daylightTransitionStart,
+ TransitionTime daylightTransitionEnd)
+ {
+ return new AdjustmentRule (dateStart, dateEnd,
daylightDelta, daylightTransitionStart, daylightTransitionEnd);
+ }
+
+ private AdjustmentRule (
+ DateTime dateStart,
+ DateTime dateEnd,
+ TimeSpan daylightDelta,
+ TransitionTime daylightTransitionStart,
+ TransitionTime daylightTransitionEnd)
+ {
+ if (dateStart.Kind != DateTimeKind.Unspecified
|| dateEnd.Kind != DateTimeKind.Unspecified)
+ throw new ArgumentException ("the Kind
property of dateStart or dateEnd parameter does not equal
DateTimeKind.Unspecified");
+
+ if (daylightTransitionStart ==
daylightTransitionEnd)
+ throw new ArgumentException
("daylightTransitionStart parameter cannot equal daylightTransitionEnd
parameter");
+
+ if (dateStart.Ticks % TimeSpan.TicksPerDay != 0
|| dateEnd.Ticks % TimeSpan.TicksPerDay != 0)
+ throw new ArgumentException ("dateStart
or dateEnd parameter includes a time of day value");
+
+ if (dateEnd < dateStart)
+ throw new ArgumentOutOfRangeException
("dateEnd is earlier than dateStart");
+
+ if (daylightDelta > new TimeSpan (14, 0, 0) ||
daylightDelta < new TimeSpan (-14, 0, 0))
+ throw new ArgumentOutOfRangeException
("daylightDelta is less than -14 or greater than 14 hours");
+
+ if (daylightDelta.Ticks %
TimeSpan.TicksPerSecond != 0)
+ throw new ArgumentOutOfRangeException
("daylightDelta parameter does not represent a whole number of seconds");
+
+ this.dateStart = dateStart;
+ this.dateEnd = dateEnd;
+ this.daylightDelta = daylightDelta;
+ this.daylightTransitionStart =
daylightTransitionStart;
+ this.daylightTransitionEnd =
daylightTransitionEnd;
+ }
+
+ public bool Equals (TimeZoneInfo.AdjustmentRule other)
+ {
+ return dateStart == other.dateStart &&
+ dateEnd == other.dateEnd &&
+ daylightDelta == other.daylightDelta &&
+ daylightTransitionStart ==
other.daylightTransitionStart &&
+ daylightTransitionEnd ==
other.daylightTransitionEnd;
+ }
+
+ public override int GetHashCode ()
+ {
+ return dateStart.GetHashCode () ^
+ dateEnd.GetHashCode () ^
+ daylightDelta.GetHashCode () ^
+ daylightTransitionStart.GetHashCode () ^
+ daylightTransitionEnd.GetHashCode ();
+ }
+
+ public void GetObjectData (SerializationInfo info,
StreamingContext context)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public void OnDeserialization (object sender)
+ {
+ throw new NotImplementedException ();
+ }
+ }
+ }
+}
+
Added: trunk/mcs/class/System.Core/System/TimeZoneInfo.TransitionTime.cs
===================================================================
--- trunk/mcs/class/System.Core/System/TimeZoneInfo.TransitionTime.cs
2007-05-11 20:14:05 UTC (rev 77256)
+++ trunk/mcs/class/System.Core/System/TimeZoneInfo.TransitionTime.cs
2007-05-11 20:29:26 UTC (rev 77257)
@@ -0,0 +1,205 @@
+/*
+ * System.TimeZoneInfo.TransitionTime
+ *
+ * Author(s)
+ * Stephane Delcroix <[EMAIL PROTECTED]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+using System.Runtime.Serialization;
+
+namespace System
+{
+ public sealed partial class TimeZoneInfo
+ {
+ [SerializableAttribute]
+ public struct TransitionTime :
IEquatable<TimeZoneInfo.TransitionTime>, ISerializable, IDeserializationCallback
+ {
+ DateTime timeOfDay;
+ public DateTime TimeOfDay {
+ get { return timeOfDay; }
+ }
+
+ int month;
+ public int Month {
+ get { return month; }
+ }
+
+ int day;
+ public int Day {
+ get {
+#if STRICT
+ if (!isFixedDateRule)
+ throw new Exception ("Day
property is not valid for floating date rules");
+#endif
+ return day;
+ }
+ }
+
+ int week;
+ public int Week {
+ get {
+#if STRICT
+ if (isFixedDateRule)
+ throw new Exception ("Week
property is not valid for fixed date rules");
+#endif
+
+ return week;
+ }
+ }
+
+ DayOfWeek dayOfWeek;
+ public DayOfWeek DayOfWeek {
+ get {
+#if STRICT
+ if (isFixedDateRule)
+ throw new Exception ("DayOfWeek
property is not valid for fixed date rules");
+#endif
+
+ return dayOfWeek;
+ }
+ }
+
+ bool isFixedDateRule;
+ public bool IsFixedDateRule {
+ get { return isFixedDateRule; }
+ }
+
+ public static TransitionTime CreateFixedDateRule (
+ DateTime timeOfDay,
+ int month,
+ int day)
+ {
+ return new TransitionTime (timeOfDay, month,
day);
+ }
+
+ public static TransitionTime CreateFloatingDateRule (
+ DateTime timeOfDay,
+ int month,
+ int week,
+ DayOfWeek dayOfWeek)
+ {
+ return new TransitionTime (timeOfDay, month,
week, dayOfWeek);
+ }
+
+ private TransitionTime (
+ DateTime timeOfDay,
+ int month,
+ int day) : this (timeOfDay, month)
+ {
+ if (day < 1 || day > 31)
+ throw new ArgumentOutOfRangeException
("day parameter is less than 1 or greater than 31");
+
+ this.day = day;
+ this.isFixedDateRule = true;
+ }
+
+ private TransitionTime (
+ DateTime timeOfDay,
+ int month,
+ int week,
+ DayOfWeek dayOfWeek) : this (timeOfDay, month)
+ {
+ if (week < 1 || week > 5)
+ throw new ArgumentOutOfRangeException
("week parameter is less than 1 or greater than 5");
+
+ if (dayOfWeek != DayOfWeek.Sunday &&
+ dayOfWeek != DayOfWeek.Monday &&
+ dayOfWeek != DayOfWeek.Tuesday
&&
+ dayOfWeek !=
DayOfWeek.Wednesday &&
+ dayOfWeek != DayOfWeek.Thursday
&&
+ dayOfWeek != DayOfWeek.Friday &&
+ dayOfWeek != DayOfWeek.Saturday)
+ throw new ArgumentOutOfRangeException
("dayOfWeek parameter is not a member od DayOfWeek enumeration");
+
+ this.week = week;
+ this.dayOfWeek = dayOfWeek;
+ this.isFixedDateRule = false;
+ }
+
+ private TransitionTime (
+ DateTime timeOfDay,
+ int month)
+ {
+ if (timeOfDay.Year != 1 || timeOfDay.Month != 1
|| timeOfDay.Day != 1)
+ throw new ArgumentException ("timeOfDay
parameter has a non-default date component");
+
+ if (timeOfDay.Kind != DateTimeKind.Unspecified)
+ throw new ArgumentException ("timeOfDay
parameter Kind's property is not DateTimeKind.Unspecified");
+
+ if (timeOfDay.Ticks % TimeSpan.TicksPerSecond
!= 0)
+ throw new ArgumentException ("timeOfDay
parameter does not represent a whole number of seconds");
+
+ if (month < 1 || month > 12)
+ throw new ArgumentOutOfRangeException
("month parameter is less than 1 or greater than 12");
+
+ this.timeOfDay = timeOfDay;
+ this.month = month;
+
+ this.week = -1;
+ this.dayOfWeek = (DayOfWeek)-1;
+ this.day = -1;
+ this.isFixedDateRule = false;
+ }
+
+ public static bool operator == (TransitionTime t1,
TransitionTime t2)
+ {
+ return ( t1.day == t2.day &&
+ t1.dayOfWeek == t2.dayOfWeek &&
+ t1.isFixedDateRule ==
t2.isFixedDateRule &&
+ t1.month == t2.month &&
+ t1.timeOfDay == t2.timeOfDay &&
+ t1.week == t2.week);
+ }
+
+ public static bool operator != (TransitionTime t1,
TransitionTime t2)
+ {
+ return !(t1 == t2);
+ }
+
+ public void GetObjectData (SerializationInfo info,
StreamingContext context)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override bool Equals (object other)
+ {
+ return this == (TransitionTime) other;
+ }
+
+ public bool Equals (TimeZoneInfo.TransitionTime other)
+ {
+ return this == other;
+ }
+
+ public override int GetHashCode ()
+ {
+ return (day ^ (int)dayOfWeek ^ month ^
(int)timeOfDay.Ticks ^ week);
+ }
+
+ public void OnDeserialization (object sender)
+ {
+ throw new NotImplementedException ();
+ }
+ }
+ }
+}
+
Added: trunk/mcs/class/System.Core/System/TimeZoneInfo.cs
===================================================================
--- trunk/mcs/class/System.Core/System/TimeZoneInfo.cs 2007-05-11 20:14:05 UTC
(rev 77256)
+++ trunk/mcs/class/System.Core/System/TimeZoneInfo.cs 2007-05-11 20:29:26 UTC
(rev 77257)
@@ -0,0 +1,787 @@
+/*
+ * System.TimeZoneInfo
+ *
+ * Author(s)
+ * Stephane Delcroix <[EMAIL PROTECTED]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+using System.Runtime.Serialization;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+#if LIBC
+using System.IO;
+using System.Collections;
+using Mono;
+#endif
+
+namespace System
+{
+ [SerializableAttribute]
+ public sealed partial class TimeZoneInfo : IEquatable<TimeZoneInfo>,
ISerializable, IDeserializationCallback
+ {
+ TimeSpan baseUtcOffset;
+ public TimeSpan BaseUtcOffset {
+ get { return baseUtcOffset; }
+ }
+
+ string daylightDisplayName;
+ public string DaylightName {
+ get {
+ if (disableDaylightSavingTime)
+ return String.Empty;
+ return daylightDisplayName;
+ }
+ }
+
+ string displayName;
+ public string DisplayName {
+ get { return displayName; }
+ }
+
+ string id;
+ public string Id {
+ get { return id; }
+ }
+
+ static TimeZoneInfo local;
+ public static TimeZoneInfo Local {
+ get {
+ if (local == null) {
+#if LIBC
+ try {
+ local =
FindSystemTimeZoneByFileName ("Local", "/etc/localtime");
+ } catch {
+ try {
+ local =
FindSystemTimeZoneByFileName ("Local", Path.Combine (TimeZoneDirectory,
"localtime"));
+ } catch {
+ throw new
TimeZoneNotFoundException ();
+ }
+ }
+#else
+ throw new TimeZoneNotFoundException ();
+#endif
+ }
+ return local;
+ }
+ }
+
+ string standardDisplayName;
+ public string StandardName {
+ get { return standardDisplayName; }
+ }
+
+ bool disableDaylightSavingTime;
+ public bool SupportsDaylightSavingTime {
+ get { return !disableDaylightSavingTime; }
+ }
+
+ static TimeZoneInfo utc;
+ public static TimeZoneInfo Utc {
+ get {
+ if (utc == null)
+ utc = CreateCustomTimeZone ("UTC", new
TimeSpan (0), "UTC", "UTC");
+ return utc;
+ }
+ }
+#if LIBC
+ static string timeZoneDirectory = null;
+ public static string TimeZoneDirectory {
+ get {
+ if (timeZoneDirectory == null)
+ timeZoneDirectory =
"/usr/share/zoneinfo";
+ return timeZoneDirectory;
+ }
+ set {
+ ClearCachedData ();
+ timeZoneDirectory = value;
+ }
+ }
+#endif
+ private AdjustmentRule [] adjustmentRules;
+
+ public static void ClearCachedData ()
+ {
+ local = null;
+ utc = null;
+ systemTimeZones = null;
+ }
+
+ public static DateTime ConvertTime (DateTime dateTime,
TimeZoneInfo destinationTimeZone)
+ {
+ return ConvertTime (dateTime, TimeZoneInfo.Local,
destinationTimeZone);
+ }
+
+ public static DateTime ConvertTime (DateTime dateTime,
TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
+ {
+ if (dateTime.Kind == DateTimeKind.Local &&
sourceTimeZone != TimeZoneInfo.Local)
+ throw new ArgumentException ("Kind propery of
dateTime is Local but the sourceTimeZone does not equal TimeZoneInfo.Local");
+
+ if (dateTime.Kind == DateTimeKind.Utc && sourceTimeZone
!= TimeZoneInfo.Utc)
+ throw new ArgumentException ("Kind propery of
dateTime is Utc but the sourceTimeZone does not equal TimeZoneInfo.Utc");
+
+ if (sourceTimeZone.IsInvalidTime (dateTime))
+ throw new ArgumentException ("dateTime
parameter is an invalid time");
+
+ if (sourceTimeZone == null)
+ throw new ArgumentNullException
("sourceTimeZone");
+
+ if (destinationTimeZone == null)
+ throw new ArgumentNullException
("destinationTimeZone");
+
+ if (dateTime.Kind == DateTimeKind.Local &&
sourceTimeZone == TimeZoneInfo.Local && destinationTimeZone ==
TimeZoneInfo.Local)
+ return dateTime;
+
+ DateTime utc = ConvertTimeToUtc (dateTime);
+
+ if (destinationTimeZone == TimeZoneInfo.Utc)
+ return utc;
+
+ return ConvertTimeFromUtc (utc, destinationTimeZone);
+
+ }
+
+ public static DateTimeOffset ConvertTime (DateTimeOffset
dateTimeOffset, TimeZoneInfo destinationTimeZone)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public static DateTime ConvertTimeBySystemTimeZoneId (DateTime
dateTime, string destinationTimeZoneId)
+ {
+ return ConvertTime (dateTime, FindSystemTimeZoneById
(destinationTimeZoneId));
+ }
+
+ public static DateTime ConvertTimeBySystemTimeZoneId (DateTime
dateTime, string sourceTimeZoneId, string destinationTimeZoneId)
+ {
+ return ConvertTime (dateTime, FindSystemTimeZoneById
(sourceTimeZoneId), FindSystemTimeZoneById (destinationTimeZoneId));
+ }
+
+ public static DateTimeOffset ConvertTimeBySystemTimeZoneId
(DateTimeOffset dateTimeOffset, string destinationTimeZoneId)
+ {
+ return ConvertTime (dateTimeOffset,
FindSystemTimeZoneById (destinationTimeZoneId));
+ }
+
+ private DateTime ConvertTimeFromUtc (DateTime dateTime)
+ {
+ if (dateTime.Kind == DateTimeKind.Local)
+ throw new ArgumentException ("Kind property of
dateTime is Local");
+
+ if (this == TimeZoneInfo.Utc)
+ return DateTime.SpecifyKind (dateTime,
DateTimeKind.Utc);
+
+ //FIXME: do not rely on DateTime implementation !
+ if (this == TimeZoneInfo.Local)
+ return DateTime.SpecifyKind
(dateTime.ToLocalTime (), DateTimeKind.Unspecified);
+
+ AdjustmentRule rule = GetApplicableRule (dateTime);
+
+ if (IsDaylightSavingTime (DateTime.SpecifyKind
(dateTime, DateTimeKind.Utc)))
+ return DateTime.SpecifyKind (dateTime +
BaseUtcOffset + rule.DaylightDelta , DateTimeKind.Unspecified);
+ else
+ return DateTime.SpecifyKind (dateTime +
BaseUtcOffset, DateTimeKind.Unspecified);
+ }
+
+ public static DateTime ConvertTimeFromUtc (DateTime dateTime,
TimeZoneInfo destinationTimeZone)
+ {
+ if (destinationTimeZone == null)
+ throw new ArgumentNullException
("destinationTimeZone");
+
+ return destinationTimeZone.ConvertTimeFromUtc
(dateTime);
+ }
+
+ public static DateTime ConvertTimeToUtc (DateTime dateTime)
+ {
+ if (dateTime.Kind == DateTimeKind.Utc)
+ return dateTime;
+
+ //FIXME: do not rely on DateTime implementation !
+ return DateTime.SpecifyKind (dateTime.ToUniversalTime
(), DateTimeKind.Utc);
+ }
+
+ public static DateTime ConvertTimeToUtc (DateTime dateTime,
TimeZoneInfo sourceTimeZone)
+ {
+ if (sourceTimeZone == null)
+ throw new ArgumentNullException
("sourceTimeZone");
+
+ if (dateTime.Kind == DateTimeKind.Utc && sourceTimeZone
!= TimeZoneInfo.Utc)
+ throw new ArgumentException ("Kind propery of
dateTime is Utc but the sourceTimeZone does not equal TimeZoneInfo.Utc");
+
+ if (dateTime.Kind == DateTimeKind.Local &&
sourceTimeZone != TimeZoneInfo.Local)
+ throw new ArgumentException ("Kind propery of
dateTime is Local but the sourceTimeZone does not equal TimeZoneInfo.Local");
+
+ if (sourceTimeZone.IsInvalidTime (dateTime))
+ throw new ArgumentException ("dateTime
parameter is an invalid time");
+
+ if (dateTime.Kind == DateTimeKind.Utc && sourceTimeZone
== TimeZoneInfo.Utc)
+ return dateTime;
+
+ if (dateTime.Kind == DateTimeKind.Utc)
+ return dateTime;
+
+ if (dateTime.Kind == DateTimeKind.Local)
+ return ConvertTimeToUtc (dateTime);
+
+ if (sourceTimeZone.IsAmbiguousTime (dateTime) ||
!sourceTimeZone.IsDaylightSavingTime (dateTime))
+ return DateTime.SpecifyKind (dateTime -
sourceTimeZone.BaseUtcOffset, DateTimeKind.Utc);
+ else {
+ AdjustmentRule rule =
sourceTimeZone.GetApplicableRule (dateTime);
+ return DateTime.SpecifyKind (dateTime -
sourceTimeZone.BaseUtcOffset - rule.DaylightDelta, DateTimeKind.Utc);
+ }
+ }
+
+ public static TimeZoneInfo CreateCustomTimeZone (string id,
TimeSpan baseUtcOffset, string displayName, string standardDisplayName)
+ {
+ return CreateCustomTimeZone (id, baseUtcOffset,
displayName, standardDisplayName, null, null, true);
+ }
+
+ public static TimeZoneInfo CreateCustomTimeZone (string id,
TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string
daylightDisplayName, TimeZoneInfo.AdjustmentRule [] adjustmentRules)
+ {
+ return CreateCustomTimeZone (id, baseUtcOffset,
displayName, standardDisplayName, daylightDisplayName, adjustmentRules, false);
+ }
+
+ public static TimeZoneInfo CreateCustomTimeZone ( string id,
TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string
daylightDisplayName, TimeZoneInfo.AdjustmentRule [] adjustmentRules, bool
disableDaylightSavingTime)
+ {
+ return new TimeZoneInfo (id, baseUtcOffset,
displayName, standardDisplayName, daylightDisplayName, adjustmentRules,
disableDaylightSavingTime);
+ }
+
+ public bool Equals (TimeZoneInfo other)
+ {
+ if (other == null)
+ return false;
+
+ return other.Id == this.Id && HasSameRules (other);
+ }
+
+ public static TimeZoneInfo FindSystemTimeZoneById (string id)
+ {
+ //FIXME: this method should check for cached values in
systemTimeZones
+ if (id == null)
+ throw new ArgumentNullException ("id");
+#if LIBC
+ string filepath = Path.Combine (TimeZoneDirectory, id);
+ return FindSystemTimeZoneByFileName (id, filepath);
+#else
+ throw new NotImplementedException ();
+#endif
+ }
+
+#if LIBC
+ const int BUFFER_SIZE = 8192; //Big enough for any tz file
+ private static TimeZoneInfo FindSystemTimeZoneByFileName
(string id, string filepath)
+ {
+ if (!File.Exists (filepath))
+ throw new TimeZoneNotFoundException ();
+
+ byte [] buffer = new byte [BUFFER_SIZE];
+ int length;
+ using (FileStream stream = File.OpenRead (filepath)) {
+ length = stream.Read (buffer, 0, BUFFER_SIZE);
+ }
+
+ if (!ValidTZFile (buffer, length))
+ throw new InvalidTimeZoneException ();
+
+ try {
+ return ParseTZBuffer (id, buffer, length);
+ } catch (Exception e) {
+ throw new InvalidTimeZoneException (e.Message);
+ }
+ }
+#endif
+
+ public static TimeZoneInfo FromSerializedString (string source)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public AdjustmentRule [] GetAdjustmentRules ()
+ {
+ if (disableDaylightSavingTime)
+ return new AdjustmentRule [0];
+ else
+ return (AdjustmentRule [])
adjustmentRules.Clone ();
+ }
+
+ public TimeSpan [] GetAmbiguousTimeOffsets (DateTime dateTime)
+ {
+ if (!IsAmbiguousTime (dateTime))
+ throw new ArgumentException ("dateTime is not
an ambiguous time");
+
+ AdjustmentRule rule = GetApplicableRule (dateTime);
+ return new TimeSpan[] {baseUtcOffset, baseUtcOffset +
rule.DaylightDelta};
+ }
+
+ public TimeSpan [] GetAmbiguousTimeOffsets (DateTimeOffset
dateTimeOffset)
+ {
+ if (!IsAmbiguousTime (dateTimeOffset))
+ throw new ArgumentException ("dateTimeOffset is
not an ambiguous time");
+
+ throw new NotImplementedException ();
+ }
+
+ public override int GetHashCode ()
+ {
+ int hash_code = Id.GetHashCode ();
+ foreach (AdjustmentRule rule in GetAdjustmentRules ())
+ hash_code ^= rule.GetHashCode ();
+ return hash_code;
+ }
+
+ public void GetObjectData (SerializationInfo info,
StreamingContext context)
+ {
+ throw new NotImplementedException ();
+ }
+
+ //FIXME: change this to a generic Dictionary and allow caching
for FindSystemTimeZoneById
+ private static List<TimeZoneInfo> systemTimeZones = null;
+ public static ReadOnlyCollection<TimeZoneInfo>
GetSystemTimeZones ()
+ {
+ if (systemTimeZones == null) {
+ systemTimeZones = new List<TimeZoneInfo> ();
+#if LIBC
+ string[] continents = new string [] {"Africa",
"America", "Antarctica", "Arctic", "Asia", "Atlantic", "Brazil", "Canada",
"Chile", "Europe", "Indian", "Mexico", "Mideast", "Pacific", "US"};
+ foreach (string continent in continents) {
+ try {
+ foreach (string zonepath in
Directory.GetFiles (Path.Combine (TimeZoneDirectory, continent))) {
+ try {
+ string id =
String.Format ("{0}/{1}", continent, Path.GetFileName (zonepath));
+
systemTimeZones.Add (FindSystemTimeZoneById (id));
+ } catch
(ArgumentNullException) {
+ } catch
(TimeZoneNotFoundException) {
+ } catch
(InvalidTimeZoneException) {
+ } catch (Exception e) {
+ if (e is
OutOfMemoryException || e is System.Security.SecurityException)
+ throw;
+ else {
+
Console.WriteLine ("Unexpected Exception");
+ throw;
+ }
+ }
+ }
+ } catch {}
+ }
+#else
+ throw new NotImplementedException ("This method
is not implemented for this platform");
+#endif
+ }
+ return new ReadOnlyCollection<TimeZoneInfo>
(systemTimeZones);
+ }
+
+ public TimeSpan GetUtcOffset (DateTime dateTime)
+ {
+ if (IsDaylightSavingTime (dateTime)) {
+ AdjustmentRule rule = GetApplicableRule
(dateTime);
+ return BaseUtcOffset + rule.DaylightDelta;
+ }
+
+ return BaseUtcOffset;
+ }
+
+ public TimeSpan GetUtcOffset (DateTimeOffset dateTimeOffset)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public bool HasSameRules (TimeZoneInfo other)
+ {
+ if (other == null)
+ throw new ArgumentNullException ("other");
+
+ if (this.BaseUtcOffset != other.BaseUtcOffset)
+ return false;
+
+ if (this.adjustmentRules.Length !=
other.adjustmentRules.Length)
+ return false;
+
+ for (int i = 0; i < adjustmentRules.Length; i++) {
+ if (! (this.adjustmentRules [i]).Equals
(other.adjustmentRules [i]))
+ return false;
+ }
+
+ return true;
+ }
+
+ public bool IsAmbiguousTime (DateTime dateTime)
+ {
+ if (dateTime.Kind == DateTimeKind.Local &&
IsInvalidTime (dateTime))
+ throw new ArgumentException ("Kind is Local and
time is Invalid");
+
+ if (this == TimeZoneInfo.Utc)
+ return false;
+
+ if (dateTime.Kind == DateTimeKind.Utc)
+ dateTime = ConvertTimeFromUtc (dateTime);
+
+ if (dateTime.Kind == DateTimeKind.Local && this !=
TimeZoneInfo.Local)
+ dateTime = ConvertTime (dateTime,
TimeZoneInfo.Local, this);
+
+ AdjustmentRule rule = GetApplicableRule (dateTime);
+ DateTime tpoint = TransitionPoint
(rule.DaylightTransitionEnd, dateTime.Year);
+ if (dateTime > tpoint - rule.DaylightDelta && dateTime
<= tpoint)
+ return true;
+
+ return false;
+ }
+
+ public bool IsAmbiguousTime (DateTimeOffset dateTimeOffset)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public bool IsDaylightSavingTime (DateTime dateTime)
+ {
+ if (dateTime.Kind == DateTimeKind.Local &&
IsInvalidTime (dateTime))
+ throw new ArgumentException ("dateTime is
invalid and Kind is Local");
+
+ if (this == TimeZoneInfo.Utc)
+ return false;
+
+ if (!SupportsDaylightSavingTime)
+ return false;
+ //FIXME: do not rely on DateTime implementation !
+ if ((dateTime.Kind == DateTimeKind.Local ||
dateTime.Kind == DateTimeKind.Unspecified) && this == TimeZoneInfo.Local)
+ return dateTime.IsDaylightSavingTime ();
+
+ //FIXME: do not rely on DateTime implementation !
+ if (dateTime.Kind == DateTimeKind.Local && this !=
TimeZoneInfo.Utc)
+ return IsDaylightSavingTime
(DateTime.SpecifyKind (dateTime.ToUniversalTime (), DateTimeKind.Utc));
+
+ AdjustmentRule rule = GetApplicableRule (dateTime.Date);
+ if (rule == null)
+ return false;
+
+ DateTime DST_start = TransitionPoint
(rule.DaylightTransitionStart, dateTime.Year);
+ DateTime DST_end = TransitionPoint
(rule.DaylightTransitionEnd, dateTime.Year +
((rule.DaylightTransitionStart.Month < rule.DaylightTransitionEnd.Month) ? 0 :
1));
+ if (dateTime.Kind == DateTimeKind.Utc) {
+ DST_start -= BaseUtcOffset;
+ DST_end -= (BaseUtcOffset + rule.DaylightDelta);
+ }
+
+ return (dateTime >= DST_start && dateTime < DST_end)
+ }
+
+ public bool IsDaylightSavingTime (DateTimeOffset dateTimeOffset)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public bool IsInvalidTime (DateTime dateTime)
+ {
+ if (dateTime.Kind == DateTimeKind.Utc)
+ return false;
+ if (dateTime.Kind == DateTimeKind.Local && this !=
Local)
+ return false;
+
+ AdjustmentRule rule = GetApplicableRule (dateTime);
+ DateTime tpoint = TransitionPoint
(rule.DaylightTransitionStart, dateTime.Year);
+ if (dateTime >= tpoint && dateTime < tpoint +
rule.DaylightDelta)
+ return true;
+
+ return false;
+ }
+
+ public void OnDeserialization (object sender)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public string ToSerializedString ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override string ToString ()
+ {
+ return DisplayName;
+ }
+
+ private TimeZoneInfo (string id, TimeSpan baseUtcOffset, string
displayName, string standardDisplayName, string daylightDisplayName,
TimeZoneInfo.AdjustmentRule [] adjustmentRules, bool disableDaylightSavingTime)
+ {
+ if (id == null)
+ throw new ArgumentNullException ("id");
+
+ if (id == String.Empty)
+ throw new ArgumentException ("id parameter is
an empty string");
+
+ if (baseUtcOffset.Ticks % TimeSpan.TicksPerMinute != 0)
+ throw new ArgumentException ("baseUtcOffset
parameter does not represent a whole number of minutes");
+
+ if (baseUtcOffset > new TimeSpan (14, 0, 0) ||
baseUtcOffset < new TimeSpan (-14, 0, 0))
+ throw new ArgumentOutOfRangeException
("baseUtcOffset parameter is greater than 14 hours or less than -14 hours");
+
+#if STRICT
+ if (id.Length > 32)
+ throw new ArgumentException ("id parameter
shouldn't be longer than 32 characters");
+#endif
+
+ if (adjustmentRules != null && adjustmentRules.Length
!= 0) {
+ AdjustmentRule prev = null;
+ foreach (AdjustmentRule current in
adjustmentRules) {
+ if (current == null)
+ throw new
InvalidTimeZoneException ("one or more elements in adjustmentRules are null");
+
+ if ((baseUtcOffset +
current.DaylightDelta < new TimeSpan (-14, 0, 0)) ||
+ (baseUtcOffset +
current.DaylightDelta > new TimeSpan (14, 0, 0)))
+ throw new
InvalidTimeZoneException ("Sum of baseUtcOffset and DaylightDelta of one or
more object in adjustmentRules array is greater than 14 or less than -14
hours;");
+
+ if (prev != null && prev.DateStart >
current.DateStart)
+ throw new
InvalidTimeZoneException ("adjustment rules specified in adjustmentRules
parameter are not in chronological order");
+
+ if (prev != null && prev.DateEnd >
current.DateStart)
+ throw new
InvalidTimeZoneException ("some adjustment rules in the adjustmentRules
parameter overlap");
+
+ if (prev != null && prev.DateEnd ==
current.DateStart)
+ throw new
InvalidTimeZoneException ("a date can have multiple adjustment rules applied to
it");
+
+ prev = current;
+ }
+ }
+
+ this.id = id;
+ this.baseUtcOffset = baseUtcOffset;
+ this.displayName = displayName ?? id;
+ this.standardDisplayName = standardDisplayName ?? id;
+ this.daylightDisplayName = daylightDisplayName;
+ this.disableDaylightSavingTime =
disableDaylightSavingTime;
+ this.adjustmentRules = adjustmentRules;
+ }
+
+ private AdjustmentRule GetApplicableRule (DateTime dateTime)
+ {
+ //Transitions are always in standard time
+ DateTime date = dateTime;
+
+ if (dateTime.Kind == DateTimeKind.Local && this !=
TimeZoneInfo.Local)
+ date = date.ToUniversalTime () + BaseUtcOffset;
+
+ if (dateTime.Kind == DateTimeKind.Utc && this !=
TimeZoneInfo.Utc)
+ date = date + BaseUtcOffset;
+
+ foreach (AdjustmentRule rule in adjustmentRules) {
+ if (rule.DateStart > date.Date)
+ return null;
+ if (rule.DateEnd < date.Date)
+ continue;
+ return rule;
+ }
+ return null;
+ }
+
+ private static DateTime TransitionPoint (TransitionTime
transition, int year)
+ {
+ if (transition.IsFixedDateRule)
+ return new DateTime (year, transition.Month,
transition.Day) + transition.TimeOfDay.TimeOfDay;
+
+ DayOfWeek first = (new DateTime (year,
transition.Month, 1)).DayOfWeek;
+ int day = 1 + (transition.Week - 1) * 7 +
(transition.DayOfWeek - first) % 7;
+ if (day > DateTime.DaysInMonth (year,
transition.Month))
+ day -= 7;
+ return new DateTime (year, transition.Month, day) +
transition.TimeOfDay.TimeOfDay;
+ }
+
+#if LIBC
+ private static bool ValidTZFile (byte [] buffer, int length)
+ {
+ System.Text.StringBuilder magic = new
System.Text.StringBuilder ();
+
+ for (int i = 0; i < 4; i++)
+ magic.Append ((char)buffer [i]);
+
+ if (magic.ToString () != "TZif")
+ return false;
+
+ if (length >= BUFFER_SIZE)
+ return false;
+
+ return true;
+ }
+
+ private struct TimeType
+ {
+ int offset;
+ bool is_dst;
+ string abbrev;
+
+ public TimeType (int offset, bool is_dst, string abbrev)
+ {
+ this.offset = offset;
+ this.is_dst = is_dst;
+ this.abbrev = abbrev;
+ }
+
+ public int Offset {
+ get { return offset; }
+ }
+
+ public bool IsDst {
+ get { return is_dst; }
+ }
+
+ public string Name {
+ get { return abbrev; }
+ }
+
+ public override string ToString ()
+ {
+ return "offset: " + offset + "s, is_dst: " +
is_dst + ", zone name: " + abbrev;
+ }
+ }
+
+ private static TimeZoneInfo ParseTZBuffer (string id, byte []
buffer, int length)
+ {
+ DataConverter enc = DataConverter.BigEndian;
+
+ //Reading the header. 4 bytes for magic, 16 are reserved
+ int ttisgmtcnt = enc.GetInt32 (buffer, 20);
+ int ttisstdcnt = enc.GetInt32 (buffer, 24);
+ int leapcnt = enc.GetInt32 (buffer, 28);
+ int timecnt = enc.GetInt32 (buffer, 32);
+ int typecnt = enc.GetInt32 (buffer, 36);
+ int charcnt = enc.GetInt32 (buffer, 40);
+
+ if (length != 44 + timecnt * 5 + typecnt * 6 + charcnt
+ leapcnt * 8 + ttisstdcnt + ttisgmtcnt)
+ throw new InvalidTimeZoneException ();
+
+ Hashtable abbreviations = ParseAbbreviations (buffer,
44 + 4 * timecnt + timecnt + 6 * typecnt, charcnt);
+ Hashtable time_types = ParseTimesTypes (buffer, 44 + 4
* timecnt + timecnt, typecnt, abbreviations);
+ SortedList transitions = ParseTransitions (buffer, 44,
timecnt, time_types);
+
+ if (time_types.Count == 0)
+ throw new InvalidTimeZoneException ();
+
+ if (time_types.Count == 1 &&
((TimeType)time_types[0]).IsDst)
+ throw new InvalidTimeZoneException ();
+
+ TimeSpan baseUtcOffset = new TimeSpan (0);
+ TimeSpan dstDelta = new TimeSpan (0);
+ string standardDisplayName = null;
+ string daylightDisplayName = null;
+ bool dst_observed = false;
+ DateTime dst_start = DateTime.MinValue;
+ List<AdjustmentRule> adjustmentRules = new
List<AdjustmentRule> ();
+
+ for (int i = 0; i < transitions.Count; i++) {
+ DateTime ttime = (DateTime) transitions.GetKey
(i);
+ TimeType ttype = (TimeType) transitions [ttime];
+ if (!ttype.IsDst) {
+ if (standardDisplayName != ttype.Name
|| baseUtcOffset.TotalSeconds != ttype.Offset) {
+ standardDisplayName =
ttype.Name;
+ daylightDisplayName = null;
+ baseUtcOffset = new TimeSpan
(0, 0, ttype.Offset);
+ adjustmentRules = new
List<AdjustmentRule> ();
+ dst_observed = false;
+ }
+ if (dst_observed) {
+ //FIXME: check additional
fields for this:
+ //most of the transitions are
expressed in GMT
+ dst_start += baseUtcOffset;
+ DateTime dst_end = ttime +
baseUtcOffset + dstDelta;
+
+ DateTime dateStart, dateEnd;
+ if (dst_start.Month < 7)
+ dateStart = new
DateTime (dst_start.Year, 1, 1);
+ else
+ dateStart = new
DateTime (dst_start.Year, 7, 1);
+
+ if (dst_end.Month >= 7)
+ dateEnd = new DateTime
(dst_start.Year, 12, 31);
+ else
+ dateEnd = new DateTime
(dst_end.Year, 6, 30);
+
+ TransitionTime transition_start
= TransitionTime.CreateFixedDateRule (new DateTime (1, 1, 1) +
dst_start.TimeOfDay, dst_start.Month, dst_start.Day);
+ TransitionTime transition_end =
TransitionTime.CreateFixedDateRule (new DateTime (1, 1, 1) + dst_end.TimeOfDay,
dst_end.Month, dst_end.Day);
+ adjustmentRules.Add
(AdjustmentRule.CreateAdjustmentRule (dateStart, dateEnd, dstDelta,
transition_start, transition_end));
+ }
+ dst_observed = false;
+ } else {
+ if (daylightDisplayName != ttype.Name
|| dstDelta.TotalSeconds != ttype.Offset - baseUtcOffset.TotalSeconds) {
+ daylightDisplayName =
ttype.Name;
+ dstDelta = new TimeSpan(0, 0,
ttype.Offset) - baseUtcOffset;
+ }
+ dst_start = ttime;
+ dst_observed = true;
+ }
+ }
+
+ if (adjustmentRules.Count == 0) {
+ TimeType t = (TimeType)time_types [0];
+ if (standardDisplayName == null) {
+ standardDisplayName = t.Name;
+ baseUtcOffset = new TimeSpan (0, 0,
t.Offset);
+ }
+ return CreateCustomTimeZone (id, baseUtcOffset,
id, standardDisplayName);
+ } else {
+ return CreateCustomTimeZone (id, baseUtcOffset,
id, standardDisplayName, daylightDisplayName, adjustmentRules.ToArray ());
+ }
+ }
+
+ private static Hashtable ParseAbbreviations (byte [] buffer,
int index, int count)
+ {
+ Hashtable abbrevs = new Hashtable ();
+ int abbrev_index = 0;
+ System.Text.StringBuilder sb = new
System.Text.StringBuilder ();
+ for (int i = 0; i < count; i++) {
+ char c = (char) buffer [index + i];
+ if (c != '\0')
+ sb.Append (c);
+ else {
+ abbrevs.Add (abbrev_index, sb.ToString
());
+ abbrev_index = i + 1;
+ sb = new System.Text.StringBuilder ();
+ }
+ }
+ return abbrevs;
+ }
+
+ private static Hashtable ParseTimesTypes (byte [] buffer, int
index, int count, Hashtable abbreviations)
+ {
+ DataConverter enc = DataConverter.BigEndian;
+ Hashtable types = new Hashtable (count);
+ for (int i = 0; i < count; i++) {
+ int offset = enc.GetInt32 (buffer, index + 6 *
i);
+ byte is_dst = buffer [index + 6 * i + 4];
+ byte abbrev = buffer [index + 6 * i + 5];
+ types.Add (i, new TimeType (offset, (is_dst !=
0), abbreviations [(int)abbrev] as string));
+ }
+ return types;
+ }
+
+ private static SortedList ParseTransitions (byte [] buffer, int
index, int count, Hashtable time_types)
+ {
+ DataConverter enc = DataConverter.BigEndian;
+ SortedList trans = new SortedList (count);
+ for (int i = 0; i < count; i++) {
+ int unixtime = enc.GetInt32 (buffer, index + 4
* i);
+ DateTime ttime = DateTimeFromUnixTime
(unixtime);
+ byte ttype = buffer [index + 4 * count + i];
+ trans.Add (ttime, time_types [(int)ttype]);
+ }
+ return trans;
+ }
+
+ private static DateTime DateTimeFromUnixTime (long unix_time)
+ {
+ DateTime date_time = new DateTime (1970, 1, 1);
+ return date_time.AddSeconds (unix_time);
+ }
+#endif
+ }
+}
Added: trunk/mcs/class/System.Core/System/TimeZoneNotFoundException.cs
===================================================================
--- trunk/mcs/class/System.Core/System/TimeZoneNotFoundException.cs
2007-05-11 20:14:05 UTC (rev 77256)
+++ trunk/mcs/class/System.Core/System/TimeZoneNotFoundException.cs
2007-05-11 20:29:26 UTC (rev 77257)
@@ -0,0 +1,44 @@
+/*
+ * System.TimeZoneNotFoundException
+ *
+ * Author(s)
+ * Stephane Delcroix <[EMAIL PROTECTED]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+namespace System
+{
+ public class TimeZoneNotFoundException : Exception
+ {
+ public TimeZoneNotFoundException () : base ()
+ {}
+
+ public TimeZoneNotFoundException (string message) : base
(message)
+ {}
+
+ public TimeZoneNotFoundException (string message, Exception e)
: base (message, e)
+ {}
+
+ protected TimeZoneNotFoundException
(Runtime.Serialization.SerializationInfo info,
Runtime.Serialization.StreamingContext sc) : base (info, sc)
+ {}
+ }
+}
Modified: trunk/mcs/class/System.Core/System.Core.dll.sources
===================================================================
--- trunk/mcs/class/System.Core/System.Core.dll.sources 2007-05-11 20:14:05 UTC
(rev 77256)
+++ trunk/mcs/class/System.Core/System.Core.dll.sources 2007-05-11 20:29:26 UTC
(rev 77257)
@@ -1,5 +1,12 @@
../../build/common/Consts.cs
+../corlib/Mono.DataConvert/DataConverter.cs
Assembly/AssemblyInfo.cs
+System/DateTimeOffset.cs
+System/InvalidTimeZoneException.cs
+System/TimeZoneInfo.AdjustmentRule.cs
+System/TimeZoneInfo.cs
+System/TimeZoneInfo.TranstitionTime.cs
+System/TimeZoneNotFoundException.cs
System.Runtime.CompilerServices/ExtensionAttribute.cs
System.Linq/Enumerable.cs
System.Linq/Funcs.cs
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches