[System.Runtime.Serialization] Static writer fix.
[mono.git] / mcs / class / corlib / 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.InteropServices;
32 using System.Runtime.Serialization.Formatters.Binary;
33 using System.Collections;
34 using System.Reflection;
35 using System.Globalization;
36
37 using NUnit.Framework;
38 namespace MonoTests.System
39 {
40         public class TimeZoneInfoTest
41         {
42                 static FieldInfo localField;
43                 static FieldInfo cachedDataField;
44                 static object localFieldObj;
45
46                 public static void SetLocal (TimeZoneInfo val)
47                 {
48                         if (localField == null) {
49                                 if (Type.GetType ("Mono.Runtime") != null) {
50                                         localField = typeof (TimeZoneInfo).GetField ("local",
51                                                         BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic);
52                                 } else {
53                                         cachedDataField = typeof (TimeZoneInfo).GetField ("s_cachedData",
54                                                         BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic);
55
56                                         localField = cachedDataField.FieldType.GetField ("m_localTimeZone",
57                                                 BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);
58                                 }
59                         }
60
61                         if (cachedDataField != null)
62                                 localFieldObj = cachedDataField.GetValue (null);
63
64                         localField.SetValue (localFieldObj, val);
65                 }
66
67                 [TestFixture]
68                 public class PropertiesTests
69                 {
70                         [Test]
71                         public void GetLocal ()
72                         {
73                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
74                                         Assert.Ignore ("Not running on Unix.");
75                                 TimeZoneInfo local = TimeZoneInfo.Local;
76                                 Assert.IsNotNull (local);
77                                 Assert.IsTrue (true);
78                         }
79
80                         [DllImport ("libc")]
81                         private static extern int readlink (string path, byte[] buffer, int buflen);
82
83                         [Test] // Covers #24958
84                         public void LocalId ()
85                         {
86                                 byte[] buf = new byte [512];
87
88                                 var path = "/etc/localtime";
89                                 try {
90                                         var ret = readlink (path, buf, buf.Length);
91                                         if (ret == -1)
92                                                 return; // path is not a symbolic link, nothing to test
93                                 } catch (DllNotFoundException e) {
94                                         return;
95                                 }
96 #if !MONOTOUCH && !XAMMAC
97                                 // this assumption is incorrect for iOS, tvO, watchOS and OSX
98                                 Assert.IsTrue (TimeZoneInfo.Local.Id != "Local", "Local timezone id should not be \"Local\"");
99 #endif
100                         }
101                 }
102
103                 [TestFixture]
104                 public class CreateCustomTimezoneTests
105                 {
106                         [Test]
107                         [ExpectedException (typeof (ArgumentNullException))]
108                         public void IdIsNullException ()
109                         {
110                                 TimeZoneInfo.CreateCustomTimeZone (null, new TimeSpan (0), null, null); 
111                         }
112                 
113                         [Test]
114                         [ExpectedException (typeof (ArgumentException))]
115                         public void IdIsEmptyString ()
116                         {
117                                 TimeZoneInfo.CreateCustomTimeZone ("", new TimeSpan (0), null, null);   
118                         }
119                 
120                         [Test]
121                         [ExpectedException (typeof (ArgumentException))]
122                         public void OffsetIsNotMinutes ()
123                         {
124                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (0, 0, 55), null, null);  
125                         }
126                 
127                         [Test]
128                         [ExpectedException (typeof (ArgumentOutOfRangeException))]
129                         public void OffsetTooBig ()
130                         {
131                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (14, 1, 0), null, null);
132                         }
133                 
134                         [Test]
135                         [ExpectedException (typeof (ArgumentOutOfRangeException))]
136                         public void OffsetTooSmall ()
137                         {
138                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", - new TimeSpan (14, 1, 0), null, null);
139                         }
140                 
141                 #if STRICT
142                         [Test]
143                         [ExpectedException (typeof (ArgumentException))]
144                         public void IdLongerThan32 ()
145                         {
146                                 TimeZoneInfo.CreateCustomTimeZone ("12345678901234567890123456789012345", new TimeSpan (0), null, null);        
147                         }       
148                 #endif
149                 
150                         [Test]
151                         [ExpectedException (typeof (InvalidTimeZoneException))]
152                         public void AdjustmentRulesOverlap ()
153                         {
154                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
155                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
156                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
157                                 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
158                                 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
159                                 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2004,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
160                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
161                         }
162                 
163                         [Test]
164                         [ExpectedException (typeof (InvalidTimeZoneException))]
165                         public void RulesNotOrdered ()
166                         {
167                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
168                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
169                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
170                                 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
171                                 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
172                                 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2006,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
173                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r2, r1});
174                         }
175                 
176                         [Test]
177                         [ExpectedException (typeof (InvalidTimeZoneException))]
178                         public void OffsetOutOfRange ()
179                         {
180                                 TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
181                                 TimeZoneInfo.TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
182                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (3,0,0), startTransition, endTransition);
183                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {rule});
184                         }
185                 
186                         [Test]
187                         [ExpectedException (typeof (InvalidTimeZoneException))]
188                         public void NullRule ()
189                         {
190                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {null});
191                         }
192                 
193                         [Test]
194                         [ExpectedException (typeof (InvalidTimeZoneException))]
195                         public void MultiplesRulesForDate ()
196                         {
197                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
198                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
199                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
200                                 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
201                                 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
202                                 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2005,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
203                                 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
204                         }
205
206                         [Test]
207                         public void SupportsDaylightSavingTime_NonEmptyAdjustmentRule ()
208                         {
209                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
210                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
211                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
212                                 TimeZoneInfo tz = TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1});
213                                 Assert.IsTrue (tz.SupportsDaylightSavingTime);
214                         }
215
216                         [Test]
217                         public void SupportsDaylightSavingTime_EmptyAdjustmentRule ()
218                         {
219                                 TimeZoneInfo tz = TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,null);
220                                 Assert.IsFalse (tz.SupportsDaylightSavingTime);
221                         }
222
223                         [Test]
224                         public void SupportsDaylightSavingTime_NonEmptyAdjustmentRule_DisableDaylightSavingTime ()
225                         {
226                                 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
227                                 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
228                                 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
229                                 TimeZoneInfo tz = TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1}, true);
230                                 Assert.IsFalse (tz.SupportsDaylightSavingTime);
231                         }
232
233                         [Test]
234                         public void SupportsDaylightSavingTime_EmptyAdjustmentRule_DisableDaylightSavingTime ()
235                         {
236                                 TimeZoneInfo tz = TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,null,true);
237                                 Assert.IsFalse (tz.SupportsDaylightSavingTime);
238                         }
239                 }
240                 
241                 [TestFixture]
242                 public class IsDaylightSavingTimeTests
243                 {
244                         TimeZoneInfo london;
245                 
246                         [SetUp]
247                         public void CreateTimeZones ()
248                         {
249                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
250                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
251                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
252                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
253                         }
254                 
255                         [Test]
256                         public void NoDSTInUTC ()
257                         {
258                                 DateTime june01 = new DateTime (2007, 06, 01);
259                                 Assert.IsFalse (TimeZoneInfo.Utc.IsDaylightSavingTime (june01));
260                         }
261                 
262                         [Test]
263                         public void DSTInLondon ()
264                         {
265                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
266                                         Assert.Ignore ("Not running on Unix.");
267                                 DateTime june01 = new DateTime (2007, 06, 01);
268                                 DateTime xmas = new DateTime (2007, 12, 25);
269                                 Assert.IsTrue (london.IsDaylightSavingTime (june01), "June 01 is DST in London");
270                                 Assert.IsFalse (london.IsDaylightSavingTime (xmas), "Xmas is not DST in London");
271                         }
272                 
273                         [Test]
274                         public void DSTTransisions ()
275                         {
276                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
277                                         Assert.Ignore ("Not running on Unix.");
278                                 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Unspecified);
279                                 DateTime startDST = new DateTime (2007, 03, 25, 2, 0, 0, DateTimeKind.Unspecified);
280                                 DateTime endDST = new DateTime (2007, 10, 28, 1, 59, 59, DateTimeKind.Unspecified);
281                                 DateTime afterDST = new DateTime (2007, 10, 28, 2, 0, 0, DateTimeKind.Unspecified);
282                                 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
283                                 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
284                                 Assert.IsFalse (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
285                                 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
286                         }
287                 
288                         [Test]
289                         public void DSTTransisionsUTC ()
290                         {
291                                 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Utc);
292                                 DateTime startDST = new DateTime (2007, 03, 25, 1, 0, 0, DateTimeKind.Utc);
293                                 DateTime endDST = new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc);
294                                 DateTime afterDST = new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc);
295                                 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
296                                 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
297                                 Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
298                                 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
299                         }
300                 
301                 #if SLOW_TESTS
302                         [Test]
303                         public void MatchTimeZoneBehavior ()
304                         {
305                                 TimeZone tzone = TimeZone.CurrentTimeZone;
306                                 TimeZoneInfo local = TimeZoneInfo.Local;
307                                 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)) {
308                                         date = DateTime.SpecifyKind (date, DateTimeKind.Local);
309                                         if (local.IsInvalidTime (date))
310                                                 continue;
311                                         Assert.IsTrue (tzone.IsDaylightSavingTime (date) == local.IsDaylightSavingTime (date));
312                                 }
313                         }
314                 #endif
315                         [Test (Description="Description xambug #17155")]
316                         public void AdjustmentRuleAfterNewYears ()
317                         {
318                                 TimeZoneInfo tz;
319                                 if (Environment.OSVersion.Platform == PlatformID.Unix)
320                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("Pacific/Auckland"); // *nix
321                                 else
322                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("New Zealand Standard Time"); // Windows
323
324                                 // DST start: 9/29/2013 2:00:00 AM
325                                 // DST end: 4/6/2014 3:00:00 AM
326                                 DateTime dt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Utc);
327                                 Assert.IsTrue (tz.IsDaylightSavingTime (dt), "#1.1");
328
329                                 // DST start: 9/29/2014 2:00:00 AM
330                                 // DST end: 4/6/2015 3:00:00 AM
331                                 dt = new DateTime (2014, 6, 9, 23, 0, 0, DateTimeKind.Utc);
332                                 Assert.IsFalse (tz.IsDaylightSavingTime (dt), "#2.1");
333
334                                 // DST start: 9/29/2014 2:00:00 AM
335                                 // DST end: 4/6/2015 3:00:00 AM
336                                 dt = new DateTime (2014, 10, 9, 23, 0, 0, DateTimeKind.Utc);
337                                 Assert.IsTrue (tz.IsDaylightSavingTime (dt), "#3.1");
338                         }
339
340                         [Test] //Covers #26008
341                         public void DSTWithFloatingDateRule ()
342                         {
343                                 // Construct a custom time zone where daylight saving time starts on the
344                                 // 2nd Sunday in March.
345                                 var transitionToDaylight = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 0, 0), 3, 2, DayOfWeek.Sunday);
346                                 var transitionToStandard = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 0, 0), 11, 1, DayOfWeek.Sunday);
347                                 var adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1, 0, 0), transitionToDaylight, transitionToStandard);
348                                 var timeZone = TimeZoneInfo.CreateCustomTimeZone ("BugCheck", new TimeSpan (-8, 0, 0), "Testing", "Testing Standard", "Testing Daylight", new TimeZoneInfo.AdjustmentRule [] { adjustment });
349                                 // See if March 7, 2014 is listed as being during daylight saving time.
350                                 // If it is DST, then the runtime has the bug that we are looking for.
351                                 Assert.IsFalse (timeZone.IsDaylightSavingTime (new DateTime (2014, 3, 7, 12, 0, 0, DateTimeKind.Unspecified)));
352                         }
353
354                         [Test] //Covers #25050
355                         public void TestAthensDST ()
356                         {
357                                 TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Athens");
358                                 var date = new DateTime (2014, 3, 30 , 2, 0, 0);
359                                 Assert.IsFalse (tzi.IsDaylightSavingTime (date));
360                                 Assert.AreEqual (new TimeSpan (2,0,0), tzi.GetUtcOffset (date));
361                         }
362                 }
363                 
364                 [TestFixture]
365                 public class ConvertTimeTests_LocalUtc : ConvertTimeTests
366                 {
367                         static TimeZoneInfo oldLocal;
368
369                         [SetUp]
370                         public void SetLocal ()
371                         {
372                                 base.CreateTimeZones ();
373
374                                 oldLocal = TimeZoneInfo.Local;
375                                 TimeZoneInfoTest.SetLocal (TimeZoneInfo.Utc);
376                         }
377
378                         [TearDown]
379                         public void RestoreLocal ()
380                         {
381                                 TimeZoneInfoTest.SetLocal (oldLocal);
382                         }
383                 }
384
385                 [TestFixture]
386                 public class ConvertTimeTests
387                 {
388                         TimeZoneInfo london;
389                 
390                         [SetUp]
391                         public void CreateTimeZones ()
392                         {
393                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
394                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
395                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
396                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
397                         }
398                 
399                         [Test]
400                         [ExpectedException (typeof (ArgumentException))]
401                         public void ConvertFromUtc_KindIsLocalException ()
402                         {
403                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
404                                         throw new ArgumentException ();
405                                 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0, DateTimeKind.Local), TimeZoneInfo.Local);  
406                         }
407                 
408                         [Test]
409                         [ExpectedException (typeof (ArgumentNullException))]
410                         public void ConvertFromUtc_DestinationTimeZoneIsNullException ()
411                         {
412                                 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0), null);            
413                         }
414                 
415                         [Test]
416                         public void ConvertFromUtc_DestinationIsUTC ()
417                         {
418                                 DateTime now = DateTime.UtcNow;
419                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (now, TimeZoneInfo.Utc);
420                                 Assert.AreEqual (now, converted);
421                         }
422                         
423                         [Test]
424                         public void ConvertFromUTC_ConvertInWinter ()
425                         {
426                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
427                                         Assert.Ignore ("Not running on Unix.");
428                                 DateTime utc = new DateTime (2007, 12, 25, 12, 0, 0);
429                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
430                                 Assert.AreEqual (utc, converted);
431                         }
432                 
433                         [Test]
434                         public void ConvertFromUtc_ConvertInSummer ()
435                         {
436                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
437                                         Assert.Ignore ("Not running on Unix.");
438                                 DateTime utc = new DateTime (2007, 06, 01, 12, 0, 0);
439                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
440                                 Assert.AreEqual (utc + new TimeSpan (1,0,0), converted);
441                         }
442                 
443                         [Test]
444                         public void ConvertToUTC_KindIsUtc ()
445                         {
446                                 DateTime now = DateTime.UtcNow;
447                                 Assert.AreEqual (now.Kind, DateTimeKind.Utc);
448                                 DateTime converted = TimeZoneInfo.ConvertTimeToUtc (now);
449                                 Assert.AreEqual (now, converted);
450                         }
451                 
452                         [Test]
453                         [ExpectedException (typeof (ArgumentException))]
454                         public void ConvertToUTC_KindIsUTCButSourceIsNot ()
455                         {
456                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Utc), london);
457                         }
458                 
459                         [Test]
460                         [ExpectedException (typeof (ArgumentException))]
461                         public void ConvertToUTC_KindIsLocalButSourceIsNot ()
462                         {
463                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
464                                         throw new ArgumentException ();
465                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Local), london);        
466                         }
467                 
468                         [Test]
469                         [ExpectedException (typeof (ArgumentException))]
470                         public void ConvertToUTC_InvalidDate ()
471                         {
472                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 3, 25, 1, 30, 0), london);
473                         }
474                 
475                         [Test]
476                         [ExpectedException (typeof (ArgumentNullException))]
477                         public void ConvertToUTC_SourceIsNull ()
478                         {
479                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 16, 0), null);
480                         }
481                 
482                 #if SLOW_TESTS
483                         [Test]
484                         public void ConvertToUtc_MatchDateTimeBehavior ()
485                         {
486                                 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)) {
487                                         Assert.AreEqual (TimeZoneInfo.ConvertTimeToUtc (date), date.ToUniversalTime ());
488                                 }
489                         }
490                 #endif
491                 
492                         [Test]
493                         public void ConvertFromToUtc ()
494                         {
495                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
496                                         Assert.Ignore ("Not running on Unix.");
497                                 DateTime utc = DateTime.UtcNow;
498                                 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
499                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
500                                 Assert.AreEqual (converted.Kind, DateTimeKind.Unspecified);
501                                 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, london);
502                                 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
503                                 Assert.AreEqual (utc, back);
504                 
505                         }
506
507                         [Test]
508                         public void ConvertTimeToUtc_Overflow ()
509                         {
510                                 var res = TimeZoneInfo.ConvertTimeToUtc (new DateTime (0));
511                                 Assert.AreEqual (res.Kind, DateTimeKind.Utc, "#1");
512
513                                 res = TimeZoneInfo.ConvertTimeToUtc (DateTime.MaxValue);
514                                 Assert.AreEqual (res.Kind, DateTimeKind.Utc, "#2");
515                         }
516
517                         [Test]
518                         public void ConvertFromToUtc_Utc ()
519                         {
520                                 DateTime utc = DateTime.UtcNow;
521                                 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
522                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, TimeZoneInfo.Utc);
523                                 Assert.AreEqual (DateTimeKind.Utc, converted.Kind);
524                                 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, TimeZoneInfo.Utc);
525                                 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
526                                 Assert.AreEqual (utc, back);
527                         }
528
529                         [Test]
530                         public void ConvertFromToLocal ()
531                         {
532                                 DateTime utc = DateTime.UtcNow;
533                                 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
534                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, TimeZoneInfo.Local);
535                                 var expectedKind = (TimeZoneInfo.Local == TimeZoneInfo.Utc)? DateTimeKind.Utc : DateTimeKind.Local;
536                                 Assert.AreEqual (expectedKind, converted.Kind);
537                                 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, TimeZoneInfo.Local);
538                                 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
539                                 Assert.AreEqual (utc, back);
540                         }
541
542                         [Test]
543                         public void ConvertToTimeZone ()
544                         {
545                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
546                                         Assert.Ignore ("Not running on Unix.");
547
548                                 TimeZoneInfo.ConvertTime (DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Pacific/Auckland"));
549                         }
550
551                         [Test]
552                         [ExpectedException (typeof (ArgumentNullException))]
553                         public void ConvertTime_DateTime_TimeZoneInfo_DestinationTimeZoneIsNull ()
554                         {
555                                 TimeZoneInfo.ConvertTime (DateTime.Now, null);
556                         }
557
558                         [Test]
559                         public void ConvertTime_DateTime_TimeZoneInfo_DateTimeKindMatch ()
560                         {
561                                 var sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Utc);
562                                 var ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Utc);
563                                 Assert.AreEqual (ddt.Kind, sdt.Kind, "#1.1");
564                                 Assert.AreEqual (ddt.Kind, DateTimeKind.Utc, "#1.2");
565                                 
566                                 sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Local);
567                                 ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Local);
568                                 Assert.AreEqual (ddt.Kind, sdt.Kind, "#2.1");
569                                 Assert.AreEqual (ddt.Kind, DateTimeKind.Local, "#2.2");
570
571                                 sdt = new DateTime (2014, 1, 9, 23, 0, 0);
572                                 ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Local);
573                                 var expectedKind = (TimeZoneInfo.Local == TimeZoneInfo.Utc)? DateTimeKind.Utc : sdt.Kind;
574                                 Assert.AreEqual (expectedKind,  ddt.Kind, "#3.1");
575                                 Assert.AreEqual (DateTimeKind.Unspecified, sdt.Kind, "#3.2");
576                         }
577
578                         [Test]
579                         [ExpectedException (typeof (ArgumentNullException))]
580                         public void ConverTime_DateTime_TimeZoneInfo_TimeZoneInfo_SourceTimeZoneIsNull ()
581                         {
582                                 TimeZoneInfo.ConvertTime (DateTime.Now, null, TimeZoneInfo.Local);
583                         }
584
585                         [Test]
586                         [ExpectedException (typeof (ArgumentNullException))]
587                         public void ConverTime_DateTime_TimeZoneInfo_TimeZoneInfo_DestinationTimeZoneIsNull ()
588                         {
589                                 TimeZoneInfo.ConvertTime (DateTime.Now, TimeZoneInfo.Utc, null);
590                         }
591
592                         [Test (Description="Fix for xambug https://bugzilla.xamarin.com/show_bug.cgi?id=17155")]
593                         public void ConvertTime_AdjustmentRuleAfterNewYears ()
594                         {
595                                 TimeZoneInfo tz;
596                                 if (Environment.OSVersion.Platform == PlatformID.Unix)
597                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("Pacific/Auckland"); // *nix
598                                 else
599                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("New Zealand Standard Time"); // Windows
600
601                                 // DST start: 9/29/2013 2:00:00 AM
602                                 // DST end: 4/6/2014 3:00:00 AM
603                                 DateTime sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Utc);
604                                 DateTime ddt = TimeZoneInfo.ConvertTime (sdt, tz);
605                                 Assert.AreEqual (10, ddt.Day, "#1.1");
606                                 Assert.AreEqual (1, ddt.Month, "#1.2");
607                                 Assert.AreEqual (2014, ddt.Year, "#1.3");
608                                 Assert.AreEqual (12, ddt.Hour, "#1.4");
609                                 Assert.AreEqual (0, ddt.Minute, "#1.5");
610                                 Assert.AreEqual (0, ddt.Second, "#1.6");
611                                 
612                                 // DST start: 9/29/2014 2:00:00 AM
613                                 // DST end: 4/6/2015 3:00:00 AM
614                                 sdt = new DateTime (2014, 6, 9, 23, 0, 0, DateTimeKind.Utc);
615                                 ddt = TimeZoneInfo.ConvertTime (sdt, tz);
616                                 Assert.AreEqual (10, ddt.Day, "#2.1");
617                                 Assert.AreEqual (6, ddt.Month, "#2.2");
618                                 Assert.AreEqual (2014, ddt.Year, "#2.3");
619                                 Assert.AreEqual (11, ddt.Hour, "#2.4");
620                                 Assert.AreEqual (0, ddt.Minute, "#2.5");
621                                 Assert.AreEqual (0, ddt.Second, "#2.6");
622                                 
623                                 // DST start: 9/29/2014 2:00:00 AM
624                                 // DST end: 4/6/2015 3:00:00 AM
625                                 sdt = new DateTime (2014, 10, 9, 23, 0, 0, DateTimeKind.Utc);
626                                 ddt = TimeZoneInfo.ConvertTime (sdt, tz);
627                                 Assert.AreEqual (10, ddt.Day, "#3.1");
628                                 Assert.AreEqual (10, ddt.Month, "#3.2");
629                                 Assert.AreEqual (2014, ddt.Year, "#3.3");
630                                 Assert.AreEqual (12, ddt.Hour, "#3.4");
631                                 Assert.AreEqual (0, ddt.Minute, "#3.5");
632                                 Assert.AreEqual (0, ddt.Second, "#3.6");
633                         }
634
635                         [Test (Description="Fix the bug https://bugzilla.xamarin.com/show_bug.cgi?id=1849")]
636                         public void ConvertTime_AjustmentConvertTimeWithSourceTimeZone () {
637                                 
638                                 TimeZoneInfo easternTimeZone;
639                                 TimeZoneInfo pacificTimeZone;
640
641                                 if (Environment.OSVersion.Platform == PlatformID.Unix) {
642                                         // *nix
643                                         easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById ("US/Eastern");
644                                         pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById ("US/Pacific");   
645                                 }
646                                 else {
647                                         // Windows
648                                         easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById ("Eastern Standard Time");
649                                         pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById ("Pacific Standard Time");
650                                 }
651
652                                 DateTime lastMidnight = new DateTime (new DateTime (2012, 06, 13).Ticks, DateTimeKind.Unspecified);
653                                 DateTime lastMidnightAsEST = TimeZoneInfo.ConvertTime (lastMidnight, pacificTimeZone, easternTimeZone);
654                                 DateTime lastMidnightAsPST = TimeZoneInfo.ConvertTime (lastMidnightAsEST, easternTimeZone, pacificTimeZone);
655                         
656                                 // Last midnight in PST as EST should be 3AM
657                                 DateTime expectedDate = new DateTime (2012, 06, 13, 3, 0, 0);
658
659                                 Assert.AreEqual (expectedDate, lastMidnightAsEST);
660                                 Assert.AreEqual (lastMidnight, lastMidnightAsPST);
661                         }
662                 }
663                 
664                 [TestFixture]
665                 public class IsInvalidTimeTests
666                 {
667                         TimeZoneInfo london;
668                 
669                         [SetUp]
670                         public void CreateTimeZones ()
671                         {
672                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
673                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
674                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
675                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
676                         }
677                 
678                 #if SLOW_TESTS
679                         [Test]
680                         public void UTCDate ()
681                         {
682                                 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)) {
683                                         date = DateTime.SpecifyKind (date, DateTimeKind.Utc);
684                                         Assert.IsFalse (london.IsInvalidTime (date));
685                                 }
686                         }
687                 #endif
688                         [Test]
689                         public void InvalidDates ()
690                         {
691                                 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 0, 59, 59)));
692                                 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 0, 0)));
693                                 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 59, 59)));
694                                 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 2, 0, 0)));
695                         }
696                 }
697                 
698                 [TestFixture]
699                 public class IsAmbiguousTimeTests
700                 {
701                         TimeZoneInfo london;
702                 
703                         [SetUp]
704                         public void CreateTimeZones ()
705                         {
706                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
707                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
708                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
709                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
710                         }
711                 
712                         [Test]
713                         public void AmbiguousDates ()
714                         {
715                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
716                                         Assert.Ignore ("Not running on Unix.");
717                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0)));
718                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 1)));
719                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 0)));
720                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 1)));
721                         }
722                 
723                         [Test]
724                         public void AmbiguousUTCDates ()
725                         {
726                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
727                                         Assert.Ignore ("Not running on Unix.");
728                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 0, DateTimeKind.Utc)));
729                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 1, DateTimeKind.Utc)));
730                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc)));
731                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc)));
732                         }
733                 
734                 #if SLOW_TESTS
735                         [Test]
736                         public void AmbiguousInUTC ()
737                         {
738                                 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)) {
739                                         Assert.IsFalse (TimeZoneInfo.Utc.IsAmbiguousTime (date));
740                                 }
741                         }
742                 #endif
743                 }
744                 
745                 [TestFixture]
746                 public class GetSystemTimeZonesTests
747                 {
748                         [Test]
749                         public void Identity ()
750                         {
751                                 Assert.AreSame (TimeZoneInfo.GetSystemTimeZones (), TimeZoneInfo.GetSystemTimeZones ());
752                         }
753
754                         [Test]
755                         public void NotEmpty ()
756                         {
757                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
758                                         Assert.Ignore ("Not running on Unix.");
759                                 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
760                                 Assert.IsNotNull(systemTZ, "SystemTZ is null");
761                                 Assert.IsFalse (systemTZ.Count == 0, "SystemTZ is empty");
762                         }
763                 
764                         [Test]
765                         public void ContainsBrussels ()
766                         {
767                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
768                                         Assert.Ignore ("Not running on Unix.");
769                                 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
770                                 foreach (TimeZoneInfo tz in systemTZ) {
771                                         if (tz.Id == "Europe/Brussels")
772                                                 return;
773                                 }
774                                 Assert.Fail ("Europe/Brussels not found in SystemTZ");
775                         }
776
777                         [Test]
778                         public void ReflectionReturnsTheCorrectMethod ()
779                         {
780                                 var method = (MethodInfo) typeof (TimeZoneInfo).GetMember ("GetSystemTimeZones", MemberTypes.Method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)[0];
781
782                                 var timeZones = (global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo>) method.Invoke (null, null);
783                                 Assert.IsTrue (timeZones.Count > 0, "GetSystemTimeZones should not return an empty collection.");
784                         }
785                 }
786                 
787                 [TestFixture]
788                 public class FindSystemTimeZoneByIdTests
789                 {
790                         [Test]
791                         [ExpectedException (typeof (ArgumentNullException))]
792                         public void NullId ()
793                         {
794                                 TimeZoneInfo.FindSystemTimeZoneById (null);
795                         }
796                 
797                         [Test]
798                         [ExpectedException (typeof (TimeZoneNotFoundException))]
799                         public void NonSystemTimezone ()
800                         {
801                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
802                                         throw new TimeZoneNotFoundException ();
803                                 TimeZoneInfo.FindSystemTimeZoneById ("Neverland/The_Lagoon");
804                         }
805                 
806                         [Test]
807                         public void FindBrusselsTZ ()
808                         {
809                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
810                                         Assert.Ignore ("Not running on Unix.");
811                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
812                                 Assert.IsNotNull (brussels);
813                         }
814                 
815                         [Test]
816                         public void OffsetIsCorrectInKinshasa ()
817                         {
818                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
819                                         Assert.Ignore ("Not running on Unix.");
820                                 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
821                                 Assert.AreEqual (new TimeSpan (1,0,0), kin.BaseUtcOffset, "BaseUtcOffset in Kinshasa is not +1h");
822                         }
823                 
824                         [Test]
825                         public void OffsetIsCorrectInBrussels ()
826                         {
827                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
828                                         Assert.Ignore ("Not running on Unix.");
829                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
830                                 Assert.AreEqual (new TimeSpan (1,0,0), brussels.BaseUtcOffset, "BaseUtcOffset for Brussels is not +1h");
831                         }
832                 
833                         [Test]
834                         public void NoDSTInKinshasa ()
835                         {
836                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
837                                         Assert.Ignore ("Not running on Unix.");
838                                 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
839                                 Assert.IsFalse (kin.SupportsDaylightSavingTime);
840                         }
841                 
842                         [Test]
843                         public void BrusselsSupportsDST ()
844                         {
845                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
846                                         Assert.Ignore ("Not running on Unix.");
847                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
848                                 Assert.IsTrue (brussels.SupportsDaylightSavingTime);
849                         }
850                 
851                         [Test]
852                         public void MelbourneSupportsDST ()
853                         {
854                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
855                                         Assert.Ignore ("Not running on Unix.");
856                                 TimeZoneInfo melbourne = TimeZoneInfo.FindSystemTimeZoneById ("Australia/Melbourne");
857                                 Assert.IsTrue (melbourne.SupportsDaylightSavingTime);
858                         }
859                 
860                         [Test]
861                         public void RomeAndVaticanSharesTime ()
862                         {
863                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
864                                         Assert.Ignore ("Not running on Unix.");
865                                 TimeZoneInfo rome = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Rome");
866                                 TimeZoneInfo vatican = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Vatican");
867                                 Assert.IsTrue (rome.HasSameRules (vatican));
868                         }
869
870                         [Test]
871                         public void FindSystemTimeZoneById_Local_Roundtrip ()
872                         {
873                                 Assert.AreEqual (TimeZoneInfo.Local.Id, TimeZoneInfo.FindSystemTimeZoneById (TimeZoneInfo.Local.Id).Id);
874                         }
875
876                         [Test]
877                         public void Test326 ()
878                         {
879                                 DateTime utc = DateTime.UtcNow;
880                                 DateTime local = TimeZoneInfo.ConvertTime (utc, TimeZoneInfo.Utc, TimeZoneInfo.FindSystemTimeZoneById (TimeZoneInfo.Local.Id));
881                                 Assert.AreEqual (local, utc + TimeZoneInfo.Local.GetUtcOffset (utc), "ConvertTime/Local");
882                         }
883                 
884                 #if SLOW_TESTS
885                         [Test]
886                         public void BrusselsAdjustments ()
887                         {
888                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 3, 5, DayOfWeek.Sunday);
889                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,3,0,0), 10, 5, DayOfWeek.Sunday);
890                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
891                                 TimeZoneInfo brussels = TimeZoneInfo.CreateCustomTimeZone ("Europe/Brussels", new TimeSpan (1, 0, 0), "Europe/Brussels", "", "", new TimeZoneInfo.AdjustmentRule [] {rule});
892                 
893                                 TimeZoneInfo brussels_sys = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
894                 
895                                 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)) {
896                                         Assert.AreEqual (brussels.GetUtcOffset (date), brussels_sys.GetUtcOffset (date));
897                                         Assert.AreEqual (brussels.IsDaylightSavingTime (date), brussels_sys.IsDaylightSavingTime (date));
898                                 }               
899                         }
900                 #endif
901
902                         [Test]
903                         public void SubminuteDSTOffsets ()
904                         {
905                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
906                                         Assert.Ignore ();
907
908                                 var subMinuteDSTs = new string [] {
909                                         "Europe/Dublin", // Europe/Dublin has a DST offset of 34 minutes and 39 seconds in 1916.
910                                         "Europe/Amsterdam",
911                                         "America/St_Johns",
912                                         "Canada/Newfoundland",
913                                         "Europe/Moscow",
914                                         "Europe/Riga",
915                                         "N/A", // testing that the test doesn't fail with inexistent TZs
916                                 };
917                                 foreach (var tz in subMinuteDSTs) {
918                                         try {
919                                                 TimeZoneInfo.FindSystemTimeZoneById (tz);
920                                         } catch (TimeZoneNotFoundException) {
921                                                 // ok;
922                                         } catch (Exception ex) {
923                                                 Assert.Fail (string.Format ("Failed to load TZ {0}: {1}", tz, ex.ToString ()));
924                                         }
925                                 }
926                         }
927                 }
928                 
929                 [TestFixture]
930                 public class GetAmbiguousTimeOffsetsTests
931                 {
932                         [Test]
933                         [ExpectedException (typeof(ArgumentException))]
934                         public void DateIsNotAmbiguous ()
935                         {
936                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
937                                         throw new ArgumentException ();
938                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
939                                 DateTime date = new DateTime (2007, 05, 11, 11, 40, 00);
940                                 brussels.GetAmbiguousTimeOffsets (date);
941                         }
942                 
943                         [Test]
944                         public void AmbiguousOffsets ()
945                         {
946                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
947                                         Assert.Ignore ("Not running on Unix.");
948                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
949                                 DateTime date = new DateTime (2007, 10, 28, 2, 30, 00);
950                                 Assert.IsTrue (brussels.IsAmbiguousTime (date));
951                                 Assert.AreEqual (2, brussels.GetAmbiguousTimeOffsets (date).Length);
952                                 Assert.AreEqual (new TimeSpan[] {new TimeSpan (1, 0, 0), new TimeSpan (2, 0, 0)}, brussels.GetAmbiguousTimeOffsets (date));
953                         }
954                 }
955
956                 [TestFixture]
957                 public class HasSameRulesTests
958                 {
959                         [Test]
960                         public void NullAdjustments () //bnc #391011
961                         {
962                                 TimeZoneInfo utc = TimeZoneInfo.Utc;
963                                 TimeZoneInfo custom = TimeZoneInfo.CreateCustomTimeZone ("Custom", new TimeSpan (0), "Custom", "Custom");
964                                 Assert.IsTrue (utc.HasSameRules (custom));
965                         }
966                 }
967
968                 [TestFixture]
969                 public class SerializationTests
970                 {
971                         [Test]
972                         public void Serialization_Deserialization ()
973                         {
974                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
975                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
976                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
977                                 TimeZoneInfo london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
978                                 MemoryStream stream = new MemoryStream ();
979                                 BinaryFormatter formatter = new BinaryFormatter ();
980                                 formatter.Serialize (stream, london);
981                                 stream.Position = 0;
982                                 TimeZoneInfo deserialized = (TimeZoneInfo) formatter.Deserialize (stream);
983                                 stream.Close ();
984                                 stream.Dispose ();
985                                 Assert.IsTrue (london.Equals (deserialized));
986                         }
987                 }
988
989                 [TestFixture]
990                 public class MultipleDaylightSavingTimeTests {
991                         private TimeZoneInfo cairo;
992                         private DateTime dst1Start;
993                         private DateTime dst1End;
994                         private DateTime dst2Start;
995                         private DateTime dst2End;
996
997                         private TimeSpan baseUtcOffset;
998                         private TimeSpan dstUtcOffset;
999                         private TimeSpan dstOffset;
1000
1001                         [SetUp]
1002                         public void CreateTimeZones ()
1003                         {
1004                                 /*
1005                                 From 1/1/2014 12:00:00 AM to 6/30/2014 12:00:00 AM
1006                                         Delta: 01:00:00
1007                                         Begins at 12:00 AM on 16 May
1008                                         Ends at 1:00 AM on 29 June
1009                                 From 7/1/2014 12:00:00 AM to 12/31/2014 12:00:00 AM
1010                                         Delta: 01:00:00
1011                                         Begins at 12:00 AM on 29 July
1012                                         Ends at 12:00 AM on 26 September
1013                                 */
1014                                 dst1Start = new DateTime (2014, 5, 16);
1015                                 dst1End = new DateTime (2014, 6, 29);
1016                                 dst2Start = new DateTime (2014, 7, 29);
1017                                 dst2End = new DateTime (2014, 9, 26);
1018
1019                                 baseUtcOffset = new TimeSpan (2, 0, 0);
1020                                 dstUtcOffset = new TimeSpan (3, 0, 0);
1021                                 dstOffset = dstUtcOffset - baseUtcOffset;
1022
1023                                 var rule1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (
1024                                         new DateTime (2014, 1, 1), new DateTime (2014, 6, 30), dstOffset,
1025                                         CreateFixedDateRule (dst1Start), CreateFixedDateRule (dst1End));
1026
1027                                 var rule2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (
1028                                         new DateTime (2014, 7, 1), new DateTime (2014, 12, 31), dstOffset,
1029                                         CreateFixedDateRule (dst2Start), CreateFixedDateRule (dst2End));
1030
1031                                 cairo = TimeZoneInfo.CreateCustomTimeZone ("Africa/Cairo", baseUtcOffset, "Africa/Cairo", "EET", "EEST",
1032                                         new [] {rule1, rule2});
1033                         }
1034
1035                         private static TimeZoneInfo.TransitionTime CreateFixedDateRule (DateTime dateTime)
1036                         {
1037                                 var time = new DateTime (dateTime.Ticks - dateTime.Date.Ticks);
1038                                 return TimeZoneInfo.TransitionTime.CreateFixedDateRule (time, dateTime.Month, dateTime.Day);
1039                         }
1040
1041                         [Test]
1042                         public void GetUtcOffset_FromUTC ()
1043                         {
1044                                 var d = dst1Start.Add (-baseUtcOffset);
1045                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1046                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1047                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1048                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1049
1050                                 d = dst1End.Add (-baseUtcOffset-dstOffset);
1051                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1052                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1053                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1054                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1055
1056                                 d = dst2Start.Add (-baseUtcOffset);
1057                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1058                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1059                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1060                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1061
1062                                 d = dst2End.Add (-baseUtcOffset-dstOffset);
1063                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1064                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1065                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1066                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1067                         }
1068
1069                         [Test]
1070                         public void GetUtcOffset_FromLocal ()
1071                         {
1072                                 var d = dst1Start.Add (-baseUtcOffset);
1073                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1074                                 d = d.ToLocalTime ();
1075                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1076                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1077                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1078
1079                                 d = dst1End.Add (-baseUtcOffset-dstOffset);
1080                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1081                                 d = d.ToLocalTime ();
1082                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1083                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1084                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1085
1086                                 d = dst2Start.Add (-baseUtcOffset);
1087                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1088                                 d = d.ToLocalTime ();
1089                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1090                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1091                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1092
1093                                 d = dst2End.Add (-baseUtcOffset-dstOffset);
1094                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1095                                 d = d.ToLocalTime ();
1096                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1097                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1098                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1099                         }
1100
1101                         [Test]
1102                         public void GetUtcOffset_FromUnspecified ()
1103                         {
1104                                 var d = dst1Start.Add (dstOffset);
1105                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1106                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1107                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1108
1109                                 d = dst1End.Add (-dstOffset);
1110                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1111                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1112                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1113
1114                                 d = dst2Start.Add (dstOffset);
1115                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1116                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1117                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1118
1119                                 d = dst2End.Add (-dstOffset);
1120                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1121                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1122                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1123                         }
1124
1125                   [Test]
1126                   public void  GetUtcOffset_FromDateTimeOffset ()
1127                   {
1128                           DateTimeOffset offset;
1129
1130                           offset = new DateTimeOffset(dst1Start, baseUtcOffset);
1131                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst1Start_with_baseUtcOffset#before");
1132                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset), "dst1Start_with_baseUtcOffset#exact");
1133                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst1Start_with_baseUtcOffset#after");
1134
1135                           offset = new DateTimeOffset(dst1End, dstOffset + baseUtcOffset);
1136                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst1End_with_dstOffset+baseUtcOffset#before");
1137                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset), "dst1End_with_dstOffset+baseUtcOffset#exact");
1138                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst1End_with_dstOffset+baseUtcOffset#after");
1139
1140                           offset = new DateTimeOffset(dst2Start, baseUtcOffset);
1141                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst2Start_with_baseUtcOffset#before");
1142                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset), "dst2Start_with_baseUtcOffset#exact");
1143                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst2Start_with_baseUtcOffset#after");
1144
1145                           offset = new DateTimeOffset(dst2End, baseUtcOffset + dstOffset);
1146                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst2End_with_dstOffset+baseUtcOffset#before");
1147                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset), "dst2End_with_dstOffset+baseUtcOffset#exact");
1148                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst2End_with_dstOffset+baseUtcOffset#after");
1149                   }
1150     }
1151
1152                 [TestFixture]
1153                 public class GetDaylightChanges
1154                 {
1155                         MethodInfo getChanges;
1156
1157                         [SetUp]
1158                         public void Setup ()
1159                         {
1160                                 var flags = BindingFlags.Instance | BindingFlags.NonPublic;
1161                                 getChanges = typeof (TimeZoneInfo).GetMethod ("GetDaylightChanges", flags);
1162                         }
1163
1164                         [Test]
1165                         public void TestSydneyDaylightChanges ()
1166                         {
1167                                 TimeZoneInfo tz;
1168                                 if (Environment.OSVersion.Platform == PlatformID.Unix)
1169                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("Australia/Sydney");
1170                                 else
1171                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("W. Australia Standard Time");
1172
1173                                 var changes = (DaylightTime) getChanges.Invoke (tz, new object [] {2014});
1174
1175                                 Assert.AreEqual (new TimeSpan (1, 0, 0), changes.Delta);
1176                                 Assert.AreEqual (new DateTime (2014, 10, 5, 2, 0, 0), changes.Start);
1177                                 Assert.AreEqual (new DateTime (2014, 4, 6, 3, 0, 0), changes.End);
1178                         }
1179
1180                         [Test]
1181                         public void AllTimeZonesDaylightChanges ()
1182                         {
1183                                 foreach (var tz in TimeZoneInfo.GetSystemTimeZones ()) {
1184                                         try {
1185                                                 for (var year = 1950; year <= 2051; year++)
1186                                                         getChanges.Invoke (tz, new object [] {year} );
1187                                         } catch (Exception e) {
1188                                                 Assert.Fail ("TimeZone " + tz.Id + " exception: " + e.ToString ()); 
1189                                         }
1190                                 }
1191                         }
1192                 }
1193
1194                 [TestFixture]
1195                 public class ParseTZBuffer
1196                 {
1197                         MethodInfo parseTZBuffer;
1198
1199                         [SetUp]
1200                         public void Setup()
1201                         {
1202                                 var flags = BindingFlags.Static | BindingFlags.NonPublic;
1203                                 parseTZBuffer = typeof (TimeZoneInfo).GetMethod ("ParseTZBuffer", flags);
1204                         }
1205
1206                         [Test]
1207                         public void Bug31432 ()
1208                         {
1209                                 // Europe/Moscow from failing device
1210                                 var base64Data = "VFppZjIAAAAAAAAAAAAAAAAAAAAAAAAPAAAADwAAAAAAAABNAAAADwAAACKbXx7HnT7yeZ4q7vme9zlpn4RX+aDYbOmhABYJoTymQKQQbcCkPTKwpRVosKU9A8CnHkVQtaQZYBUnp9AWGNxAFwjbUBf6D8AY6g7QGdtDQBrMk9AbvKDwHKyR8B2cgvAejHPwH3xk8CBsVfAhXEbwIkw38CM8KPAkLBnwJRwK8CYL+/AnBSdwJ/UYcCjlF4ApeL+AKdTQQCrEszArtNxwLKTNcC2UvnAuhK9wL3SgcDBkkXAxXbzwMnKX8DM9nvA0UnnwNR2A8DYyW/A2/WLwOBt4cDjdRPA5+1pwOr0m8DvbPHA8pkNwPbsecD6GJXA/mwBwQGYHcEGEHPBCRelwQ2P+8EQly3BFQ+DwRgWtcEcjwvBH7snwSQOk8EnOq/BK44bwS66N8EzMo3BNjm/wVEwdYAIBAgMBAwUEBQYFBwgHCQcJBwkHCQoLCgsKCwoLCgsKCwoMDQoJBwsKCwoLCgsKCwoLCgsKCwoLCgsKCwoLCgsKCwoLCgsKCwoLCg4KAAAjOQAAAAAxhwEEAAAjdwAAAAA/lwEIAAAqMAADAAA4QAENAABGUAEPAAAqMAARAAAcIAAVAAA4QAEZAAAqMAARAAA4QAEZAAAqMAEdAAAcIAAVAAA4QAARTU1UAE1TVABNRFNUAFMATQBNU0sARUVUAE1TRABFRVNUAAAAAAAAAAAAAAABAQEBAQAAAAAAAAAAAAAAAAAAAFRaaWYyAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAATgAAABAAAAAm/////1a2wMf/////m18ex/////+dPvJ5/////54q7vn/////nvc5af////+fhFf5/////6DYbOn/////oQAWCf////+hPKZA/////6QQbcD/////pD0ysP////+lFWiw/////6U9A8D/////px5FUP////+1pBlgAAAAABUnp9AAAAAAFhjcQAAAAAAXCNtQAAAAABf6D8AAAAAAGOoO0AAAAAAZ20NAAAAAABrMk9AAAAAAG7yg8AAAAAAcrJHwAAAAAB2cgvAAAAAAHoxz8AAAAAAffGTwAAAAACBsVfAAAAAAIVxG8AAAAAAiTDfwAAAAACM8KPAAAAAAJCwZ8AAAAAAlHArwAAAAACYL+/AAAAAAJwUncAAAAAAn9RhwAAAAACjlF4AAAAAAKXi/gAAAAAAp1NBAAAAAACrEszAAAAAAK7TccAAAAAAspM1wAAAAAC2UvnAAAAAALoSvcAAAAAAvdKBwAAAAADBkkXAAAAAAMV288AAAAAAycpfwAAAAADM9nvAAAAAANFJ58AAAAAA1HYDwAAAAADYyW/AAAAAANv1i8AAAAAA4G3hwAAAAADjdRPAAAAAAOftacAAAAAA6vSbwAAAAADvbPHAAAAAAPKZDcAAAAAA9ux5wAAAAAD6GJXAAAAAAP5sAcAAAAABAZgdwAAAAAEGEHPAAAAAAQkXpcAAAAABDY/7wAAAAAEQly3AAAAAARUPg8AAAAABGBa1wAAAAAEcjwvAAAAAAR+7J8AAAAABJA6TwAAAAAEnOq/AAAAAASuOG8AAAAABLro3wAAAAAEzMo3AAAAAATY5v8AAAAABUTB1gAQMCAwQCBAYFBgcGCAkICggKCAoICgsMCwwLDAsMCwwLDAsNDgsKCAwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCw8LAAAjOQAAAAAjOQAEAAAxhwEIAAAjdwAEAAA/lwEMAAAqMAADAAA4QAERAABGUAETAAAqMAAVAAAcIAAZAAA4QAEdAAAqMAAVAAA4QAEdAAAqMAEhAAAcIAAZAAA4QAAVTE1UAE1NVABNU1QATURTVABTAE0ATVNLAEVFVABNU0QARUVTVAAAAAAAAAAAAAAAAAEBAQEBAAAAAAAAAAAAAAAAAAAAAApNU0stMwo=";
1211
1212                                 var data = Convert.FromBase64String (base64Data);
1213
1214                                 var tz = parseTZBuffer.Invoke (null, new object[] { "Test", data, data.Length});
1215                                 Assert.IsTrue (tz != null);
1216                         }
1217                 }
1218         }
1219 }