Revert "Revert "Merge branch 'master' of https://github.com/mono/mono""
[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  * Copyright 2011 Xamarin Inc.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  * 
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  * 
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28
29 using System;
30 using System.IO;
31 using System.Runtime.Serialization.Formatters.Binary;
32 using System.Collections;
33
34 using NUnit.Framework;
35 #if NET_2_0
36 namespace MonoTests.System
37 {
38         public class TimeZoneInfoTest
39         {
40                 [TestFixture]
41                 public class PropertiesTests
42                 {
43                         [Test]
44                         public void GetLocal ()
45                         {
46                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
47                                         Assert.Ignore ("Not running on Unix.");
48                                 TimeZoneInfo local = TimeZoneInfo.Local;
49                                 Assert.IsNotNull (local);
50                                 Assert.IsTrue (true);
51                         }
52                 }
53
54                 [TestFixture]
55                 public class CreateCustomTimezoneTests
56                 {
57                         [Test]
58                         [ExpectedException (typeof (ArgumentNullException))]
59                         public void IdIsNullException ()
60                         {
61                                 TimeZoneInfo.CreateCustomTimeZone (null, new TimeSpan (0), null, null); 
62                         }
63                 
64                         [Test]
65                         [ExpectedException (typeof (ArgumentException))]
66                         public void IdIsEmptyString ()
67                         {
68                                 TimeZoneInfo.CreateCustomTimeZone ("", new TimeSpan (0), null, null);   
69                         }
70                 
71                         [Test]
72                         [ExpectedException (typeof (ArgumentException))]
73                         public void OffsetIsNotMinutes ()
74                         {
75                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (0, 0, 55), null, null);  
76                         }
77                 
78                         [Test]
79                         [ExpectedException (typeof (ArgumentOutOfRangeException))]
80                         public void OffsetTooBig ()
81                         {
82                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (14, 1, 0), null, null);
83                         }
84                 
85                         [Test]
86                         [ExpectedException (typeof (ArgumentOutOfRangeException))]
87                         public void OffsetTooSmall ()
88                         {
89                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", - new TimeSpan (14, 1, 0), null, null);
90                         }
91                 
92                 #if STRICT
93                         [Test]
94                         [ExpectedException (typeof (ArgumentException))]
95                         public void IdLongerThan32 ()
96                         {
97                                 TimeZoneInfo.CreateCustomTimeZone ("12345678901234567890123456789012345", new TimeSpan (0), null, null);        
98                         }       
99                 #endif
100                 
101                         [Test]
102                         [ExpectedException (typeof (InvalidTimeZoneException))]
103                         public void AdjustmentRulesOverlap ()
104                         {
105                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
106                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
107                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
108                                 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
109                                 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
110                                 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2004,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
111                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
112                         }
113                 
114                         [Test]
115                         [ExpectedException (typeof (InvalidTimeZoneException))]
116                         public void RulesNotOrdered ()
117                         {
118                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
119                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
120                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
121                                 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
122                                 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
123                                 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2006,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
124                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r2, r1});
125                         }
126                 
127                         [Test]
128                         [ExpectedException (typeof (InvalidTimeZoneException))]
129                         public void OffsetOutOfRange ()
130                         {
131                                 TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
132                                 TimeZoneInfo.TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
133                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (3,0,0), startTransition, endTransition);
134                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {rule});
135                         }
136                 
137                         [Test]
138                         [ExpectedException (typeof (InvalidTimeZoneException))]
139                         public void NullRule ()
140                         {
141                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {null});
142                         }
143                 
144                         [Test]
145                         [ExpectedException (typeof (InvalidTimeZoneException))]
146                         public void MultiplesRulesForDate ()
147                         {
148                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
149                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
150                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
151                                 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
152                                 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
153                                 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2005,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
154                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
155                         }
156
157                         [Test]
158                         public void SupportsDaylightSavingTime_NonEmptyAdjustmentRule ()
159                         {
160                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
161                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
162                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
163                                 TimeZoneInfo tz = TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1});
164                                 Assert.IsTrue (tz.SupportsDaylightSavingTime);
165                         }
166
167                         [Test]
168                         public void SupportsDaylightSavingTime_EmptyAdjustmentRule ()
169                         {
170                                 TimeZoneInfo tz = TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,null);
171                                 Assert.IsFalse (tz.SupportsDaylightSavingTime);
172                         }
173
174                         [Test]
175                         public void SupportsDaylightSavingTime_NonEmptyAdjustmentRule_DisableDaylightSavingTime ()
176                         {
177                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
178                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
179                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
180                                 TimeZoneInfo tz = TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1}, true);
181                                 Assert.IsFalse (tz.SupportsDaylightSavingTime);
182                         }
183
184                         [Test]
185                         public void SupportsDaylightSavingTime_EmptyAdjustmentRule_DisableDaylightSavingTime ()
186                         {
187                                 TimeZoneInfo tz = TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,null,true);
188                                 Assert.IsFalse (tz.SupportsDaylightSavingTime);
189                         }
190                 }
191                 
192                 [TestFixture]
193                 public class IsDaylightSavingTimeTests
194                 {
195                         TimeZoneInfo london;
196                 
197                         [SetUp]
198                         public void CreateTimeZones ()
199                         {
200                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
201                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
202                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
203                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
204                         }
205                 
206                         [Test]
207                         public void NoDSTInUTC ()
208                         {
209                                 DateTime june01 = new DateTime (2007, 06, 01);
210                                 Assert.IsFalse (TimeZoneInfo.Utc.IsDaylightSavingTime (june01));
211                         }
212                 
213                         [Test]
214                         public void DSTInLondon ()
215                         {
216                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
217                                         Assert.Ignore ("Not running on Unix.");
218                                 DateTime june01 = new DateTime (2007, 06, 01);
219                                 DateTime xmas = new DateTime (2007, 12, 25);
220                                 Assert.IsTrue (london.IsDaylightSavingTime (june01), "June 01 is DST in London");
221                                 Assert.IsFalse (london.IsDaylightSavingTime (xmas), "Xmas is not DST in London");
222                         }
223                 
224                         [Test]
225                         public void DSTTransisions ()
226                         {
227                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
228                                         Assert.Ignore ("Not running on Unix.");
229                                 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Unspecified);
230                                 DateTime startDST = new DateTime (2007, 03, 25, 2, 0, 0, DateTimeKind.Unspecified);
231                                 DateTime endDST = new DateTime (2007, 10, 28, 1, 59, 59, DateTimeKind.Unspecified);
232                                 DateTime afterDST = new DateTime (2007, 10, 28, 2, 0, 0, DateTimeKind.Unspecified);
233                                 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
234                                 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
235                                 Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
236                                 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
237                         }
238                 
239                         [Test]
240                         public void DSTTransisionsUTC ()
241                         {
242                                 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Utc);
243                                 DateTime startDST = new DateTime (2007, 03, 25, 1, 0, 0, DateTimeKind.Utc);
244                                 DateTime endDST = new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc);
245                                 DateTime afterDST = new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc);
246                                 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
247                                 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
248                                 Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
249                                 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
250                         }
251                 
252                 #if SLOW_TESTS
253                         [Test]
254                         public void MatchTimeZoneBehavior ()
255                         {
256                                 TimeZone tzone = TimeZone.CurrentTimeZone;
257                                 TimeZoneInfo local = TimeZoneInfo.Local;
258                                 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)) {
259                                         date = DateTime.SpecifyKind (date, DateTimeKind.Local);
260                                         if (local.IsInvalidTime (date))
261                                                 continue;
262                                         Assert.IsTrue (tzone.IsDaylightSavingTime (date) == local.IsDaylightSavingTime (date));
263                                 }
264                         }
265                 #endif
266                         [Test (Description="Description xambug #17155")]
267                         public void AdjustmentRuleAfterNewYears ()
268                         {
269                                 TimeZoneInfo tz;
270                                 if (Environment.OSVersion.Platform == PlatformID.Unix)
271                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("Pacific/Auckland"); // *nix
272                                 else
273                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("New Zealand Standard Time"); // Windows
274
275                                 // DST start: 9/29/2013 2:00:00 AM
276                                 // DST end: 4/6/2014 3:00:00 AM
277                                 DateTime dt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Utc);
278                                 Assert.IsTrue (tz.IsDaylightSavingTime (dt), "#1.1");
279
280                                 // DST start: 9/29/2014 2:00:00 AM
281                                 // DST end: 4/6/2015 3:00:00 AM
282                                 dt = new DateTime (2014, 6, 9, 23, 0, 0, DateTimeKind.Utc);
283                                 Assert.IsFalse (tz.IsDaylightSavingTime (dt), "#2.1");
284
285                                 // DST start: 9/29/2014 2:00:00 AM
286                                 // DST end: 4/6/2015 3:00:00 AM
287                                 dt = new DateTime (2014, 10, 9, 23, 0, 0, DateTimeKind.Utc);
288                                 Assert.IsTrue (tz.IsDaylightSavingTime (dt), "#3.1");
289                         }
290                 }
291                 
292                 [TestFixture]
293                 public class ConvertTimeTests
294                 {
295                         TimeZoneInfo london;
296                 
297                         [SetUp]
298                         public void CreateTimeZones ()
299                         {
300                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
301                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
302                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
303                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
304                         }
305                 
306                         [Test]
307                         [ExpectedException (typeof (ArgumentException))]
308                         public void ConvertFromUtc_KindIsLocalException ()
309                         {
310                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
311                                         throw new ArgumentException ();
312                                 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0, DateTimeKind.Local), TimeZoneInfo.Local);  
313                         }
314                 
315                         [Test]
316                         [ExpectedException (typeof (ArgumentNullException))]
317                         public void ConvertFromUtc_DestinationTimeZoneIsNullException ()
318                         {
319                                 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0), null);            
320                         }
321                 
322                         [Test]
323                         public void ConvertFromUtc_DestinationIsUTC ()
324                         {
325                                 DateTime now = DateTime.UtcNow;
326                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (now, TimeZoneInfo.Utc);
327                                 Assert.AreEqual (now, converted);
328                         }
329                         
330                         [Test]
331                         public void ConvertFromUTC_ConvertInWinter ()
332                         {
333                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
334                                         Assert.Ignore ("Not running on Unix.");
335                                 DateTime utc = new DateTime (2007, 12, 25, 12, 0, 0);
336                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
337                                 Assert.AreEqual (utc, converted);
338                         }
339                 
340                         [Test]
341                         public void ConvertFromUtc_ConvertInSummer ()
342                         {
343                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
344                                         Assert.Ignore ("Not running on Unix.");
345                                 DateTime utc = new DateTime (2007, 06, 01, 12, 0, 0);
346                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
347                                 Assert.AreEqual (utc + new TimeSpan (1,0,0), converted);
348                         }
349                 
350                         [Test]
351                         public void ConvertToUTC_KindIsUtc ()
352                         {
353                                 DateTime now = DateTime.UtcNow;
354                                 Assert.AreEqual (now.Kind, DateTimeKind.Utc);
355                                 DateTime converted = TimeZoneInfo.ConvertTimeToUtc (now);
356                                 Assert.AreEqual (now, converted);
357                         }
358                 
359                         [Test]
360                         [ExpectedException (typeof (ArgumentException))]
361                         public void ConvertToUTC_KindIsUTCButSourceIsNot ()
362                         {
363                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Utc), london);
364                         }
365                 
366                         [Test]
367                         [ExpectedException (typeof (ArgumentException))]
368                         public void ConvertToUTC_KindIsLocalButSourceIsNot ()
369                         {
370                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
371                                         throw new ArgumentException ();
372                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Local), london);        
373                         }
374                 
375                         [Test]
376                         [ExpectedException (typeof (ArgumentException))]
377                         public void ConvertToUTC_InvalidDate ()
378                         {
379                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 3, 25, 1, 30, 0), london);
380                         }
381                 
382                         [Test]
383                         [ExpectedException (typeof (ArgumentNullException))]
384                         public void ConvertToUTC_SourceIsNull ()
385                         {
386                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 16, 0), null);
387                         }
388                 
389                 #if SLOW_TESTS
390                         [Test]
391                         public void ConvertToUtc_MatchDateTimeBehavior ()
392                         {
393                                 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)) {
394                                         Assert.AreEqual (TimeZoneInfo.ConvertTimeToUtc (date), date.ToUniversalTime ());
395                                 }
396                         }
397                 #endif
398                 
399                         [Test]
400                         public void ConvertFromToUtc ()
401                         {
402                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
403                                         Assert.Ignore ("Not running on Unix.");
404                                 DateTime utc = DateTime.UtcNow;
405                                 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
406                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
407                                 Assert.AreEqual (converted.Kind, DateTimeKind.Unspecified);
408                                 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, london);
409                                 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
410                                 Assert.AreEqual (utc, back);
411                 
412                         }
413
414
415                         [Test]
416                         public void ConvertFromToLocal ()
417                         {
418                                 DateTime utc = DateTime.UtcNow;
419                                 Assert.AreEqual(utc.Kind, DateTimeKind.Utc);
420                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc(utc, TimeZoneInfo.Local);
421                         #if NET_4_0
422                                 Assert.AreEqual(DateTimeKind.Local, converted.Kind);
423                         #else
424                                 Assert.AreEqual(DateTimeKind.Unspecified, converted.Kind);
425                         #endif
426                                 DateTime back = TimeZoneInfo.ConvertTimeToUtc(converted, TimeZoneInfo.Local);
427                                 Assert.AreEqual(back.Kind, DateTimeKind.Utc);
428                                 Assert.AreEqual(utc, back);
429                         }
430
431                         [Test]
432                         public void ConvertToTimeZone ()
433                         {
434                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
435                                         Assert.Ignore ("Not running on Unix.");
436
437                                 TimeZoneInfo.ConvertTime (DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Pacific/Auckland"));
438                         }
439
440                         [Test]
441                         [ExpectedException (typeof (ArgumentNullException))]
442                         public void ConvertTime_DateTime_TimeZoneInfo_DestinationTimeZoneIsNull ()
443                         {
444                                 TimeZoneInfo.ConvertTime (DateTime.Now, null);
445                         }
446
447                         [Test]
448                         public void ConvertTime_DateTime_TimeZoneInfo_DateTimeKindMatch ()
449                         {
450                                 var sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Utc);
451                                 var ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Utc);
452                                 Assert.AreEqual (ddt.Kind, sdt.Kind, "#1.1");
453                                 Assert.AreEqual (ddt.Kind, DateTimeKind.Utc, "#1.2");
454                                 
455                                 sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Local);
456                                 ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Local);
457                                 Assert.AreEqual (ddt.Kind, sdt.Kind, "#2.1");
458                                 Assert.AreEqual (ddt.Kind, DateTimeKind.Local, "#2.2");
459
460                                 sdt = new DateTime (2014, 1, 9, 23, 0, 0);
461                                 ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Local);
462                                 Assert.AreEqual (ddt.Kind, sdt.Kind, "#3.1");
463                                 Assert.AreEqual (ddt.Kind, DateTimeKind.Unspecified, "#3.2");
464                         }
465
466                         [Test]
467                         [ExpectedException (typeof (ArgumentNullException))]
468                         public void ConverTime_DateTime_TimeZoneInfo_TimeZoneInfo_SourceTimeZoneIsNull ()
469                         {
470                                 TimeZoneInfo.ConvertTime (DateTime.Now, null, TimeZoneInfo.Local);
471                         }
472
473                         [Test]
474                         [ExpectedException (typeof (ArgumentNullException))]
475                         public void ConverTime_DateTime_TimeZoneInfo_TimeZoneInfo_DestinationTimeZoneIsNull ()
476                         {
477                                 TimeZoneInfo.ConvertTime (DateTime.Now, TimeZoneInfo.Utc, null);
478                         }
479
480                         [Test (Description="Fix for xambug https://bugzilla.xamarin.com/show_bug.cgi?id=17155")]
481                         public void ConvertTime_AdjustmentRuleAfterNewYears ()
482                         {
483                                 TimeZoneInfo tz;
484                                 if (Environment.OSVersion.Platform == PlatformID.Unix)
485                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("Pacific/Auckland"); // *nix
486                                 else
487                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("New Zealand Standard Time"); // Windows
488
489                                 // DST start: 9/29/2013 2:00:00 AM
490                                 // DST end: 4/6/2014 3:00:00 AM
491                                 DateTime sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Utc);
492                                 DateTime ddt = TimeZoneInfo.ConvertTime (sdt, tz);
493                                 Assert.AreEqual (10, ddt.Day, "#1.1");
494                                 Assert.AreEqual (1, ddt.Month, "#1.2");
495                                 Assert.AreEqual (2014, ddt.Year, "#1.3");
496                                 Assert.AreEqual (12, ddt.Hour, "#1.4");
497                                 Assert.AreEqual (0, ddt.Minute, "#1.5");
498                                 Assert.AreEqual (0, ddt.Second, "#1.6");
499                                 
500                                 // DST start: 9/29/2014 2:00:00 AM
501                                 // DST end: 4/6/2015 3:00:00 AM
502                                 sdt = new DateTime (2014, 6, 9, 23, 0, 0, DateTimeKind.Utc);
503                                 ddt = TimeZoneInfo.ConvertTime (sdt, tz);
504                                 Assert.AreEqual (10, ddt.Day, "#2.1");
505                                 Assert.AreEqual (6, ddt.Month, "#2.2");
506                                 Assert.AreEqual (2014, ddt.Year, "#2.3");
507                                 Assert.AreEqual (11, ddt.Hour, "#2.4");
508                                 Assert.AreEqual (0, ddt.Minute, "#2.5");
509                                 Assert.AreEqual (0, ddt.Second, "#2.6");
510                                 
511                                 // DST start: 9/29/2014 2:00:00 AM
512                                 // DST end: 4/6/2015 3:00:00 AM
513                                 sdt = new DateTime (2014, 10, 9, 23, 0, 0, DateTimeKind.Utc);
514                                 ddt = TimeZoneInfo.ConvertTime (sdt, tz);
515                                 Assert.AreEqual (10, ddt.Day, "#3.1");
516                                 Assert.AreEqual (10, ddt.Month, "#3.2");
517                                 Assert.AreEqual (2014, ddt.Year, "#3.3");
518                                 Assert.AreEqual (12, ddt.Hour, "#3.4");
519                                 Assert.AreEqual (0, ddt.Minute, "#3.5");
520                                 Assert.AreEqual (0, ddt.Second, "#3.6");
521                         }
522                 }
523                 
524                 [TestFixture]
525                 public class IsInvalidTimeTests
526                 {
527                         TimeZoneInfo london;
528                 
529                         [SetUp]
530                         public void CreateTimeZones ()
531                         {
532                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
533                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
534                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
535                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
536                         }
537                 
538                 #if SLOW_TESTS
539                         [Test]
540                         public void UTCDate ()
541                         {
542                                 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)) {
543                                         date = DateTime.SpecifyKind (date, DateTimeKind.Utc);
544                                         Assert.IsFalse (london.IsInvalidTime (date));
545                                 }
546                         }
547                 #endif
548                         [Test]
549                         public void InvalidDates ()
550                         {
551                                 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 0, 59, 59)));
552                                 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 0, 0)));
553                                 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 59, 59)));
554                                 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 2, 0, 0)));
555                         }
556                 }
557                 
558                 [TestFixture]
559                 public class IsAmbiguousTimeTests
560                 {
561                         TimeZoneInfo london;
562                 
563                         [SetUp]
564                         public void CreateTimeZones ()
565                         {
566                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
567                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
568                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
569                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
570                         }
571                 
572                         [Test]
573                         public void AmbiguousDates ()
574                         {
575                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
576                                         Assert.Ignore ("Not running on Unix.");
577                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0)));
578                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 1)));
579                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 0)));
580                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 1)));
581                         }
582                 
583                         [Test]
584                         public void AmbiguousUTCDates ()
585                         {
586                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
587                                         Assert.Ignore ("Not running on Unix.");
588                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 0, DateTimeKind.Utc)));
589                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 1, DateTimeKind.Utc)));
590                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc)));
591                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc)));
592                         }
593                 
594                 #if SLOW_TESTS
595                         [Test]
596                         public void AmbiguousInUTC ()
597                         {
598                                 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)) {
599                                         Assert.IsFalse (TimeZoneInfo.Utc.IsAmbiguousTime (date));
600                                 }
601                         }
602                 #endif
603                 }
604                 
605                 [TestFixture]
606                 public class GetSystemTimeZonesTests
607                 {
608                         [Test]
609                         public void NotEmpty ()
610                         {
611                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
612                                         Assert.Ignore ("Not running on Unix.");
613                                 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
614                                 Assert.IsNotNull(systemTZ, "SystemTZ is null");
615                                 Assert.IsFalse (systemTZ.Count == 0, "SystemTZ is empty");
616                         }
617                 
618                         [Test]
619                         public void ContainsBrussels ()
620                         {
621                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
622                                         Assert.Ignore ("Not running on Unix.");
623                                 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
624                                 foreach (TimeZoneInfo tz in systemTZ) {
625                                         if (tz.Id == "Europe/Brussels")
626                                                 return;
627                                 }
628                                 Assert.Fail ("Europe/Brussels not found in SystemTZ");
629                         }
630                 }
631                 
632                 [TestFixture]
633                 public class FindSystemTimeZoneByIdTests
634                 {
635                         [Test]
636                         [ExpectedException (typeof (ArgumentNullException))]
637                         public void NullId ()
638                         {
639                                 TimeZoneInfo.FindSystemTimeZoneById (null);
640                         }
641                 
642                         [Test]
643                         [ExpectedException (typeof (TimeZoneNotFoundException))]
644                         public void NonSystemTimezone ()
645                         {
646                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
647                                         throw new TimeZoneNotFoundException ();
648                                 TimeZoneInfo.FindSystemTimeZoneById ("Neverland/The_Lagoon");
649                         }
650                 
651                         [Test]
652                         public void FindBrusselsTZ ()
653                         {
654                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
655                                         Assert.Ignore ("Not running on Unix.");
656                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
657                                 Assert.IsNotNull (brussels);
658                         }
659                 
660                         [Test]
661                         public void OffsetIsCorrectInKinshasa ()
662                         {
663                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
664                                         Assert.Ignore ("Not running on Unix.");
665                                 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
666                                 Assert.AreEqual (new TimeSpan (1,0,0), kin.BaseUtcOffset, "BaseUtcOffset in Kinshasa is not +1h");
667                         }
668                 
669                         [Test]
670                         public void OffsetIsCorrectInBrussels ()
671                         {
672                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
673                                         Assert.Ignore ("Not running on Unix.");
674                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
675                                 Assert.AreEqual (new TimeSpan (1,0,0), brussels.BaseUtcOffset, "BaseUtcOffset for Brussels is not +1h");
676                         }
677                 
678                         [Test]
679                         public void NoDSTInKinshasa ()
680                         {
681                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
682                                         Assert.Ignore ("Not running on Unix.");
683                                 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
684                                 Assert.IsFalse (kin.SupportsDaylightSavingTime);
685                         }
686                 
687                         [Test]
688                         public void BrusselsSupportsDST ()
689                         {
690                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
691                                         Assert.Ignore ("Not running on Unix.");
692                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
693                                 Assert.IsTrue (brussels.SupportsDaylightSavingTime);
694                         }
695                 
696                         [Test]
697                         public void MelbourneSupportsDST ()
698                         {
699                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
700                                         Assert.Ignore ("Not running on Unix.");
701                                 TimeZoneInfo melbourne = TimeZoneInfo.FindSystemTimeZoneById ("Australia/Melbourne");
702                                 Assert.IsTrue (melbourne.SupportsDaylightSavingTime);
703                         }
704                 
705                         [Test]
706                         public void RomeAndVaticanSharesTime ()
707                         {
708                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
709                                         Assert.Ignore ("Not running on Unix.");
710                                 TimeZoneInfo rome = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Rome");
711                                 TimeZoneInfo vatican = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Vatican");
712                                 Assert.IsTrue (rome.HasSameRules (vatican));
713                         }
714
715                         [Test]
716                         public void FindSystemTimeZoneById_Local_Roundtrip ()
717                         {
718                                 Assert.AreEqual (TimeZoneInfo.Local.Id, TimeZoneInfo.FindSystemTimeZoneById (TimeZoneInfo.Local.Id).Id);
719                         }
720
721                         [Test]
722                         public void Test326 ()
723                         {
724                                 DateTime utc = DateTime.UtcNow;
725                                 DateTime local = TimeZoneInfo.ConvertTime (utc, TimeZoneInfo.Utc, TimeZoneInfo.FindSystemTimeZoneById (TimeZoneInfo.Local.Id));
726                                 Assert.AreEqual (local, utc + TimeZoneInfo.Local.GetUtcOffset (utc), "ConvertTime/Local");
727                         }
728                 
729                 #if SLOW_TESTS
730                         [Test]
731                         public void BrusselsAdjustments ()
732                         {
733                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 3, 5, DayOfWeek.Sunday);
734                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,3,0,0), 10, 5, DayOfWeek.Sunday);
735                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
736                                 TimeZoneInfo brussels = TimeZoneInfo.CreateCustomTimeZone ("Europe/Brussels", new TimeSpan (1, 0, 0), "Europe/Brussels", "", "", new TimeZoneInfo.AdjustmentRule [] {rule});
737                 
738                                 TimeZoneInfo brussels_sys = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
739                 
740                                 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)) {
741                                         Assert.AreEqual (brussels.GetUtcOffset (date), brussels_sys.GetUtcOffset (date));
742                                         Assert.AreEqual (brussels.IsDaylightSavingTime (date), brussels_sys.IsDaylightSavingTime (date));
743                                 }               
744                         }
745                 #endif
746                 }
747                 
748                 [TestFixture]
749                 public class GetAmbiguousTimeOffsetsTests
750                 {
751                         [Test]
752                         [ExpectedException (typeof(ArgumentException))]
753                         public void DateIsNotAmbiguous ()
754                         {
755                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
756                                         throw new ArgumentException ();
757                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
758                                 DateTime date = new DateTime (2007, 05, 11, 11, 40, 00);
759                                 brussels.GetAmbiguousTimeOffsets (date);
760                         }
761                 
762                         [Test]
763                         public void AmbiguousOffsets ()
764                         {
765                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
766                                         Assert.Ignore ("Not running on Unix.");
767                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
768                                 DateTime date = new DateTime (2007, 10, 28, 2, 30, 00);
769                                 Assert.IsTrue (brussels.IsAmbiguousTime (date));
770                                 Assert.AreEqual (2, brussels.GetAmbiguousTimeOffsets (date).Length);
771                                 Assert.AreEqual (new TimeSpan[] {new TimeSpan (1, 0, 0), new TimeSpan (2, 0, 0)}, brussels.GetAmbiguousTimeOffsets (date));
772                         }
773                 }
774
775                 [TestFixture]
776                 public class HasSameRulesTests
777                 {
778                         [Test]
779                         public void NullAdjustments () //bnc #391011
780                         {
781                                 TimeZoneInfo utc = TimeZoneInfo.Utc;
782                                 TimeZoneInfo custom = TimeZoneInfo.CreateCustomTimeZone ("Custom", new TimeSpan (0), "Custom", "Custom");
783                                 Assert.IsTrue (utc.HasSameRules (custom));
784                         }
785                 }
786
787                 [TestFixture]
788                 public class SerializationTests
789                 {
790                         [Test]
791                         public void Serialization_Deserialization ()
792                         {
793                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
794                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
795                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
796                                 TimeZoneInfo london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
797                                 MemoryStream stream = new MemoryStream ();
798                                 BinaryFormatter formatter = new BinaryFormatter ();
799                                 formatter.Serialize (stream, london);
800                                 stream.Position = 0;
801                                 TimeZoneInfo deserialized = (TimeZoneInfo) formatter.Deserialize (stream);
802                                 stream.Close ();
803                                 stream.Dispose ();
804                                 Assert.IsTrue (london.Equals (deserialized));
805                         }
806                 }
807         }
808 }
809 #endif