New error message.
[mono.git] / mcs / class / System.Core / System / TimeZoneInfo.AdjustmentRule.cs
1 /*
2  * System.TimeZoneInfo.AdjustmentRule
3  *
4  * Author(s)
5  *      Stephane Delcroix <stephane@delcroix.org>
6  *
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:
14  * 
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  * 
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.
25  */
26
27 #if (INSIDE_CORLIB && NET_4_0) || (NET_3_5 && !NET_4_0)
28
29 using System.Runtime.Serialization;
30
31 namespace System
32 {
33         public sealed partial class TimeZoneInfo {
34                 [SerializableAttribute]
35                 public sealed class AdjustmentRule : IEquatable<TimeZoneInfo.AdjustmentRule>, ISerializable, IDeserializationCallback
36                 {
37                         DateTime dateEnd;
38                         public DateTime DateEnd {
39                                 get { return dateEnd; } 
40                         }
41
42                         DateTime dateStart;
43                         public DateTime DateStart {
44                                 get { return dateStart; }
45                         }
46
47                         TimeSpan daylightDelta;
48                         public TimeSpan DaylightDelta {
49                                 get { return daylightDelta; }
50                         }
51
52                         TransitionTime daylightTransitionEnd;
53                         public TransitionTime DaylightTransitionEnd {
54                                 get { return daylightTransitionEnd; }
55                         }
56
57                         TransitionTime daylightTransitionStart;
58                         public TransitionTime DaylightTransitionStart {
59                                 get { return daylightTransitionStart; }
60                         }
61
62                         public static AdjustmentRule CreateAdjustmentRule (
63                                 DateTime dateStart,
64                                 DateTime dateEnd,
65                                 TimeSpan daylightDelta,
66                                 TransitionTime daylightTransitionStart,
67                                 TransitionTime daylightTransitionEnd)
68                         {
69                                 return new AdjustmentRule (dateStart, dateEnd, daylightDelta, daylightTransitionStart, daylightTransitionEnd);
70                         }
71
72                         private AdjustmentRule (
73                                 DateTime dateStart,
74                                 DateTime dateEnd,
75                                 TimeSpan daylightDelta,
76                                 TransitionTime daylightTransitionStart,
77                                 TransitionTime daylightTransitionEnd)
78                         {
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");
81
82                                 if (daylightTransitionStart == daylightTransitionEnd)
83                                         throw new ArgumentException ("daylightTransitionStart parameter cannot equal daylightTransitionEnd parameter");
84
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");
87
88                                 if (dateEnd < dateStart)
89                                         throw new ArgumentOutOfRangeException ("dateEnd is earlier than dateStart");
90
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");
93
94                                 if (daylightDelta.Ticks % TimeSpan.TicksPerSecond != 0)
95                                         throw new ArgumentOutOfRangeException ("daylightDelta parameter does not represent a whole number of seconds");
96
97                                 this.dateStart = dateStart;
98                                 this.dateEnd = dateEnd;
99                                 this.daylightDelta = daylightDelta;
100                                 this.daylightTransitionStart = daylightTransitionStart;
101                                 this.daylightTransitionEnd = daylightTransitionEnd;
102                         }
103
104                         public bool Equals (TimeZoneInfo.AdjustmentRule other)
105                         {
106                                 return dateStart == other.dateStart &&
107                                         dateEnd == other.dateEnd &&
108                                         daylightDelta == other.daylightDelta && 
109                                         daylightTransitionStart == other.daylightTransitionStart &&
110                                         daylightTransitionEnd == other.daylightTransitionEnd;
111                         }
112
113                         public override int GetHashCode ()
114                         {
115                                 return dateStart.GetHashCode () ^ 
116                                         dateEnd.GetHashCode () ^
117                                         daylightDelta.GetHashCode () ^
118                                         daylightTransitionStart.GetHashCode () ^
119                                         daylightTransitionEnd.GetHashCode ();
120                         }
121                                         
122                         public void GetObjectData (SerializationInfo info, StreamingContext context)
123                         {
124                                 throw new NotImplementedException ();
125                         }
126         
127                         public void OnDeserialization (object sender)
128                         {
129                                 throw new NotImplementedException ();
130                         }
131                 }
132         }
133 }
134
135 #endif