2007-12-20 Stephane Delcroix <sdelcroix@novell.com>
[mono.git] / mcs / class / System.Core / Test / System / TimeZoneInfoTest.cs
1 /*
2  * TimeZoneInfo.Tests
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 using System;
28 using System.Collections;
29
30 using NUnit.Framework;
31 #if NET_2_0
32 namespace MonoTests.System
33 {
34         public class TimeZoneInfoTest
35         {
36                 [TestFixture]
37                 public class PropertiesTests
38                 {
39                         [Test]
40                         public void GetLocal ()
41                         {
42                                 TimeZoneInfo local = TimeZoneInfo.Local;
43                                 Assert.IsTrue (true);
44                         }
45                 }
46
47                 [TestFixture]
48                 public class CreateCustomTimezoneTests
49                 {
50                         [Test]
51                         [ExpectedException (typeof (ArgumentNullException))]
52                         public void IdIsNullException ()
53                         {
54                                 TimeZoneInfo.CreateCustomTimeZone (null, new TimeSpan (0), null, null); 
55                         }
56                 
57                         [Test]
58                         [ExpectedException (typeof (ArgumentException))]
59                         public void IdIsEmptyString ()
60                         {
61                                 TimeZoneInfo.CreateCustomTimeZone ("", new TimeSpan (0), null, null);   
62                         }
63                 
64                         [Test]
65                         [ExpectedException (typeof (ArgumentException))]
66                         public void OffsetIsNotMinutes ()
67                         {
68                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (0, 0, 55), null, null);  
69                         }
70                 
71                         [Test]
72                         [ExpectedException (typeof (ArgumentOutOfRangeException))]
73                         public void OffsetTooBig ()
74                         {
75                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (14, 1, 0), null, null);
76                         }
77                 
78                         [Test]
79                         [ExpectedException (typeof (ArgumentOutOfRangeException))]
80                         public void OffsetTooSmall ()
81                         {
82                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", - new TimeSpan (14, 1, 0), null, null);
83                         }
84                 
85                 #if STRICT
86                         [Test]
87                         [ExpectedException (typeof (ArgumentException))]
88                         public void IdLongerThan32 ()
89                         {
90                                 TimeZoneInfo.CreateCustomTimeZone ("12345678901234567890123456789012345", new TimeSpan (0), null, null);        
91                         }       
92                 #endif
93                 
94                         [Test]
95                         [ExpectedException (typeof (InvalidTimeZoneException))]
96                         public void AdjustmentRulesOverlap ()
97                         {
98                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
99                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
100                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
101                                 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
102                                 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
103                                 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2004,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
104                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
105                         }
106                 
107                         [Test]
108                         [ExpectedException (typeof (InvalidTimeZoneException))]
109                         public void RulesNotOrdered ()
110                         {
111                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
112                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
113                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
114                                 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
115                                 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
116                                 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2006,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
117                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r2, r1});
118                         }
119                 
120                         [Test]
121                         [ExpectedException (typeof (InvalidTimeZoneException))]
122                         public void OffsetOutOfRange ()
123                         {
124                                 TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
125                                 TimeZoneInfo.TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
126                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (3,0,0), startTransition, endTransition);
127                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {rule});
128                         }
129                 
130                         [Test]
131                         [ExpectedException (typeof (InvalidTimeZoneException))]
132                         public void NullRule ()
133                         {
134                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {null});
135                         }
136                 
137                         [Test]
138                         [ExpectedException (typeof (InvalidTimeZoneException))]
139                         public void MultiplesRulesForDate ()
140                         {
141                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
142                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
143                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
144                                 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
145                                 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
146                                 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2005,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
147                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
148                         }
149                 }
150                 
151                 [TestFixture]
152                 public class IsDaylightSavingTimeTests
153                 {
154                         TimeZoneInfo london;
155                 
156                         [SetUp]
157                         public void CreateTimeZones ()
158                         {
159                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
160                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
161                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
162                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
163                         }
164                 
165                         [Test]
166                         public void NoDSTInUTC ()
167                         {
168                                 DateTime june01 = new DateTime (2007, 06, 01);
169                                 Assert.IsFalse (TimeZoneInfo.Utc.IsDaylightSavingTime (june01));
170                         }
171                 
172                         [Test]
173                         public void DSTInLondon ()
174                         {
175                                 DateTime june01 = new DateTime (2007, 06, 01);
176                                 DateTime xmas = new DateTime (2007, 12, 25);
177                                 Assert.IsTrue (london.IsDaylightSavingTime (june01), "June 01 is DST in London");
178                                 Assert.IsFalse (london.IsDaylightSavingTime (xmas), "Xmas is not DST in London");
179                         }
180                 
181                         [Test]
182                         public void DSTTransisions ()
183                         {
184                                 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Unspecified);
185                                 DateTime startDST = new DateTime (2007, 03, 25, 2, 0, 0, DateTimeKind.Unspecified);
186                                 DateTime endDST = new DateTime (2007, 10, 28, 1, 59, 59, DateTimeKind.Unspecified);
187                                 DateTime afterDST = new DateTime (2007, 10, 28, 2, 0, 0, DateTimeKind.Unspecified);
188                                 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
189                                 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
190                                 Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
191                                 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
192                         }
193                 
194                         [Test]
195                         public void DSTTransisionsUTC ()
196                         {
197                                 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Utc);
198                                 DateTime startDST = new DateTime (2007, 03, 25, 1, 0, 0, DateTimeKind.Utc);
199                                 DateTime endDST = new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc);
200                                 DateTime afterDST = new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc);
201                                 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
202                                 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
203                                 Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
204                                 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
205                         }
206                 
207                 #if SLOW_TESTS
208                         [Test]
209                         public void MatchTimeZoneBehavior ()
210                         {
211                                 TimeZone tzone = TimeZone.CurrentTimeZone;
212                                 TimeZoneInfo local = TimeZoneInfo.Local;
213                                 for (DateTime date = new DateTime (2007, 01, 01, 0, 0, 0, DateTimeKind.Local); date < new DateTime (2007, 12, 31, 23, 59, 59); date += new TimeSpan (0,1,0)) {
214                                         date = DateTime.SpecifyKind (date, DateTimeKind.Local);
215                                         if (local.IsInvalidTime (date))
216                                                 continue;
217                                         Assert.IsTrue (tzone.IsDaylightSavingTime (date) == local.IsDaylightSavingTime (date));
218                                 }
219                         }
220                 #endif
221                 }
222                 
223                 [TestFixture]
224                 public class ConvertTimeTests
225                 {
226                         TimeZoneInfo london;
227                 
228                         [SetUp]
229                         public void CreateTimeZones ()
230                         {
231                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
232                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
233                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
234                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
235                         }
236                 
237                         [Test]
238                         [ExpectedException (typeof (ArgumentException))]
239                         public void ConvertFromUtc_KindIsLocalException ()
240                         {
241                                 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0, DateTimeKind.Local), TimeZoneInfo.Local);  
242                         }
243                 
244                         [Test]
245                         [ExpectedException (typeof (ArgumentNullException))]
246                         public void ConvertFromUtc_DestinationTimeZoneIsNullException ()
247                         {
248                                 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0), null);            
249                         }
250                 
251                         [Test]
252                         public void ConvertFromUtc_DestinationIsUTC ()
253                         {
254                                 DateTime now = DateTime.UtcNow;
255                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (now, TimeZoneInfo.Utc);
256                                 Assert.AreEqual (now, converted);
257                         }
258                         
259                         [Test]
260                         public void ConvertFromUTC_ConvertInWinter ()
261                         {
262                                 DateTime utc = new DateTime (2007, 12, 25, 12, 0, 0);
263                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
264                                 Assert.AreEqual (utc, converted);
265                         }
266                 
267                         [Test]
268                         public void ConvertFromUtc_ConvertInSummer ()
269                         {
270                                 DateTime utc = new DateTime (2007, 06, 01, 12, 0, 0);
271                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
272                                 Assert.AreEqual (utc + new TimeSpan (1,0,0), converted);
273                         }
274                 
275                         [Test]
276                         public void ConvertToUTC_KindIsUtc ()
277                         {
278                                 DateTime now = DateTime.UtcNow;
279                                 Assert.AreEqual (now.Kind, DateTimeKind.Utc);
280                                 DateTime converted = TimeZoneInfo.ConvertTimeToUtc (now);
281                                 Assert.AreEqual (now, converted);
282                         }
283                 
284                         [Test]
285                         [ExpectedException (typeof (ArgumentException))]
286                         public void ConvertToUTC_KindIsUTCButSourceIsNot ()
287                         {
288                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Utc), london);
289                         }
290                 
291                         [Test]
292                         [ExpectedException (typeof (ArgumentException))]
293                         public void ConvertToUTC_KindIsLocalButSourceIsNot ()
294                         {
295                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Local), london);        
296                         }
297                 
298                         [Test]
299                         [ExpectedException (typeof (ArgumentException))]
300                         public void ConvertToUTC_InvalidDate ()
301                         {
302                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 3, 25, 1, 30, 0), london);
303                         }
304                 
305                         [Test]
306                         [ExpectedException (typeof (ArgumentNullException))]
307                         public void ConvertToUTC_SourceIsNull ()
308                         {
309                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 16, 0), null);
310                         }
311                 
312                 #if SLOW_TESTS
313                         [Test]
314                         public void ConvertToUtc_MatchDateTimeBehavior ()
315                         {
316                                 for (DateTime date = new DateTime (2007, 01, 01, 0, 0, 0); date < new DateTime (2007, 12, 31, 23, 59, 59); date += new TimeSpan (0,1,0)) {
317                                         Assert.AreEqual (TimeZoneInfo.ConvertTimeToUtc (date), date.ToUniversalTime ());
318                                 }
319                         }
320                 #endif
321                 
322                         [Test]
323                         public void ConvertFromToUtc ()
324                         {
325                                 DateTime utc = DateTime.UtcNow;
326                                 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
327                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
328                                 Assert.AreEqual (converted.Kind, DateTimeKind.Unspecified);
329                                 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, london);
330                                 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
331                                 Assert.AreEqual (utc, back);
332                 
333                         }
334                 }
335                 
336                 [TestFixture]
337                 public class IsInvalidTimeTests
338                 {
339                         TimeZoneInfo london;
340                 
341                         [SetUp]
342                         public void CreateTimeZones ()
343                         {
344                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
345                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
346                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
347                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
348                         }
349                 
350                 #if SLOW_TESTS
351                         [Test]
352                         public void UTCDate ()
353                         {
354                                 for (DateTime date = new DateTime (2007, 01, 01, 0, 0, 0); date < new DateTime (2007, 12, 31, 23, 59, 59); date += new TimeSpan (0,1,0)) {
355                                         date = DateTime.SpecifyKind (date, DateTimeKind.Utc);
356                                         Assert.IsFalse (london.IsInvalidTime (date));
357                                 }
358                         }
359                 #endif
360                         [Test]
361                         public void InvalidDates ()
362                         {
363                                 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 0, 59, 59)));
364                                 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 0, 0)));
365                                 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 59, 59)));
366                                 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 2, 0, 0)));
367                         }
368                 }
369                 
370                 [TestFixture]
371                 public class IsAmbiguousTimeTests
372                 {
373                         TimeZoneInfo london;
374                 
375                         [SetUp]
376                         public void CreateTimeZones ()
377                         {
378                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
379                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
380                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
381                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
382                         }
383                 
384                         [Test]
385                         public void AmbiguousDates ()
386                         {
387                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0)));
388                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 1)));
389                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 0)));
390                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 1)));
391                         }
392                 
393                         [Test]
394                         public void AmbiguousUTCDates ()
395                         {
396                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 0, DateTimeKind.Utc)));
397                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 1, DateTimeKind.Utc)));
398                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc)));
399                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc)));
400                         }
401                 
402                 #if SLOW_TESTS
403                         [Test]
404                         public void AmbiguousInUTC ()
405                         {
406                                 for (DateTime date = new DateTime (2007, 01, 01, 0, 0, 0); date < new DateTime (2007, 12, 31, 23, 59, 59); date += new TimeSpan (0,1,0)) {
407                                         Assert.IsFalse (TimeZoneInfo.Utc.IsAmbiguousTime (date));
408                                 }
409                         }
410                 #endif
411                 }
412                 
413                 [TestFixture]
414                 public class GetSystemTimeZonesTests
415                 {
416                         [Test]
417                         public void NotEmpty ()
418                         {
419                                 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
420                                 Assert.IsNotNull(systemTZ, "SystemTZ is null");
421                                 Assert.IsFalse (systemTZ.Count == 0, "SystemTZ is empty");
422                         }
423                 
424                         [Test]
425                         public void ContainsBrussels ()
426                         {
427                                 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
428                                 foreach (TimeZoneInfo tz in systemTZ) {
429                                         if (tz.Id == "Europe/Brussels")
430                                                 return;
431                                 }
432                                 Assert.Fail ("Europe/Brussels not found in SystemTZ");
433                         }
434                 }
435                 
436                 [TestFixture]
437                 public class FindSystemTimeZoneByIdTests
438                 {
439                         [Test]
440                         [ExpectedException (typeof (ArgumentNullException))]
441                         public void NullId ()
442                         {
443                                 TimeZoneInfo.FindSystemTimeZoneById (null);
444                         }
445                 
446                         [Test]
447                         [ExpectedException (typeof (TimeZoneNotFoundException))]
448                         public void NonSystemTimezone ()
449                         {
450                                 TimeZoneInfo.FindSystemTimeZoneById ("Neverland/The_Lagoon");
451                         }
452                 
453                         [Test]
454                         public void FindBrusselsTZ ()
455                         {
456                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
457                                 Assert.IsNotNull (brussels);
458                         }
459                 
460                         [Test]
461                         public void OffsetIsCorrectInKinshasa ()
462                         {
463                                 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
464                                 Assert.AreEqual (new TimeSpan (1,0,0), kin.BaseUtcOffset, "BaseUtcOffset in Kinshasa is not +1h");
465                         }
466                 
467                         [Test]
468                         public void OffsetIsCorrectInBrussels ()
469                         {
470                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
471                                 Assert.AreEqual (new TimeSpan (1,0,0), brussels.BaseUtcOffset, "BaseUtcOffset for Brussels is not +1h");
472                         }
473                 
474                         [Test]
475                         public void NoDSTInKinshasa ()
476                         {
477                                 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
478                                 Assert.IsFalse (kin.SupportsDaylightSavingTime);
479                         }
480                 
481                         [Test]
482                         public void BrusselsSupportsDST ()
483                         {
484                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
485                                 Assert.IsTrue (brussels.SupportsDaylightSavingTime);
486                         }
487                 
488                         [Test]
489                         public void MelbourneSupportsDST ()
490                         {
491                                 TimeZoneInfo melbourne = TimeZoneInfo.FindSystemTimeZoneById ("Australia/Melbourne");
492                                 Assert.IsTrue (melbourne.SupportsDaylightSavingTime);
493                         }
494                 
495                         [Test]
496                         public void RomeAndVaticanSharesTime ()
497                         {
498                                 TimeZoneInfo rome = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Rome");
499                                 TimeZoneInfo vatican = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Vatican");
500                                 Assert.IsTrue (rome.HasSameRules (vatican));
501                         }
502                 
503                 #if SLOW_TESTS
504                         [Test]
505                         public void BrusselsAdjustments ()
506                         {
507                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 3, 5, DayOfWeek.Sunday);
508                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,3,0,0), 10, 5, DayOfWeek.Sunday);
509                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
510                                 TimeZoneInfo brussels = TimeZoneInfo.CreateCustomTimeZone ("Europe/Brussels", new TimeSpan (1, 0, 0), "Europe/Brussels", "", "", new TimeZoneInfo.AdjustmentRule [] {rule});
511                 
512                                 TimeZoneInfo brussels_sys = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
513                 
514                                 for (DateTime date = new DateTime (2006, 01, 01, 0, 0, 0, DateTimeKind.Local); date < new DateTime (2007, 12, 31, 23, 59, 59); date += new TimeSpan (0,30,0)) {
515                                         Assert.AreEqual (brussels.GetUtcOffset (date), brussels_sys.GetUtcOffset (date));
516                                         Assert.AreEqual (brussels.IsDaylightSavingTime (date), brussels_sys.IsDaylightSavingTime (date));
517                                 }               
518                         }
519                 #endif
520                 }
521                 
522                 [TestFixture]
523                 public class GetAmbiguousTimeOffsetsTests
524                 {
525                         [Test]
526                         [ExpectedException (typeof(ArgumentException))]
527                         public void DateIsNotAmbiguous ()
528                         {
529                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
530                                 DateTime date = new DateTime (2007, 05, 11, 11, 40, 00);
531                                 brussels.GetAmbiguousTimeOffsets (date);
532                         }
533                 
534                         [Test]
535                         public void AmbiguousOffsets ()
536                         {
537                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
538                                 DateTime date = new DateTime (2007, 10, 28, 2, 30, 00);
539                                 Assert.IsTrue (brussels.IsAmbiguousTime (date));
540                                 Assert.AreEqual (2, brussels.GetAmbiguousTimeOffsets (date).Length);
541                                 Assert.AreEqual (new TimeSpan[] {new TimeSpan (1, 0, 0), new TimeSpan (2, 0, 0)}, brussels.GetAmbiguousTimeOffsets (date));
542                         }
543                 }
544         }
545 }
546 #endif