5e3811bca0019d8a6964049b9387ea5943157eff
[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                         [Test] //Covers #41349
364                         public void TestIsDST_DateTimeOffset ()
365                         {
366                                 TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Athens");
367                                 var date = new DateTime (2014, 3, 30 , 2, 0, 0);
368                                 var offset = tzi.GetUtcOffset (date);
369                                 var dateOffset = new DateTimeOffset (date, offset);
370                                 Assert.IsFalse (tzi.IsDaylightSavingTime (dateOffset));
371
372                                 date = new DateTime (2014, 3, 30 , 3, 0, 0);
373                                 offset = tzi.GetUtcOffset (date);
374                                 dateOffset = new DateTimeOffset (date, offset);
375                                 Assert.IsTrue (tzi.IsDaylightSavingTime (dateOffset));
376                         }
377                 }
378                 
379                 [TestFixture]
380                 public class ConvertTimeTests_LocalUtc : ConvertTimeTests
381                 {
382                         static TimeZoneInfo oldLocal;
383
384                         [SetUp]
385                         public void SetLocal ()
386                         {
387                                 base.CreateTimeZones ();
388
389                                 oldLocal = TimeZoneInfo.Local;
390                                 TimeZoneInfoTest.SetLocal (TimeZoneInfo.Utc);
391                         }
392
393                         [TearDown]
394                         public void RestoreLocal ()
395                         {
396                                 TimeZoneInfoTest.SetLocal (oldLocal);
397                         }
398                 }
399
400                 [TestFixture]
401                 public class ConvertTimeTests
402                 {
403                         TimeZoneInfo london;
404                 
405                         [SetUp]
406                         public void CreateTimeZones ()
407                         {
408                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
409                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
410                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
411                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
412                         }
413                 
414                         [Test]
415                         [ExpectedException (typeof (ArgumentException))]
416                         public void ConvertFromUtc_KindIsLocalException ()
417                         {
418                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
419                                         throw new ArgumentException ();
420                                 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0, DateTimeKind.Local), TimeZoneInfo.Local);  
421                         }
422                 
423                         [Test]
424                         [ExpectedException (typeof (ArgumentNullException))]
425                         public void ConvertFromUtc_DestinationTimeZoneIsNullException ()
426                         {
427                                 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0), null);            
428                         }
429                 
430                         [Test]
431                         public void ConvertFromUtc_DestinationIsUTC ()
432                         {
433                                 DateTime now = DateTime.UtcNow;
434                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (now, TimeZoneInfo.Utc);
435                                 Assert.AreEqual (now, converted);
436                         }
437                         
438                         [Test]
439                         public void ConvertFromUTC_ConvertInWinter ()
440                         {
441                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
442                                         Assert.Ignore ("Not running on Unix.");
443                                 DateTime utc = new DateTime (2007, 12, 25, 12, 0, 0);
444                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
445                                 Assert.AreEqual (utc, converted);
446                         }
447                 
448                         [Test]
449                         public void ConvertFromUtc_ConvertInSummer ()
450                         {
451                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
452                                         Assert.Ignore ("Not running on Unix.");
453                                 DateTime utc = new DateTime (2007, 06, 01, 12, 0, 0);
454                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
455                                 Assert.AreEqual (utc + new TimeSpan (1,0,0), converted);
456                         }
457                 
458                         [Test]
459                         public void ConvertToUTC_KindIsUtc ()
460                         {
461                                 DateTime now = DateTime.UtcNow;
462                                 Assert.AreEqual (now.Kind, DateTimeKind.Utc);
463                                 DateTime converted = TimeZoneInfo.ConvertTimeToUtc (now);
464                                 Assert.AreEqual (now, converted);
465                         }
466                 
467                         [Test]
468                         [ExpectedException (typeof (ArgumentException))]
469                         public void ConvertToUTC_KindIsUTCButSourceIsNot ()
470                         {
471                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Utc), london);
472                         }
473                 
474                         [Test]
475                         [ExpectedException (typeof (ArgumentException))]
476                         public void ConvertToUTC_KindIsLocalButSourceIsNot ()
477                         {
478                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
479                                         throw new ArgumentException ();
480                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Local), london);        
481                         }
482                 
483                         [Test]
484                         [ExpectedException (typeof (ArgumentException))]
485                         public void ConvertToUTC_InvalidDate ()
486                         {
487                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 3, 25, 1, 30, 0), london);
488                         }
489                 
490                         [Test]
491                         [ExpectedException (typeof (ArgumentNullException))]
492                         public void ConvertToUTC_SourceIsNull ()
493                         {
494                                 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 16, 0), null);
495                         }
496                 
497                 #if SLOW_TESTS
498                         [Test]
499                         public void ConvertToUtc_MatchDateTimeBehavior ()
500                         {
501                                 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)) {
502                                         Assert.AreEqual (TimeZoneInfo.ConvertTimeToUtc (date), date.ToUniversalTime ());
503                                 }
504                         }
505                 #endif
506                 
507                         [Test]
508                         public void ConvertFromToUtc ()
509                         {
510                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
511                                         Assert.Ignore ("Not running on Unix.");
512                                 DateTime utc = DateTime.UtcNow;
513                                 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
514                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
515                                 Assert.AreEqual (converted.Kind, DateTimeKind.Unspecified);
516                                 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, london);
517                                 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
518                                 Assert.AreEqual (utc, back);
519                 
520                         }
521
522                         [Test]
523                         public void ConvertTimeToUtc_Overflow ()
524                         {
525                                 var res = TimeZoneInfo.ConvertTimeToUtc (new DateTime (0));
526                                 Assert.AreEqual (res.Kind, DateTimeKind.Utc, "#1");
527
528                                 res = TimeZoneInfo.ConvertTimeToUtc (DateTime.MaxValue);
529                                 Assert.AreEqual (res.Kind, DateTimeKind.Utc, "#2");
530                         }
531
532                         [Test]
533                         public void ConvertFromToUtc_Utc ()
534                         {
535                                 DateTime utc = DateTime.UtcNow;
536                                 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
537                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, TimeZoneInfo.Utc);
538                                 Assert.AreEqual (DateTimeKind.Utc, converted.Kind);
539                                 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, TimeZoneInfo.Utc);
540                                 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
541                                 Assert.AreEqual (utc, back);
542                         }
543
544                         [Test]
545                         public void ConvertFromToLocal ()
546                         {
547                                 DateTime utc = DateTime.UtcNow;
548                                 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
549                                 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, TimeZoneInfo.Local);
550                                 var expectedKind = (TimeZoneInfo.Local == TimeZoneInfo.Utc)? DateTimeKind.Utc : DateTimeKind.Local;
551                                 Assert.AreEqual (expectedKind, converted.Kind);
552                                 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, TimeZoneInfo.Local);
553                                 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
554                                 Assert.AreEqual (utc, back);
555                         }
556
557                         [Test]
558                         public void ConvertToTimeZone ()
559                         {
560                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
561                                         Assert.Ignore ("Not running on Unix.");
562
563                                 TimeZoneInfo.ConvertTime (DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Pacific/Auckland"));
564                         }
565
566                         [Test]
567                         [ExpectedException (typeof (ArgumentNullException))]
568                         public void ConvertTime_DateTime_TimeZoneInfo_DestinationTimeZoneIsNull ()
569                         {
570                                 TimeZoneInfo.ConvertTime (DateTime.Now, null);
571                         }
572
573                         [Test]
574                         public void ConvertTime_DateTime_TimeZoneInfo_DateTimeKindMatch ()
575                         {
576                                 var sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Utc);
577                                 var ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Utc);
578                                 Assert.AreEqual (ddt.Kind, sdt.Kind, "#1.1");
579                                 Assert.AreEqual (ddt.Kind, DateTimeKind.Utc, "#1.2");
580                                 
581                                 sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Local);
582                                 ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Local);
583                                 Assert.AreEqual (ddt.Kind, sdt.Kind, "#2.1");
584                                 Assert.AreEqual (ddt.Kind, DateTimeKind.Local, "#2.2");
585
586                                 sdt = new DateTime (2014, 1, 9, 23, 0, 0);
587                                 ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Local);
588                                 var expectedKind = (TimeZoneInfo.Local == TimeZoneInfo.Utc)? DateTimeKind.Utc : sdt.Kind;
589                                 Assert.AreEqual (expectedKind,  ddt.Kind, "#3.1");
590                                 Assert.AreEqual (DateTimeKind.Unspecified, sdt.Kind, "#3.2");
591                         }
592
593                         [Test]
594                         [ExpectedException (typeof (ArgumentNullException))]
595                         public void ConverTime_DateTime_TimeZoneInfo_TimeZoneInfo_SourceTimeZoneIsNull ()
596                         {
597                                 TimeZoneInfo.ConvertTime (DateTime.Now, null, TimeZoneInfo.Local);
598                         }
599
600                         [Test]
601                         [ExpectedException (typeof (ArgumentNullException))]
602                         public void ConverTime_DateTime_TimeZoneInfo_TimeZoneInfo_DestinationTimeZoneIsNull ()
603                         {
604                                 TimeZoneInfo.ConvertTime (DateTime.Now, TimeZoneInfo.Utc, null);
605                         }
606
607                         [Test (Description="Fix for xambug https://bugzilla.xamarin.com/show_bug.cgi?id=17155")]
608                         public void ConvertTime_AdjustmentRuleAfterNewYears ()
609                         {
610                                 TimeZoneInfo tz;
611                                 if (Environment.OSVersion.Platform == PlatformID.Unix)
612                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("Pacific/Auckland"); // *nix
613                                 else
614                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("New Zealand Standard Time"); // Windows
615
616                                 // DST start: 9/29/2013 2:00:00 AM
617                                 // DST end: 4/6/2014 3:00:00 AM
618                                 DateTime sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Utc);
619                                 DateTime ddt = TimeZoneInfo.ConvertTime (sdt, tz);
620                                 Assert.AreEqual (10, ddt.Day, "#1.1");
621                                 Assert.AreEqual (1, ddt.Month, "#1.2");
622                                 Assert.AreEqual (2014, ddt.Year, "#1.3");
623                                 Assert.AreEqual (12, ddt.Hour, "#1.4");
624                                 Assert.AreEqual (0, ddt.Minute, "#1.5");
625                                 Assert.AreEqual (0, ddt.Second, "#1.6");
626                                 
627                                 // DST start: 9/29/2014 2:00:00 AM
628                                 // DST end: 4/6/2015 3:00:00 AM
629                                 sdt = new DateTime (2014, 6, 9, 23, 0, 0, DateTimeKind.Utc);
630                                 ddt = TimeZoneInfo.ConvertTime (sdt, tz);
631                                 Assert.AreEqual (10, ddt.Day, "#2.1");
632                                 Assert.AreEqual (6, ddt.Month, "#2.2");
633                                 Assert.AreEqual (2014, ddt.Year, "#2.3");
634                                 Assert.AreEqual (11, ddt.Hour, "#2.4");
635                                 Assert.AreEqual (0, ddt.Minute, "#2.5");
636                                 Assert.AreEqual (0, ddt.Second, "#2.6");
637                                 
638                                 // DST start: 9/29/2014 2:00:00 AM
639                                 // DST end: 4/6/2015 3:00:00 AM
640                                 sdt = new DateTime (2014, 10, 9, 23, 0, 0, DateTimeKind.Utc);
641                                 ddt = TimeZoneInfo.ConvertTime (sdt, tz);
642                                 Assert.AreEqual (10, ddt.Day, "#3.1");
643                                 Assert.AreEqual (10, ddt.Month, "#3.2");
644                                 Assert.AreEqual (2014, ddt.Year, "#3.3");
645                                 Assert.AreEqual (12, ddt.Hour, "#3.4");
646                                 Assert.AreEqual (0, ddt.Minute, "#3.5");
647                                 Assert.AreEqual (0, ddt.Second, "#3.6");
648                         }
649
650                         [Test (Description="Fix the bug https://bugzilla.xamarin.com/show_bug.cgi?id=1849")]
651                         public void ConvertTime_AjustmentConvertTimeWithSourceTimeZone () {
652                                 
653                                 TimeZoneInfo easternTimeZone;
654                                 TimeZoneInfo pacificTimeZone;
655
656                                 if (Environment.OSVersion.Platform == PlatformID.Unix) {
657                                         // *nix
658                                         easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById ("US/Eastern");
659                                         pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById ("US/Pacific");   
660                                 }
661                                 else {
662                                         // Windows
663                                         easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById ("Eastern Standard Time");
664                                         pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById ("Pacific Standard Time");
665                                 }
666
667                                 DateTime lastMidnight = new DateTime (new DateTime (2012, 06, 13).Ticks, DateTimeKind.Unspecified);
668                                 DateTime lastMidnightAsEST = TimeZoneInfo.ConvertTime (lastMidnight, pacificTimeZone, easternTimeZone);
669                                 DateTime lastMidnightAsPST = TimeZoneInfo.ConvertTime (lastMidnightAsEST, easternTimeZone, pacificTimeZone);
670                         
671                                 // Last midnight in PST as EST should be 3AM
672                                 DateTime expectedDate = new DateTime (2012, 06, 13, 3, 0, 0);
673
674                                 Assert.AreEqual (expectedDate, lastMidnightAsEST);
675                                 Assert.AreEqual (lastMidnight, lastMidnightAsPST);
676                         }
677
678                         [Test]
679                         public void ConvertTimeBySystemTimeZoneId_UtcId ()
680                         {
681                                 DateTime localTime = TimeZoneInfo.ConvertTime (DateTime.UtcNow, TimeZoneInfo.Utc, TimeZoneInfo.Local);
682
683                                 TimeZoneInfo.ConvertTimeBySystemTimeZoneId (DateTime.UtcNow, TimeZoneInfo.Utc.Id, TimeZoneInfo.Local.Id);
684                         }
685                 }
686                 
687                 [TestFixture]
688                 public class IsInvalidTimeTests
689                 {
690                         TimeZoneInfo london;
691                 
692                         [SetUp]
693                         public void CreateTimeZones ()
694                         {
695                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
696                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
697                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
698                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
699                         }
700                 
701                 #if SLOW_TESTS
702                         [Test]
703                         public void UTCDate ()
704                         {
705                                 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)) {
706                                         date = DateTime.SpecifyKind (date, DateTimeKind.Utc);
707                                         Assert.IsFalse (london.IsInvalidTime (date));
708                                 }
709                         }
710                 #endif
711                         [Test]
712                         public void InvalidDates ()
713                         {
714                                 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 0, 59, 59)));
715                                 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 0, 0)));
716                                 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 59, 59)));
717                                 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 2, 0, 0)));
718                         }
719                 }
720                 
721                 [TestFixture]
722                 public class IsAmbiguousTimeTests
723                 {
724                         TimeZoneInfo london;
725                 
726                         [SetUp]
727                         public void CreateTimeZones ()
728                         {
729                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
730                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
731                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
732                                 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
733                         }
734                 
735                         [Test]
736                         public void AmbiguousDates ()
737                         {
738                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
739                                         Assert.Ignore ("Not running on Unix.");
740                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0)));
741                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 1)));
742                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 0)));
743                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 1)));
744                         }
745                 
746                         [Test]
747                         public void AmbiguousUTCDates ()
748                         {
749                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
750                                         Assert.Ignore ("Not running on Unix.");
751                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 0, DateTimeKind.Utc)));
752                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 1, DateTimeKind.Utc)));
753                                 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc)));
754                                 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc)));
755                         }
756                 
757                 #if SLOW_TESTS
758                         [Test]
759                         public void AmbiguousInUTC ()
760                         {
761                                 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)) {
762                                         Assert.IsFalse (TimeZoneInfo.Utc.IsAmbiguousTime (date));
763                                 }
764                         }
765                 #endif
766                 }
767                 
768                 [TestFixture]
769                 public class GetSystemTimeZonesTests
770                 {
771                         [Test]
772                         public void Identity ()
773                         {
774                                 Assert.AreSame (TimeZoneInfo.GetSystemTimeZones (), TimeZoneInfo.GetSystemTimeZones ());
775                         }
776
777                         [Test]
778                         public void NotEmpty ()
779                         {
780                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
781                                         Assert.Ignore ("Not running on Unix.");
782                                 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
783                                 Assert.IsNotNull(systemTZ, "SystemTZ is null");
784                                 Assert.IsFalse (systemTZ.Count == 0, "SystemTZ is empty");
785                         }
786                 
787                         [Test]
788                         public void ContainsBrussels ()
789                         {
790                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
791                                         Assert.Ignore ("Not running on Unix.");
792                                 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
793                                 foreach (TimeZoneInfo tz in systemTZ) {
794                                         if (tz.Id == "Europe/Brussels")
795                                                 return;
796                                 }
797                                 Assert.Fail ("Europe/Brussels not found in SystemTZ");
798                         }
799
800                         [Test]
801                         public void ReflectionReturnsTheCorrectMethod ()
802                         {
803                                 var method = (MethodInfo) typeof (TimeZoneInfo).GetMember ("GetSystemTimeZones", MemberTypes.Method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)[0];
804
805                                 var timeZones = (global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo>) method.Invoke (null, null);
806                                 Assert.IsTrue (timeZones.Count > 0, "GetSystemTimeZones should not return an empty collection.");
807                         }
808
809 #if !MOBILE
810                         [Test]
811                         public void WindowsRegistryTimezoneWithParentheses ()
812                         {
813                                 var method = (MethodInfo) typeof (TimeZoneInfo).GetMember ("TrimSpecial", MemberTypes.Method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)[0];
814
815                                 var name = method.Invoke (null, new object [] { " <--->  Central Standard Time (Mexico)   ||<<>>" });
816                                 Assert.AreEqual (name, "Central Standard Time (Mexico)", "#1");
817                         }
818 #endif
819                 }
820                 
821                 [TestFixture]
822                 public class FindSystemTimeZoneByIdTests
823                 {
824                         [Test]
825                         [ExpectedException (typeof (ArgumentNullException))]
826                         public void NullId ()
827                         {
828                                 TimeZoneInfo.FindSystemTimeZoneById (null);
829                         }
830                 
831                         [Test]
832                         [ExpectedException (typeof (TimeZoneNotFoundException))]
833                         public void NonSystemTimezone ()
834                         {
835                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
836                                         throw new TimeZoneNotFoundException ();
837                                 TimeZoneInfo.FindSystemTimeZoneById ("Neverland/The_Lagoon");
838                         }
839                 
840                         [Test]
841                         public void FindBrusselsTZ ()
842                         {
843                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
844                                         Assert.Ignore ("Not running on Unix.");
845                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
846                                 Assert.IsNotNull (brussels);
847                         }
848                 
849                         [Test]
850                         public void OffsetIsCorrectInKinshasa ()
851                         {
852                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
853                                         Assert.Ignore ("Not running on Unix.");
854                                 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
855                                 Assert.AreEqual (new TimeSpan (1,0,0), kin.BaseUtcOffset, "BaseUtcOffset in Kinshasa is not +1h");
856                         }
857                 
858                         [Test]
859                         public void OffsetIsCorrectInBrussels ()
860                         {
861                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
862                                         Assert.Ignore ("Not running on Unix.");
863                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
864                                 Assert.AreEqual (new TimeSpan (1,0,0), brussels.BaseUtcOffset, "BaseUtcOffset for Brussels is not +1h");
865                         }
866                 
867                         [Test]
868                         public void NoDSTInKinshasa ()
869                         {
870                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
871                                         Assert.Ignore ("Not running on Unix.");
872                                 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
873                                 Assert.IsFalse (kin.SupportsDaylightSavingTime);
874                         }
875                 
876                         [Test]
877                         public void BrusselsSupportsDST ()
878                         {
879                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
880                                         Assert.Ignore ("Not running on Unix.");
881                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
882                                 Assert.IsTrue (brussels.SupportsDaylightSavingTime);
883                         }
884                 
885                         [Test]
886                         public void MelbourneSupportsDST ()
887                         {
888                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
889                                         Assert.Ignore ("Not running on Unix.");
890                                 TimeZoneInfo melbourne = TimeZoneInfo.FindSystemTimeZoneById ("Australia/Melbourne");
891                                 Assert.IsTrue (melbourne.SupportsDaylightSavingTime);
892                         }
893                 
894                         [Test]
895                         public void RomeAndVaticanSharesTime ()
896                         {
897                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
898                                         Assert.Ignore ("Not running on Unix.");
899                                 TimeZoneInfo rome = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Rome");
900                                 TimeZoneInfo vatican = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Vatican");
901                                 Assert.IsTrue (rome.HasSameRules (vatican));
902                         }
903
904                         [Test]
905                         public void FindSystemTimeZoneById_Local_Roundtrip ()
906                         {
907                                 Assert.AreEqual (TimeZoneInfo.Local.Id, TimeZoneInfo.FindSystemTimeZoneById (TimeZoneInfo.Local.Id).Id);
908                         }
909
910                         [Test]
911                         public void Test326 ()
912                         {
913                                 DateTime utc = DateTime.UtcNow;
914                                 DateTime local = TimeZoneInfo.ConvertTime (utc, TimeZoneInfo.Utc, TimeZoneInfo.FindSystemTimeZoneById (TimeZoneInfo.Local.Id));
915                                 Assert.AreEqual (local, utc + TimeZoneInfo.Local.GetUtcOffset (utc), "ConvertTime/Local");
916                         }
917                 
918                 #if SLOW_TESTS
919                         [Test]
920                         public void BrusselsAdjustments ()
921                         {
922                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 3, 5, DayOfWeek.Sunday);
923                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,3,0,0), 10, 5, DayOfWeek.Sunday);
924                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
925                                 TimeZoneInfo brussels = TimeZoneInfo.CreateCustomTimeZone ("Europe/Brussels", new TimeSpan (1, 0, 0), "Europe/Brussels", "", "", new TimeZoneInfo.AdjustmentRule [] {rule});
926                 
927                                 TimeZoneInfo brussels_sys = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
928                 
929                                 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)) {
930                                         Assert.AreEqual (brussels.GetUtcOffset (date), brussels_sys.GetUtcOffset (date));
931                                         Assert.AreEqual (brussels.IsDaylightSavingTime (date), brussels_sys.IsDaylightSavingTime (date));
932                                 }               
933                         }
934                 #endif
935
936                         [Test]
937                         public void SubminuteDSTOffsets ()
938                         {
939                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
940                                         Assert.Ignore ();
941
942                                 var subMinuteDSTs = new string [] {
943                                         "Europe/Dublin", // Europe/Dublin has a DST offset of 34 minutes and 39 seconds in 1916.
944                                         "Europe/Amsterdam",
945                                         "America/St_Johns",
946                                         "Canada/Newfoundland",
947                                         "Europe/Moscow",
948                                         "Europe/Riga",
949                                 };
950                                 foreach (var tz in subMinuteDSTs) {
951                                         TimeZoneInfo.FindSystemTimeZoneById (tz);
952                                 }
953                         }
954
955                         [Test]
956                         [ExpectedException (typeof (TimeZoneNotFoundException))]
957                         public void InvalidName ()
958                         {
959                                 TimeZoneInfo.FindSystemTimeZoneById ("N/A");
960                         }
961                 }
962                 
963                 [TestFixture]
964                 public class GetAmbiguousTimeOffsetsTests
965                 {
966                         [Test]
967                         [ExpectedException (typeof(ArgumentException))]
968                         public void DateIsNotAmbiguous ()
969                         {
970                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
971                                         throw new ArgumentException ();
972                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
973                                 DateTime date = new DateTime (2007, 05, 11, 11, 40, 00);
974                                 brussels.GetAmbiguousTimeOffsets (date);
975                         }
976                 
977                         [Test]
978                         public void AmbiguousOffsets ()
979                         {
980                                 if (Environment.OSVersion.Platform != PlatformID.Unix)
981                                         Assert.Ignore ("Not running on Unix.");
982                                 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
983                                 DateTime date = new DateTime (2007, 10, 28, 2, 30, 00);
984                                 Assert.IsTrue (brussels.IsAmbiguousTime (date));
985                                 Assert.AreEqual (2, brussels.GetAmbiguousTimeOffsets (date).Length);
986                                 Assert.AreEqual (new TimeSpan[] {new TimeSpan (1, 0, 0), new TimeSpan (2, 0, 0)}, brussels.GetAmbiguousTimeOffsets (date));
987                         }
988                 }
989
990                 [TestFixture]
991                 public class HasSameRulesTests
992                 {
993                         [Test]
994                         public void NullAdjustments () //bnc #391011
995                         {
996                                 TimeZoneInfo utc = TimeZoneInfo.Utc;
997                                 TimeZoneInfo custom = TimeZoneInfo.CreateCustomTimeZone ("Custom", new TimeSpan (0), "Custom", "Custom");
998                                 Assert.IsTrue (utc.HasSameRules (custom));
999                         }
1000                 }
1001
1002                 [TestFixture]
1003                 public class SerializationTests
1004                 {
1005                         [Test]
1006                         public void Serialization_Deserialization ()
1007                         {
1008                                 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
1009                                 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
1010                                 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
1011                                 TimeZoneInfo london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
1012                                 MemoryStream stream = new MemoryStream ();
1013                                 BinaryFormatter formatter = new BinaryFormatter ();
1014                                 formatter.Serialize (stream, london);
1015                                 stream.Position = 0;
1016                                 TimeZoneInfo deserialized = (TimeZoneInfo) formatter.Deserialize (stream);
1017                                 stream.Close ();
1018                                 stream.Dispose ();
1019                                 Assert.IsTrue (london.Equals (deserialized));
1020                         }
1021                 }
1022
1023                 [TestFixture]
1024                 public class MultipleDaylightSavingTimeTests {
1025                         private TimeZoneInfo cairo;
1026                         private DateTime dst1Start;
1027                         private DateTime dst1End;
1028                         private DateTime dst2Start;
1029                         private DateTime dst2End;
1030
1031                         private TimeSpan baseUtcOffset;
1032                         private TimeSpan dstUtcOffset;
1033                         private TimeSpan dstOffset;
1034
1035                         [SetUp]
1036                         public void CreateTimeZones ()
1037                         {
1038                                 /*
1039                                 From 1/1/2014 12:00:00 AM to 6/30/2014 12:00:00 AM
1040                                         Delta: 01:00:00
1041                                         Begins at 12:00 AM on 16 May
1042                                         Ends at 1:00 AM on 29 June
1043                                 From 7/1/2014 12:00:00 AM to 12/31/2014 12:00:00 AM
1044                                         Delta: 01:00:00
1045                                         Begins at 12:00 AM on 29 July
1046                                         Ends at 12:00 AM on 26 September
1047                                 */
1048                                 dst1Start = new DateTime (2014, 5, 16);
1049                                 dst1End = new DateTime (2014, 6, 29);
1050                                 dst2Start = new DateTime (2014, 7, 29);
1051                                 dst2End = new DateTime (2014, 9, 26);
1052
1053                                 baseUtcOffset = new TimeSpan (2, 0, 0);
1054                                 dstUtcOffset = new TimeSpan (3, 0, 0);
1055                                 dstOffset = dstUtcOffset - baseUtcOffset;
1056
1057                                 var rule1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (
1058                                         new DateTime (2014, 1, 1), new DateTime (2014, 6, 30), dstOffset,
1059                                         CreateFixedDateRule (dst1Start), CreateFixedDateRule (dst1End));
1060
1061                                 var rule2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (
1062                                         new DateTime (2014, 7, 1), new DateTime (2014, 12, 31), dstOffset,
1063                                         CreateFixedDateRule (dst2Start), CreateFixedDateRule (dst2End));
1064
1065                                 cairo = TimeZoneInfo.CreateCustomTimeZone ("Africa/Cairo", baseUtcOffset, "Africa/Cairo", "EET", "EEST",
1066                                         new [] {rule1, rule2});
1067                         }
1068
1069                         private static TimeZoneInfo.TransitionTime CreateFixedDateRule (DateTime dateTime)
1070                         {
1071                                 var time = new DateTime (dateTime.Ticks - dateTime.Date.Ticks);
1072                                 return TimeZoneInfo.TransitionTime.CreateFixedDateRule (time, dateTime.Month, dateTime.Day);
1073                         }
1074
1075                         [Test]
1076                         public void GetUtcOffset_FromUTC ()
1077                         {
1078                                 var d = dst1Start.Add (-baseUtcOffset);
1079                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1080                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1081                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1082                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1083
1084                                 d = dst1End.Add (-baseUtcOffset-dstOffset);
1085                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1086                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1087                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1088                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1089
1090                                 d = dst2Start.Add (-baseUtcOffset);
1091                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1092                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1093                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1094                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1095
1096                                 d = dst2End.Add (-baseUtcOffset-dstOffset);
1097                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1098                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1099                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1100                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1101                         }
1102
1103                         [Test]
1104                         public void GetUtcOffset_FromLocal ()
1105                         {
1106                                 var d = dst1Start.Add (-baseUtcOffset);
1107                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1108                                 d = d.ToLocalTime ();
1109                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1110                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1111                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1112
1113                                 d = dst1End.Add (-baseUtcOffset-dstOffset);
1114                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1115                                 d = d.ToLocalTime ();
1116                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1117                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1118                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1119
1120                                 d = dst2Start.Add (-baseUtcOffset);
1121                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1122                                 d = d.ToLocalTime ();
1123                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1124                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1125                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1126
1127                                 d = dst2End.Add (-baseUtcOffset-dstOffset);
1128                                 d = DateTime.SpecifyKind (d, DateTimeKind.Utc);
1129                                 d = d.ToLocalTime ();
1130                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1131                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1132                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1133                         }
1134
1135                         [Test]
1136                         public void GetUtcOffset_FromUnspecified ()
1137                         {
1138                                 var d = dst1Start.Add (dstOffset);
1139                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1140                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1141                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1142
1143                                 d = dst1End.Add (-dstOffset);
1144                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1145                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1146                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1147
1148                                 d = dst2Start.Add (dstOffset);
1149                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1150                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
1151                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1152
1153                                 d = dst2End.Add (-dstOffset);
1154                                 Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
1155                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d));
1156                                 Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
1157                         }
1158
1159                   [Test]
1160                   public void  GetUtcOffset_FromDateTimeOffset ()
1161                   {
1162                           DateTimeOffset offset;
1163
1164                           offset = new DateTimeOffset(dst1Start, baseUtcOffset);
1165                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst1Start_with_baseUtcOffset#before");
1166                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset), "dst1Start_with_baseUtcOffset#exact");
1167                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst1Start_with_baseUtcOffset#after");
1168
1169                           offset = new DateTimeOffset(dst1End, dstOffset + baseUtcOffset);
1170                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst1End_with_dstOffset+baseUtcOffset#before");
1171                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset), "dst1End_with_dstOffset+baseUtcOffset#exact");
1172                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst1End_with_dstOffset+baseUtcOffset#after");
1173
1174                           offset = new DateTimeOffset(dst2Start, baseUtcOffset);
1175                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst2Start_with_baseUtcOffset#before");
1176                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset), "dst2Start_with_baseUtcOffset#exact");
1177                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst2Start_with_baseUtcOffset#after");
1178
1179                           offset = new DateTimeOffset(dst2End, baseUtcOffset + dstOffset);
1180                           Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, -1))), "dst2End_with_dstOffset+baseUtcOffset#before");
1181                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset), "dst2End_with_dstOffset+baseUtcOffset#exact");
1182                           Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset(offset.Add(new TimeSpan(0, 0, 0, 1))), "dst2End_with_dstOffset+baseUtcOffset#after");
1183                   }
1184
1185                         [Test]
1186                         public void DTS_WithMinimalDate ()
1187                         {
1188                                 TimeZoneInfo.TransitionTime startTransition, endTransition;
1189                                 startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 4, 0, 0),
1190                                                                                                                                                                   10, 2, DayOfWeek.Sunday);
1191                                 endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 3, 0, 0),
1192                                                                                                                                                                 3, 2, DayOfWeek.Sunday);
1193
1194                                 var ctz = TimeZoneInfo.CreateCustomTimeZone ("test", TimeSpan.FromHours (-5), "display", "sdisplay", "dst", new [] {
1195                                         TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue, DateTime.MaxValue.Date, TimeSpan.FromHours (-1), startTransition, endTransition) });
1196
1197                                 var offset = ctz.GetUtcOffset (DateTime.MinValue);
1198                                 Assert.AreEqual (TimeSpan.FromHours (-5), offset); // TODO: Wrong it should be -6
1199                         }
1200     }
1201
1202                 [TestFixture]
1203                 public class GetDaylightChanges
1204                 {
1205                         MethodInfo getChanges;
1206
1207                         [SetUp]
1208                         public void Setup ()
1209                         {
1210                                 var flags = BindingFlags.Instance | BindingFlags.NonPublic;
1211                                 getChanges = typeof (TimeZoneInfo).GetMethod ("GetDaylightChanges", flags);
1212                         }
1213
1214                         [Test]
1215                         public void TestSydneyDaylightChanges ()
1216                         {
1217                                 TimeZoneInfo tz;
1218                                 if (Environment.OSVersion.Platform == PlatformID.Unix)
1219                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("Australia/Sydney");
1220                                 else
1221                                         tz = TimeZoneInfo.FindSystemTimeZoneById ("W. Australia Standard Time");
1222
1223                                 var changes = (DaylightTime) getChanges.Invoke (tz, new object [] {2014});
1224
1225                                 Assert.AreEqual (new TimeSpan (1, 0, 0), changes.Delta);
1226                                 Assert.AreEqual (new DateTime (2014, 10, 5, 2, 0, 0), changes.Start);
1227                                 Assert.AreEqual (new DateTime (2014, 4, 6, 3, 0, 0), changes.End);
1228                         }
1229
1230                         [Test]
1231                         public void AllTimeZonesDaylightChanges ()
1232                         {
1233                                 foreach (var tz in TimeZoneInfo.GetSystemTimeZones ()) {
1234                                         try {
1235                                                 for (var year = 1950; year <= 2051; year++)
1236                                                         getChanges.Invoke (tz, new object [] {year} );
1237                                         } catch (Exception e) {
1238                                                 Assert.Fail ("TimeZone " + tz.Id + " exception: " + e.ToString ()); 
1239                                         }
1240                                 }
1241                         }
1242                 }
1243
1244                 [TestFixture]
1245                 public class ParseTZBuffer
1246                 {
1247                         MethodInfo parseTZBuffer;
1248
1249                         [SetUp]
1250                         public void Setup()
1251                         {
1252                                 var flags = BindingFlags.Static | BindingFlags.NonPublic;
1253                                 parseTZBuffer = typeof (TimeZoneInfo).GetMethod ("ParseTZBuffer", flags);
1254                         }
1255
1256                         [Test]
1257                         public void Bug31432 ()
1258                         {
1259                                 // Europe/Moscow from failing device
1260                                 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=";
1261
1262                                 var data = Convert.FromBase64String (base64Data);
1263
1264                                 var tz = parseTZBuffer.Invoke (null, new object[] { "Test", data, data.Length});
1265                                 Assert.IsTrue (tz != null);
1266                         }
1267                 }
1268         }
1269 }