2 * System.TimeZoneInfo.AdjustmentRule
5 * Stephane Delcroix <stephane@delcroix.org>
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #if (INSIDE_CORLIB && NET_4_0) || (NET_2_1 && !INSIDE_CORLIB) || (NET_3_5 && !NET_4_0 && !BOOTSTRAP_NET_4_0)
29 using System
.Runtime
.Serialization
;
33 public sealed partial class TimeZoneInfo
{
34 [SerializableAttribute
]
35 public sealed class AdjustmentRule
: IEquatable
<TimeZoneInfo
.AdjustmentRule
>, ISerializable
, IDeserializationCallback
38 public DateTime DateEnd
{
39 get { return dateEnd; }
43 public DateTime DateStart
{
44 get { return dateStart; }
47 TimeSpan daylightDelta
;
48 public TimeSpan DaylightDelta
{
49 get { return daylightDelta; }
52 TransitionTime daylightTransitionEnd
;
53 public TransitionTime DaylightTransitionEnd
{
54 get { return daylightTransitionEnd; }
57 TransitionTime daylightTransitionStart
;
58 public TransitionTime DaylightTransitionStart
{
59 get { return daylightTransitionStart; }
62 public static AdjustmentRule
CreateAdjustmentRule (
65 TimeSpan daylightDelta
,
66 TransitionTime daylightTransitionStart
,
67 TransitionTime daylightTransitionEnd
)
69 return new AdjustmentRule (dateStart
, dateEnd
, daylightDelta
, daylightTransitionStart
, daylightTransitionEnd
);
72 private AdjustmentRule (
75 TimeSpan daylightDelta
,
76 TransitionTime daylightTransitionStart
,
77 TransitionTime daylightTransitionEnd
)
79 if (dateStart
.Kind
!= DateTimeKind
.Unspecified
|| dateEnd
.Kind
!= DateTimeKind
.Unspecified
)
80 throw new ArgumentException ("the Kind property of dateStart or dateEnd parameter does not equal DateTimeKind.Unspecified");
82 if (daylightTransitionStart
== daylightTransitionEnd
)
83 throw new ArgumentException ("daylightTransitionStart parameter cannot equal daylightTransitionEnd parameter");
85 if (dateStart
.Ticks
% TimeSpan
.TicksPerDay
!= 0 || dateEnd
.Ticks
% TimeSpan
.TicksPerDay
!= 0)
86 throw new ArgumentException ("dateStart or dateEnd parameter includes a time of day value");
88 if (dateEnd
< dateStart
)
89 throw new ArgumentOutOfRangeException ("dateEnd is earlier than dateStart");
91 if (daylightDelta
> new TimeSpan (14, 0, 0) || daylightDelta
< new TimeSpan (-14, 0, 0))
92 throw new ArgumentOutOfRangeException ("daylightDelta is less than -14 or greater than 14 hours");
94 if (daylightDelta
.Ticks
% TimeSpan
.TicksPerSecond
!= 0)
95 throw new ArgumentOutOfRangeException ("daylightDelta parameter does not represent a whole number of seconds");
97 this.dateStart
= dateStart
;
98 this.dateEnd
= dateEnd
;
99 this.daylightDelta
= daylightDelta
;
100 this.daylightTransitionStart
= daylightTransitionStart
;
101 this.daylightTransitionEnd
= daylightTransitionEnd
;
104 public bool Equals (TimeZoneInfo
.AdjustmentRule other
)
106 return dateStart
== other
.dateStart
&&
107 dateEnd
== other
.dateEnd
&&
108 daylightDelta
== other
.daylightDelta
&&
109 daylightTransitionStart
== other
.daylightTransitionStart
&&
110 daylightTransitionEnd
== other
.daylightTransitionEnd
;
113 public override int GetHashCode ()
115 return dateStart
.GetHashCode () ^
116 dateEnd
.GetHashCode () ^
117 daylightDelta
.GetHashCode () ^
118 daylightTransitionStart
.GetHashCode () ^
119 daylightTransitionEnd
.GetHashCode ();
122 public void GetObjectData (SerializationInfo info
, StreamingContext context
)
124 throw new NotImplementedException ();
127 public void OnDeserialization (object sender
)
129 throw new NotImplementedException ();