2 * System.TimeZoneInfo.TransitionTime
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 || BOOTSTRAP_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
35 [SerializableAttribute
]
36 #if NET_4_0 || BOOTSRAP_NET_4_0
37 [TypeForwardedFrom (Consts
.AssemblySystemCore_3_5
)]
39 public struct TransitionTime
: IEquatable
<TimeZoneInfo
.TransitionTime
>, ISerializable
, IDeserializationCallback
42 public DateTime TimeOfDay
{
43 get { return timeOfDay; }
56 throw new Exception ("Day property is not valid for floating date rules");
67 throw new Exception ("Week property is not valid for fixed date rules");
75 public DayOfWeek DayOfWeek
{
79 throw new Exception ("DayOfWeek property is not valid for fixed date rules");
87 public bool IsFixedDateRule
{
88 get { return isFixedDateRule; }
91 public static TransitionTime
CreateFixedDateRule (
96 return new TransitionTime (timeOfDay
, month
, day
);
99 public static TransitionTime
CreateFloatingDateRule (
105 return new TransitionTime (timeOfDay
, month
, week
, dayOfWeek
);
108 private TransitionTime (
111 int day
) : this (timeOfDay
, month
)
113 if (day
< 1 || day
> 31)
114 throw new ArgumentOutOfRangeException ("day parameter is less than 1 or greater than 31");
117 this.isFixedDateRule
= true;
120 private TransitionTime (
124 DayOfWeek dayOfWeek
) : this (timeOfDay
, month
)
126 if (week
< 1 || week
> 5)
127 throw new ArgumentOutOfRangeException ("week parameter is less than 1 or greater than 5");
129 if (dayOfWeek
!= DayOfWeek
.Sunday
&&
130 dayOfWeek
!= DayOfWeek
.Monday
&&
131 dayOfWeek
!= DayOfWeek
.Tuesday
&&
132 dayOfWeek
!= DayOfWeek
.Wednesday
&&
133 dayOfWeek
!= DayOfWeek
.Thursday
&&
134 dayOfWeek
!= DayOfWeek
.Friday
&&
135 dayOfWeek
!= DayOfWeek
.Saturday
)
136 throw new ArgumentOutOfRangeException ("dayOfWeek parameter is not a member od DayOfWeek enumeration");
139 this.dayOfWeek
= dayOfWeek
;
140 this.isFixedDateRule
= false;
143 private TransitionTime (
147 if (timeOfDay
.Year
!= 1 || timeOfDay
.Month
!= 1 || timeOfDay
.Day
!= 1)
148 throw new ArgumentException ("timeOfDay parameter has a non-default date component");
150 if (timeOfDay
.Kind
!= DateTimeKind
.Unspecified
)
151 throw new ArgumentException ("timeOfDay parameter Kind's property is not DateTimeKind.Unspecified");
153 if (timeOfDay
.Ticks
% TimeSpan
.TicksPerMillisecond
!= 0)
154 throw new ArgumentException ("timeOfDay parameter does not represent a whole number of milliseconds");
156 if (month
< 1 || month
> 12)
157 throw new ArgumentOutOfRangeException ("month parameter is less than 1 or greater than 12");
159 this.timeOfDay
= timeOfDay
;
163 this.dayOfWeek
= (System
.DayOfWeek
)(-1);
165 this.isFixedDateRule
= false;
168 public static bool operator == (TransitionTime t1
, TransitionTime t2
)
170 return ( t1
.day
== t2
.day
&&
171 t1
.dayOfWeek
== t2
.dayOfWeek
&&
172 t1
.isFixedDateRule
== t2
.isFixedDateRule
&&
173 t1
.month
== t2
.month
&&
174 t1
.timeOfDay
== t2
.timeOfDay
&&
178 public static bool operator != (TransitionTime t1
, TransitionTime t2
)
185 void ISerializable
.GetObjectData (SerializationInfo info
, StreamingContext context
)
187 public void GetObjectData (SerializationInfo info
, StreamingContext context
)
190 throw new NotImplementedException ();
193 public override bool Equals (object other
)
195 if (other
is TransitionTime
)
196 return this == (TransitionTime
) other
;
200 public bool Equals (TimeZoneInfo
.TransitionTime other
)
202 return this == other
;
205 public override int GetHashCode ()
207 return (day ^
(int)dayOfWeek ^ month ^
(int)timeOfDay
.Ticks ^ week
);
211 void IDeserializationCallback
.OnDeserialization (object sender
)
213 public void OnDeserialization (object sender
)
216 throw new NotImplementedException ();