5 * Stephane Delcroix <stephane@delcroix.org>
7 * Copyright 2011 Xamarin Inc.
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:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
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.
32 using System
.Runtime
.InteropServices
;
33 using System
.Runtime
.Serialization
.Formatters
.Binary
;
34 using System
.Collections
;
35 using System
.Reflection
;
36 using System
.Globalization
;
38 using NUnit
.Framework
;
39 namespace MonoTests
.System
41 public class TimeZoneInfoTest
43 static FieldInfo localField
;
44 static FieldInfo cachedDataField
;
45 static object localFieldObj
;
47 public static string MapTimeZoneId (string id
)
49 if (Environment
.OSVersion
.Platform
== PlatformID
.Unix
)
53 case "Pacific/Auckland":
54 return "New Zealand Standard Time";
56 return "GTB Standard Time";
58 return "Eastern Standard Time";
60 return "Central Standard Time";
62 return "Pacific Standard Time";
63 case "Australia/Sydney":
64 case "Australia/Melbourne":
65 return "AUS Eastern Standard Time";
66 case "Europe/Brussels":
67 return "Romance Standard Time";
68 case "Africa/Kinshasa":
69 return "W. Central Africa Standard Time";
71 case "Europe/Vatican":
72 return "W. Europe Standard Time";
73 case "Canada/Eastern":
74 return "Eastern Standard Time";
76 return "Iran Standard Time";
77 case "Europe/Guernsey":
78 return "GMT Standard Time";
80 Assert
.Fail ($"No mapping defined for zone id '{id}'");
86 public static void SetLocal (TimeZoneInfo val
)
88 if (localField
== null) {
90 localField
= typeof (TimeZoneInfo
).GetField ("local",
91 BindingFlags
.Static
| BindingFlags
.GetField
| BindingFlags
.NonPublic
);
93 cachedDataField
= typeof (TimeZoneInfo
).GetField ("s_cachedData",
94 BindingFlags
.Static
| BindingFlags
.GetField
| BindingFlags
.NonPublic
);
96 localField
= cachedDataField
.FieldType
.GetField ("_localTimeZone",
97 BindingFlags
.Instance
| BindingFlags
.GetField
| BindingFlags
.NonPublic
);
101 if (cachedDataField
!= null)
102 localFieldObj
= cachedDataField
.GetValue (null);
104 localField
.SetValue (localFieldObj
, val
);
108 public class PropertiesTests
111 public void GetLocal ()
113 TimeZoneInfo local
= TimeZoneInfo
.Local
;
114 Assert
.IsNotNull (local
);
115 Assert
.IsTrue (true);
119 private static extern int readlink (string path
, byte[] buffer
, int buflen
);
121 [Test
] // Covers #24958
122 public void LocalId ()
124 #if !MONOTOUCH && !XAMMAC
125 byte[] buf
= new byte [512];
127 var path
= "/etc/localtime";
129 var ret
= readlink (path
, buf
, buf
.Length
);
131 return; // path is not a symbolic link, nothing to test
132 } catch (DllNotFoundException e
) {
137 Assert
.IsTrue (TimeZoneInfo
.Local
.Id
!= "Local", "Local timezone id should not be \"Local\"");
142 public class CreateCustomTimezoneTests
145 [ExpectedException (typeof (ArgumentNullException
))]
146 public void IdIsNullException ()
148 TimeZoneInfo
.CreateCustomTimeZone (null, new TimeSpan (0), null, null);
152 [ExpectedException (typeof (ArgumentException
))]
153 public void IdIsEmptyString ()
155 TimeZoneInfo
.CreateCustomTimeZone ("", new TimeSpan (0), null, null);
159 [ExpectedException (typeof (ArgumentException
))]
160 public void OffsetIsNotMinutes ()
162 TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (0, 0, 55), null, null);
166 [ExpectedException (typeof (ArgumentOutOfRangeException
))]
167 public void OffsetTooBig ()
169 TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (14, 1, 0), null, null);
173 [ExpectedException (typeof (ArgumentOutOfRangeException
))]
174 public void OffsetTooSmall ()
176 TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", - new TimeSpan (14, 1, 0), null, null);
181 [ExpectedException (typeof (ArgumentException
))]
182 public void IdLongerThan32 ()
184 TimeZoneInfo
.CreateCustomTimeZone ("12345678901234567890123456789012345", new TimeSpan (0), null, null);
189 [ExpectedException (typeof (InvalidTimeZoneException
))]
190 public void AdjustmentRulesOverlap ()
192 TimeZoneInfo
.TransitionTime s1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek
.Sunday
);
193 TimeZoneInfo
.TransitionTime e1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek
.Sunday
);
194 TimeZoneInfo
.AdjustmentRule r1
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1
, e1
);
195 TimeZoneInfo
.TransitionTime s2
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek
.Sunday
);
196 TimeZoneInfo
.TransitionTime e2
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek
.Sunday
);
197 TimeZoneInfo
.AdjustmentRule r2
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (new DateTime (2004,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2
, e2
);
198 TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo
.AdjustmentRule
[] {r1, r2}
);
202 [ExpectedException (typeof (InvalidTimeZoneException
))]
203 public void RulesNotOrdered ()
205 TimeZoneInfo
.TransitionTime s1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek
.Sunday
);
206 TimeZoneInfo
.TransitionTime e1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek
.Sunday
);
207 TimeZoneInfo
.AdjustmentRule r1
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1
, e1
);
208 TimeZoneInfo
.TransitionTime s2
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek
.Sunday
);
209 TimeZoneInfo
.TransitionTime e2
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek
.Sunday
);
210 TimeZoneInfo
.AdjustmentRule r2
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (new DateTime (2006,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2
, e2
);
211 TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo
.AdjustmentRule
[] {r2, r1}
);
215 [ExpectedException (typeof (InvalidTimeZoneException
))]
216 public void OffsetOutOfRange ()
218 TimeZoneInfo
.TransitionTime startTransition
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek
.Sunday
);
219 TimeZoneInfo
.TransitionTime endTransition
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek
.Sunday
);
220 TimeZoneInfo
.AdjustmentRule rule
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (3,0,0), startTransition
, endTransition
);
221 TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo
.AdjustmentRule
[] {rule}
);
225 [ExpectedException (typeof (InvalidTimeZoneException
))]
226 public void NullRule ()
228 TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo
.AdjustmentRule
[] {null}
);
232 [ExpectedException (typeof (InvalidTimeZoneException
))]
233 public void MultiplesRulesForDate ()
235 TimeZoneInfo
.TransitionTime s1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek
.Sunday
);
236 TimeZoneInfo
.TransitionTime e1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek
.Sunday
);
237 TimeZoneInfo
.AdjustmentRule r1
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1
, e1
);
238 TimeZoneInfo
.TransitionTime s2
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek
.Sunday
);
239 TimeZoneInfo
.TransitionTime e2
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek
.Sunday
);
240 TimeZoneInfo
.AdjustmentRule r2
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (new DateTime (2005,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2
, e2
);
241 TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo
.AdjustmentRule
[] {r1, r2}
);
245 public void SupportsDaylightSavingTime_NonEmptyAdjustmentRule ()
247 TimeZoneInfo
.TransitionTime s1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek
.Sunday
);
248 TimeZoneInfo
.TransitionTime e1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek
.Sunday
);
249 TimeZoneInfo
.AdjustmentRule r1
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1
, e1
);
250 TimeZoneInfo tz
= TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo
.AdjustmentRule
[] {r1}
);
251 Assert
.IsTrue (tz
.SupportsDaylightSavingTime
);
255 public void SupportsDaylightSavingTime_EmptyAdjustmentRule ()
257 TimeZoneInfo tz
= TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,null);
258 Assert
.IsFalse (tz
.SupportsDaylightSavingTime
);
262 public void SupportsDaylightSavingTime_NonEmptyAdjustmentRule_DisableDaylightSavingTime ()
264 TimeZoneInfo
.TransitionTime s1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek
.Sunday
);
265 TimeZoneInfo
.TransitionTime e1
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek
.Sunday
);
266 TimeZoneInfo
.AdjustmentRule r1
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1
, e1
);
267 TimeZoneInfo tz
= TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo
.AdjustmentRule
[] {r1}
, true);
268 Assert
.IsFalse (tz
.SupportsDaylightSavingTime
);
272 public void SupportsDaylightSavingTime_EmptyAdjustmentRule_DisableDaylightSavingTime ()
274 TimeZoneInfo tz
= TimeZoneInfo
.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,null,true);
275 Assert
.IsFalse (tz
.SupportsDaylightSavingTime
);
280 [Category ("NotWasm")]
281 public class IsDaylightSavingTimeTests
286 public void CreateTimeZones ()
288 TimeZoneInfo
.TransitionTime start
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek
.Sunday
);
289 TimeZoneInfo
.TransitionTime end
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek
.Sunday
);
290 TimeZoneInfo
.AdjustmentRule rule
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (DateTime
.MinValue
.Date
, DateTime
.MaxValue
.Date
, new TimeSpan (1,0,0), start
, end
);
291 london
= TimeZoneInfo
.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo
.AdjustmentRule
[] {rule}
);
295 public void NoDSTInUTC ()
297 DateTime june01
= new DateTime (2007, 06, 01);
298 Assert
.IsFalse (TimeZoneInfo
.Utc
.IsDaylightSavingTime (june01
));
302 public void DSTInLondon ()
304 DateTime june01
= new DateTime (2007, 06, 01);
305 DateTime xmas
= new DateTime (2007, 12, 25);
306 Assert
.IsTrue (london
.IsDaylightSavingTime (june01
), "June 01 is DST in London");
307 Assert
.IsFalse (london
.IsDaylightSavingTime (xmas
), "Xmas is not DST in London");
311 [Category ("MobileNotWorking")]
312 public void DSTTransitions ()
314 DateTime beforeDST
= new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind
.Unspecified
);
315 DateTime startDST
= new DateTime (2007, 03, 25, 2, 0, 0, DateTimeKind
.Unspecified
);
316 DateTime endDST
= new DateTime (2007, 10, 28, 1, 59, 59, DateTimeKind
.Unspecified
);
317 DateTime afterDST
= new DateTime (2007, 10, 28, 2, 0, 0, DateTimeKind
.Unspecified
);
318 Assert
.IsFalse (london
.IsDaylightSavingTime (beforeDST
), "Just before DST");
319 Assert
.IsTrue (london
.IsDaylightSavingTime (startDST
), "the first seconds of DST");
320 Assert
.IsFalse (london
.IsDaylightSavingTime (endDST
), "The last seconds of DST");
321 Assert
.IsFalse (london
.IsDaylightSavingTime (afterDST
), "Just after DST");
325 public void DSTTransitionsUTC ()
327 DateTime beforeDST
= new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind
.Utc
);
328 DateTime startDST
= new DateTime (2007, 03, 25, 1, 0, 0, DateTimeKind
.Utc
);
329 DateTime endDST
= new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind
.Utc
);
330 DateTime afterDST
= new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind
.Utc
);
331 Assert
.IsFalse (london
.IsDaylightSavingTime (beforeDST
), "Just before DST");
332 Assert
.IsTrue (london
.IsDaylightSavingTime (startDST
), "the first seconds of DST");
333 Assert
.IsTrue (london
.IsDaylightSavingTime (endDST
), "The last seconds of DST");
334 Assert
.IsFalse (london
.IsDaylightSavingTime (afterDST
), "Just after DST");
339 public void MatchTimeZoneBehavior ()
341 TimeZone tzone
= TimeZone
.CurrentTimeZone
;
342 TimeZoneInfo local
= TimeZoneInfo
.Local
;
343 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)) {
344 date
= DateTime
.SpecifyKind (date
, DateTimeKind
.Local
);
345 if (local
.IsInvalidTime (date
))
347 Assert
.IsTrue (tzone
.IsDaylightSavingTime (date
) == local
.IsDaylightSavingTime (date
));
351 [Test (Description
="Description xambug #17155")]
352 public void AdjustmentRuleAfterNewYears ()
354 TimeZoneInfo tz
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Pacific/Auckland"));
355 // DST start: 9/29/2013 2:00:00 AM
356 // DST end: 4/6/2014 3:00:00 AM
357 DateTime dt
= new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind
.Utc
);
358 Assert
.IsTrue (tz
.IsDaylightSavingTime (dt
), "#1.1");
360 // DST start: 9/29/2014 2:00:00 AM
361 // DST end: 4/6/2015 3:00:00 AM
362 dt
= new DateTime (2014, 6, 9, 23, 0, 0, DateTimeKind
.Utc
);
363 Assert
.IsFalse (tz
.IsDaylightSavingTime (dt
), "#2.1");
365 // DST start: 9/29/2014 2:00:00 AM
366 // DST end: 4/6/2015 3:00:00 AM
367 dt
= new DateTime (2014, 10, 9, 23, 0, 0, DateTimeKind
.Utc
);
368 Assert
.IsTrue (tz
.IsDaylightSavingTime (dt
), "#3.1");
371 [Test
] //Covers #26008
372 public void DSTWithFloatingDateRule ()
374 // Construct a custom time zone where daylight saving time starts on the
375 // 2nd Sunday in March.
376 var transitionToDaylight
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 0, 0), 3, 2, DayOfWeek
.Sunday
);
377 var transitionToStandard
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 0, 0), 11, 1, DayOfWeek
.Sunday
);
378 var adjustment
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (DateTime
.MinValue
.Date
, DateTime
.MaxValue
.Date
, new TimeSpan (1, 0, 0), transitionToDaylight
, transitionToStandard
);
379 var timeZone
= TimeZoneInfo
.CreateCustomTimeZone ("BugCheck", new TimeSpan (-8, 0, 0), "Testing", "Testing Standard", "Testing Daylight", new TimeZoneInfo
.AdjustmentRule
[] { adjustment }
);
380 // See if March 7, 2014 is listed as being during daylight saving time.
381 // If it is DST, then the runtime has the bug that we are looking for.
382 Assert
.IsFalse (timeZone
.IsDaylightSavingTime (new DateTime (2014, 3, 7, 12, 0, 0, DateTimeKind
.Unspecified
)));
385 [Test
] //Covers #25050
386 public void TestAthensDST ()
388 TimeZoneInfo tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Athens"));
389 var date
= new DateTime (2014, 3, 30 , 2, 0, 0);
390 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
391 Assert
.AreEqual (new TimeSpan (2,0,0), tzi
.GetUtcOffset (date
));
395 public void TestAthensDST_InDSTDelta ()
397 // In .NET/.Net Core GetUtcOffset() returns the BaseUtcOffset for times within the hour
398 // lost when DST starts and IsDaylightSavingTime() returns false for datetime and true for datetimeoffset
400 TimeZoneInfo tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Athens"));
402 var date
= new DateTime (2014, 3, 30 , 2, 0, 0);
403 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
404 Assert
.AreEqual (new TimeSpan (2, 0, 0), tzi
.GetUtcOffset (date
));
405 Assert
.IsFalse (tzi
.IsDaylightSavingTime (new DateTimeOffset (date
, tzi
.GetUtcOffset (date
))));
407 date
= new DateTime (2014, 3, 30 , 3, 0, 0);
408 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
409 Assert
.AreEqual (new TimeSpan (2, 0, 0), tzi
.GetUtcOffset (date
));
410 Assert
.IsTrue (tzi
.IsDaylightSavingTime (new DateTimeOffset (date
, tzi
.GetUtcOffset (date
))));
412 date
= new DateTime (2014, 3, 30 , 3, 1, 0);
413 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
414 Assert
.AreEqual (new TimeSpan (2, 0, 0), tzi
.GetUtcOffset (date
));
415 Assert
.IsTrue (tzi
.IsDaylightSavingTime (new DateTimeOffset (date
, tzi
.GetUtcOffset (date
))));
417 date
= new DateTime (2014, 3, 30 , 3, 59, 0);
418 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
419 Assert
.AreEqual (new TimeSpan (2, 0, 0), tzi
.GetUtcOffset (date
));
420 Assert
.IsTrue (tzi
.IsDaylightSavingTime (new DateTimeOffset (date
, tzi
.GetUtcOffset (date
))));
422 date
= new DateTime (2014, 3, 30 , 4, 0, 0);
423 Assert
.IsTrue (tzi
.IsDaylightSavingTime (date
));
424 Assert
.AreEqual (new TimeSpan (3, 0, 0), tzi
.GetUtcOffset (date
));
425 Assert
.IsTrue (tzi
.IsDaylightSavingTime (new DateTimeOffset (date
, tzi
.GetUtcOffset (date
))));
428 [Test
] //Covers #41349
429 public void TestIsDST_DateTimeOffset ()
431 TimeZoneInfo tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Athens"));
432 var date
= new DateTime (2014, 3, 30 , 2, 0, 0);
433 var offset
= tzi
.GetUtcOffset (date
);
434 var dateOffset
= new DateTimeOffset (date
, offset
);
435 Assert
.IsFalse (tzi
.IsDaylightSavingTime (dateOffset
));
437 date
= new DateTime (2014, 3, 30 , 3, 0, 0);
438 offset
= tzi
.GetUtcOffset (date
);
439 dateOffset
= new DateTimeOffset (date
, offset
);
440 Assert
.IsTrue (tzi
.IsDaylightSavingTime (dateOffset
));
443 // https://github.com/mono/mono/issues/9664
445 public void Bug_9664 ()
447 TimeZoneInfo tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("US/Central"));
448 var date
= new DateTime (2019, 3, 9, 21, 0, 0);
449 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
450 Assert
.AreEqual (new TimeSpan (-6, 0, 0), tzi
.GetUtcOffset (date
));
452 tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("US/Central"));
453 date
= new DateTime (2019, 3, 10, 2, 0, 0);
454 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
455 Assert
.AreEqual (new TimeSpan (-6, 0, 0), tzi
.GetUtcOffset (date
));
457 tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("US/Central"));
458 date
= new DateTime (2019, 3, 10, 2, 30, 0);
459 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
460 Assert
.AreEqual (new TimeSpan (-6, 0, 0), tzi
.GetUtcOffset (date
));
462 tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("US/Central"));
463 date
= new DateTime (2019, 3, 10, 3, 0, 0);
464 Assert
.IsTrue (tzi
.IsDaylightSavingTime (date
));
465 Assert
.AreEqual (new TimeSpan (-5, 0, 0), tzi
.GetUtcOffset (date
));
467 #if !WINAOT // https://github.com/mono/mono/issues/15439
468 tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Vatican"));
469 date
= new DateTime (2018, 10, 28, 2, 15, 0);
470 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
471 Assert
.AreEqual (new TimeSpan (1, 0, 0), tzi
.GetUtcOffset (date
));
473 tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Asia/Tehran"));
474 date
= new DateTime (2018, 9, 21, 23, 15, 0);
475 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
476 Assert
.AreEqual (new TimeSpan (3, 30, 0), tzi
.GetUtcOffset (date
));
478 // for Greenwitch Mean Time (Guernsey)
479 tzi
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Guernsey"));
480 date
= new DateTime (2019, 10, 27, 1, 15, 0);
481 Assert
.IsFalse (tzi
.IsDaylightSavingTime (date
));
482 Assert
.AreEqual (new TimeSpan (0, 0, 0), tzi
.GetUtcOffset (date
));
488 [Category ("NotWasm")]
489 public class ConvertTimeTests_LocalUtc
: ConvertTimeTests
491 static TimeZoneInfo oldLocal
;
494 public void SetLocal ()
496 base.CreateTimeZones ();
498 oldLocal
= TimeZoneInfo
.Local
;
499 TimeZoneInfoTest
.SetLocal (TimeZoneInfo
.GetSystemTimeZones().First(t
=> t
.BaseUtcOffset
== TimeSpan
.Zero
));
503 public void RestoreLocal ()
505 TimeZoneInfoTest
.SetLocal (oldLocal
);
510 [Category ("NotWasm")]
511 public class ConvertTimeTests
516 public void CreateTimeZones ()
518 TimeZoneInfo
.TransitionTime start
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek
.Sunday
);
519 TimeZoneInfo
.TransitionTime end
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek
.Sunday
);
520 TimeZoneInfo
.AdjustmentRule rule
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (DateTime
.MinValue
.Date
, DateTime
.MaxValue
.Date
, new TimeSpan (1,0,0), start
, end
);
521 london
= TimeZoneInfo
.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo
.AdjustmentRule
[] {rule}
);
525 [ExpectedException (typeof (ArgumentException
))]
526 public void ConvertFromUtc_KindIsLocalException ()
528 TimeZoneInfo
.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0, DateTimeKind
.Local
), TimeZoneInfo
.Local
);
532 [ExpectedException (typeof (ArgumentNullException
))]
533 public void ConvertFromUtc_DestinationTimeZoneIsNullException ()
535 TimeZoneInfo
.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0), null);
539 public void ConvertFromUtc_DestinationIsUTC ()
541 DateTime now
= DateTime
.UtcNow
;
542 DateTime converted
= TimeZoneInfo
.ConvertTimeFromUtc (now
, TimeZoneInfo
.Utc
);
543 Assert
.AreEqual (now
, converted
);
547 public void ConvertFromUTC_ConvertInWinter ()
549 DateTime utc
= new DateTime (2007, 12, 25, 12, 0, 0);
550 DateTime converted
= TimeZoneInfo
.ConvertTimeFromUtc (utc
, london
);
551 Assert
.AreEqual (utc
, converted
);
555 public void ConvertFromUtc_ConvertInSummer ()
557 DateTime utc
= new DateTime (2007, 06, 01, 12, 0, 0);
558 DateTime converted
= TimeZoneInfo
.ConvertTimeFromUtc (utc
, london
);
559 Assert
.AreEqual (utc
+ new TimeSpan (1,0,0), converted
);
563 public void ConvertToUTC_KindIsUtc ()
565 DateTime now
= DateTime
.UtcNow
;
566 Assert
.AreEqual (now
.Kind
, DateTimeKind
.Utc
);
567 DateTime converted
= TimeZoneInfo
.ConvertTimeToUtc (now
);
568 Assert
.AreEqual (now
, converted
);
572 [ExpectedException (typeof (ArgumentException
))]
573 public void ConvertToUTC_KindIsUTCButSourceIsNot ()
575 TimeZoneInfo
.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind
.Utc
), london
);
579 [ExpectedException (typeof (ArgumentException
))]
580 public void ConvertToUTC_KindIsLocalButSourceIsNot ()
582 TimeZoneInfo
.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind
.Local
), london
);
586 [ExpectedException (typeof (ArgumentException
))]
587 public void ConvertToUTC_InvalidDate ()
589 TimeZoneInfo
.ConvertTimeToUtc (new DateTime (2007, 3, 25, 1, 30, 0), london
);
593 [ExpectedException (typeof (ArgumentNullException
))]
594 public void ConvertToUTC_SourceIsNull ()
596 TimeZoneInfo
.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 16, 0), null);
601 public void ConvertToUtc_MatchDateTimeBehavior ()
603 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)) {
604 Assert
.AreEqual (TimeZoneInfo
.ConvertTimeToUtc (date
), date
.ToUniversalTime ());
610 public void ConvertFromToUtc ()
612 DateTime utc
= DateTime
.UtcNow
;
613 Assert
.AreEqual (utc
.Kind
, DateTimeKind
.Utc
);
614 DateTime converted
= TimeZoneInfo
.ConvertTimeFromUtc (utc
, london
);
615 Assert
.AreEqual (converted
.Kind
, DateTimeKind
.Unspecified
);
616 DateTime back
= TimeZoneInfo
.ConvertTimeToUtc (converted
, london
);
617 Assert
.AreEqual (back
.Kind
, DateTimeKind
.Utc
);
618 Assert
.AreEqual (utc
, back
);
623 public void ConvertTimeToUtc_Overflow ()
625 var res
= TimeZoneInfo
.ConvertTimeToUtc (new DateTime (0));
626 Assert
.AreEqual (res
.Kind
, DateTimeKind
.Utc
, "#1");
628 res
= TimeZoneInfo
.ConvertTimeToUtc (DateTime
.MaxValue
);
629 Assert
.AreEqual (res
.Kind
, DateTimeKind
.Utc
, "#2");
633 public void ConvertFromToUtc_Utc ()
635 DateTime utc
= DateTime
.UtcNow
;
636 Assert
.AreEqual (utc
.Kind
, DateTimeKind
.Utc
);
637 DateTime converted
= TimeZoneInfo
.ConvertTimeFromUtc (utc
, TimeZoneInfo
.Utc
);
638 Assert
.AreEqual (DateTimeKind
.Utc
, converted
.Kind
);
639 DateTime back
= TimeZoneInfo
.ConvertTimeToUtc (converted
, TimeZoneInfo
.Utc
);
640 Assert
.AreEqual (back
.Kind
, DateTimeKind
.Utc
);
641 Assert
.AreEqual (utc
, back
);
645 public void ConvertFromToLocal ()
647 DateTime utc
= DateTime
.UtcNow
;
648 Assert
.AreEqual (utc
.Kind
, DateTimeKind
.Utc
);
649 DateTime converted
= TimeZoneInfo
.ConvertTimeFromUtc (utc
, TimeZoneInfo
.Local
);
650 var expectedKind
= (TimeZoneInfo
.Local
== TimeZoneInfo
.Utc
)? DateTimeKind
.Utc
: DateTimeKind
.Local
;
651 Assert
.AreEqual (expectedKind
, converted
.Kind
);
652 DateTime back
= TimeZoneInfo
.ConvertTimeToUtc (converted
, TimeZoneInfo
.Local
);
653 Assert
.AreEqual (back
.Kind
, DateTimeKind
.Utc
);
654 Assert
.AreEqual (utc
, back
);
658 public void ConvertToTimeZone ()
660 TimeZoneInfo
.ConvertTime (DateTime
.Now
, TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Pacific/Auckland")));
664 [ExpectedException (typeof (ArgumentNullException
))]
665 public void ConvertTime_DateTime_TimeZoneInfo_DestinationTimeZoneIsNull ()
667 TimeZoneInfo
.ConvertTime (DateTime
.Now
, null);
671 [Category ("MobileNotWorking")]
672 public void ConvertTime_DateTime_TimeZoneInfo_DateTimeKindMatch ()
674 var sdt
= new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind
.Utc
);
675 var ddt
= TimeZoneInfo
.ConvertTime (sdt
, TimeZoneInfo
.Utc
);
676 Assert
.AreEqual (ddt
.Kind
, sdt
.Kind
, "#1.1");
677 Assert
.AreEqual (ddt
.Kind
, DateTimeKind
.Utc
, "#1.2");
679 sdt
= new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind
.Local
);
680 ddt
= TimeZoneInfo
.ConvertTime (sdt
, TimeZoneInfo
.Local
);
681 Assert
.AreEqual (ddt
.Kind
, sdt
.Kind
, "#2.1");
682 Assert
.AreEqual (ddt
.Kind
, DateTimeKind
.Local
, "#2.2");
684 sdt
= new DateTime (2014, 1, 9, 23, 0, 0);
685 ddt
= TimeZoneInfo
.ConvertTime (sdt
, TimeZoneInfo
.Local
);
686 var expectedKind
= (TimeZoneInfo
.Local
== TimeZoneInfo
.Utc
)? DateTimeKind
.Utc
: DateTimeKind
.Local
;
687 Assert
.AreEqual (expectedKind
, ddt
.Kind
, "#3.1");
688 Assert
.AreEqual (DateTimeKind
.Unspecified
, sdt
.Kind
, "#3.2");
692 [ExpectedException (typeof (ArgumentNullException
))]
693 public void ConverTime_DateTime_TimeZoneInfo_TimeZoneInfo_SourceTimeZoneIsNull ()
695 TimeZoneInfo
.ConvertTime (DateTime
.Now
, null, TimeZoneInfo
.Local
);
699 [ExpectedException (typeof (ArgumentNullException
))]
700 public void ConverTime_DateTime_TimeZoneInfo_TimeZoneInfo_DestinationTimeZoneIsNull ()
702 TimeZoneInfo
.ConvertTime (DateTime
.Now
, TimeZoneInfo
.Utc
, null);
705 [Test (Description
="Fix for xambug https://bugzilla.xamarin.com/show_bug.cgi?id=17155")]
706 public void ConvertTime_AdjustmentRuleAfterNewYears ()
708 TimeZoneInfo tz
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Pacific/Auckland"));
710 // DST start: 9/29/2013 2:00:00 AM
711 // DST end: 4/6/2014 3:00:00 AM
712 DateTime sdt
= new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind
.Utc
);
713 DateTime ddt
= TimeZoneInfo
.ConvertTime (sdt
, tz
);
714 Assert
.AreEqual (10, ddt
.Day
, "#1.1");
715 Assert
.AreEqual (1, ddt
.Month
, "#1.2");
716 Assert
.AreEqual (2014, ddt
.Year
, "#1.3");
717 Assert
.AreEqual (12, ddt
.Hour
, "#1.4");
718 Assert
.AreEqual (0, ddt
.Minute
, "#1.5");
719 Assert
.AreEqual (0, ddt
.Second
, "#1.6");
721 // DST start: 9/29/2014 2:00:00 AM
722 // DST end: 4/6/2015 3:00:00 AM
723 sdt
= new DateTime (2014, 6, 9, 23, 0, 0, DateTimeKind
.Utc
);
724 ddt
= TimeZoneInfo
.ConvertTime (sdt
, tz
);
725 Assert
.AreEqual (10, ddt
.Day
, "#2.1");
726 Assert
.AreEqual (6, ddt
.Month
, "#2.2");
727 Assert
.AreEqual (2014, ddt
.Year
, "#2.3");
728 Assert
.AreEqual (11, ddt
.Hour
, "#2.4");
729 Assert
.AreEqual (0, ddt
.Minute
, "#2.5");
730 Assert
.AreEqual (0, ddt
.Second
, "#2.6");
732 // DST start: 9/29/2014 2:00:00 AM
733 // DST end: 4/6/2015 3:00:00 AM
734 sdt
= new DateTime (2014, 10, 9, 23, 0, 0, DateTimeKind
.Utc
);
735 ddt
= TimeZoneInfo
.ConvertTime (sdt
, tz
);
736 Assert
.AreEqual (10, ddt
.Day
, "#3.1");
737 Assert
.AreEqual (10, ddt
.Month
, "#3.2");
738 Assert
.AreEqual (2014, ddt
.Year
, "#3.3");
739 Assert
.AreEqual (12, ddt
.Hour
, "#3.4");
740 Assert
.AreEqual (0, ddt
.Minute
, "#3.5");
741 Assert
.AreEqual (0, ddt
.Second
, "#3.6");
744 [Test (Description
="Fix the bug https://bugzilla.xamarin.com/show_bug.cgi?id=1849")]
745 public void ConvertTime_AjustmentConvertTimeWithSourceTimeZone () {
747 TimeZoneInfo easternTimeZone
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("US/Eastern"));
748 TimeZoneInfo pacificTimeZone
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("US/Pacific"));
750 DateTime lastMidnight
= new DateTime (new DateTime (2012, 06, 13).Ticks
, DateTimeKind
.Unspecified
);
751 DateTime lastMidnightAsEST
= TimeZoneInfo
.ConvertTime (lastMidnight
, pacificTimeZone
, easternTimeZone
);
752 DateTime lastMidnightAsPST
= TimeZoneInfo
.ConvertTime (lastMidnightAsEST
, easternTimeZone
, pacificTimeZone
);
754 // Last midnight in PST as EST should be 3AM
755 DateTime expectedDate
= new DateTime (2012, 06, 13, 3, 0, 0);
757 Assert
.AreEqual (expectedDate
, lastMidnightAsEST
);
758 Assert
.AreEqual (lastMidnight
, lastMidnightAsPST
);
762 public void ConvertTimeBySystemTimeZoneId_UtcId ()
764 DateTime localTime
= TimeZoneInfo
.ConvertTime (DateTime
.UtcNow
, TimeZoneInfo
.Utc
, TimeZoneInfo
.Local
);
766 TimeZoneInfo
.ConvertTimeBySystemTimeZoneId (DateTime
.UtcNow
, TimeZoneInfo
.Utc
.Id
, TimeZoneInfo
.Local
.Id
);
771 [Category ("NotWasm")]
772 public class IsInvalidTimeTests
777 public void CreateTimeZones ()
779 TimeZoneInfo
.TransitionTime start
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek
.Sunday
);
780 TimeZoneInfo
.TransitionTime end
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek
.Sunday
);
781 TimeZoneInfo
.AdjustmentRule rule
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (DateTime
.MinValue
.Date
, DateTime
.MaxValue
.Date
, new TimeSpan (1,0,0), start
, end
);
782 london
= TimeZoneInfo
.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo
.AdjustmentRule
[] {rule}
);
787 public void UTCDate ()
789 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)) {
790 date
= DateTime
.SpecifyKind (date
, DateTimeKind
.Utc
);
791 Assert
.IsFalse (london
.IsInvalidTime (date
));
796 public void InvalidDates ()
798 Assert
.IsFalse (london
.IsInvalidTime (new DateTime (2007, 03, 25, 0, 59, 59)));
799 Assert
.IsTrue (london
.IsInvalidTime (new DateTime (2007, 03, 25, 1, 0, 0)));
800 Assert
.IsTrue (london
.IsInvalidTime (new DateTime (2007, 03, 25, 1, 59, 59)));
801 Assert
.IsFalse (london
.IsInvalidTime (new DateTime (2007, 03, 25, 2, 0, 0)));
806 [Category ("NotWasm")]
807 public class IsAmbiguousTimeTests
812 public void CreateTimeZones ()
814 TimeZoneInfo
.TransitionTime start
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek
.Sunday
);
815 TimeZoneInfo
.TransitionTime end
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek
.Sunday
);
816 TimeZoneInfo
.AdjustmentRule rule
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (DateTime
.MinValue
.Date
, DateTime
.MaxValue
.Date
, new TimeSpan (1,0,0), start
, end
);
817 london
= TimeZoneInfo
.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo
.AdjustmentRule
[] {rule}
);
821 [Category ("MobileNotWorking")]
822 public void AmbiguousDates ()
824 Assert
.IsTrue (london
.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0)));
825 Assert
.IsTrue (london
.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 1)));
826 Assert
.IsFalse (london
.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 0)));
827 Assert
.IsFalse (london
.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 1)));
831 [Category ("MobileNotWorking")]
832 public void AmbiguousUTCDates ()
834 Assert
.IsTrue (london
.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 0, DateTimeKind
.Utc
)));
835 Assert
.IsTrue (london
.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 1, DateTimeKind
.Utc
)));
836 Assert
.IsTrue (london
.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind
.Utc
)));
837 Assert
.IsTrue (london
.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind
.Utc
)));
842 public void AmbiguousInUTC ()
844 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)) {
845 Assert
.IsFalse (TimeZoneInfo
.Utc
.IsAmbiguousTime (date
));
852 [Category ("NotWasm")]
853 public class GetSystemTimeZonesTests
856 public void Identity ()
858 Assert
.AreSame (TimeZoneInfo
.GetSystemTimeZones (), TimeZoneInfo
.GetSystemTimeZones ());
862 public void NotEmpty ()
864 global::System
.Collections
.ObjectModel
.ReadOnlyCollection
<TimeZoneInfo
> systemTZ
= TimeZoneInfo
.GetSystemTimeZones ();
865 Assert
.IsNotNull(systemTZ
, "SystemTZ is null");
866 Assert
.IsFalse (systemTZ
.Count
== 0, "SystemTZ is empty");
870 public void ContainsBrussels ()
872 global::System
.Collections
.ObjectModel
.ReadOnlyCollection
<TimeZoneInfo
> systemTZ
= TimeZoneInfo
.GetSystemTimeZones ();
873 foreach (TimeZoneInfo tz
in systemTZ
) {
874 if (tz
.Id
== MapTimeZoneId ("Europe/Brussels"))
877 Assert
.Fail ("Europe/Brussels not found in SystemTZ");
881 public void ReflectionReturnsTheCorrectMethod ()
883 var method
= (MethodInfo
) typeof (TimeZoneInfo
).GetMember ("GetSystemTimeZones", MemberTypes
.Method
, BindingFlags
.Static
| BindingFlags
.Public
| BindingFlags
.NonPublic
)[0];
885 var timeZones
= (global::System
.Collections
.ObjectModel
.ReadOnlyCollection
<TimeZoneInfo
>) method
.Invoke (null, null);
886 Assert
.IsTrue (timeZones
.Count
> 0, "GetSystemTimeZones should not return an empty collection.");
891 public void WindowsRegistryTimezoneWithParentheses ()
893 var memberInfos
= typeof (TimeZoneInfo
).GetMember ("TrimSpecial", MemberTypes
.Method
, BindingFlags
.Static
| BindingFlags
.Public
| BindingFlags
.NonPublic
);
895 if (memberInfos
.Length
== 0)
896 Assert
.Ignore ("TrimSpecial method not found");
898 var name
= ((MethodInfo
)memberInfos
[0]).Invoke (null, new object [] { " <---> Central Standard Time (Mexico) ||<<>>" }
);
899 Assert
.AreEqual (name
, "Central Standard Time (Mexico)", "#1");
905 [Category ("NotWasm")]
906 public class FindSystemTimeZoneByIdTests
909 [ExpectedException (typeof (ArgumentNullException
))]
910 public void NullId ()
912 TimeZoneInfo
.FindSystemTimeZoneById (null);
916 [ExpectedException (typeof (TimeZoneNotFoundException
))]
917 public void NonSystemTimezone ()
919 TimeZoneInfo
.FindSystemTimeZoneById ("Neverland/The_Lagoon");
923 public void FindBrusselsTZ ()
925 TimeZoneInfo brussels
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Brussels"));
926 Assert
.IsNotNull (brussels
);
930 public void OffsetIsCorrectInKinshasa ()
932 TimeZoneInfo kin
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Africa/Kinshasa"));
933 Assert
.AreEqual (new TimeSpan (1,0,0), kin
.BaseUtcOffset
, "BaseUtcOffset in Kinshasa is not +1h");
937 public void OffsetIsCorrectInBrussels ()
939 TimeZoneInfo brussels
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Brussels"));
940 Assert
.AreEqual (new TimeSpan (1,0,0), brussels
.BaseUtcOffset
, "BaseUtcOffset for Brussels is not +1h");
944 [Category ("MobileNotWorking")]
945 [Category ("NotOnWindows")]
946 public void DSTInKinshasa ()
948 TimeZoneInfo kin
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Africa/Kinshasa"));
949 Assert
.IsTrue (kin
.SupportsDaylightSavingTime
);
953 public void BrusselsSupportsDST ()
955 TimeZoneInfo brussels
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Brussels"));
956 Assert
.IsTrue (brussels
.SupportsDaylightSavingTime
);
960 public void MelbourneSupportsDST ()
962 TimeZoneInfo melbourne
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Australia/Melbourne"));
963 Assert
.IsTrue (melbourne
.SupportsDaylightSavingTime
);
967 public void RomeAndVaticanSharesTime ()
969 TimeZoneInfo rome
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Rome"));
970 TimeZoneInfo vatican
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Vatican"));
971 Assert
.IsTrue (rome
.HasSameRules (vatican
));
975 public void FindSystemTimeZoneById_Local_Roundtrip ()
977 Assert
.AreEqual (TimeZoneInfo
.Local
.Id
, TimeZoneInfo
.FindSystemTimeZoneById (TimeZoneInfo
.Local
.Id
).Id
);
981 public void Test326 ()
983 DateTime utc
= DateTime
.UtcNow
;
984 DateTime local
= TimeZoneInfo
.ConvertTime (utc
, TimeZoneInfo
.Utc
, TimeZoneInfo
.FindSystemTimeZoneById (TimeZoneInfo
.Local
.Id
));
985 Assert
.AreEqual (local
, utc
+ TimeZoneInfo
.Local
.GetUtcOffset (utc
), "ConvertTime/Local");
990 public void BrusselsAdjustments ()
992 TimeZoneInfo
.TransitionTime start
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 3, 5, DayOfWeek
.Sunday
);
993 TimeZoneInfo
.TransitionTime end
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,3,0,0), 10, 5, DayOfWeek
.Sunday
);
994 TimeZoneInfo
.AdjustmentRule rule
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (DateTime
.MinValue
.Date
, DateTime
.MaxValue
.Date
, new TimeSpan (1,0,0), start
, end
);
995 TimeZoneInfo brussels
= TimeZoneInfo
.CreateCustomTimeZone ("Europe/Brussels", new TimeSpan (1, 0, 0), "Europe/Brussels", "", "", new TimeZoneInfo
.AdjustmentRule
[] {rule}
);
997 TimeZoneInfo brussels_sys
= TimeZoneInfo
.FindSystemTimeZoneById ("Europe/Brussels");
999 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)) {
1000 Assert
.AreEqual (brussels
.GetUtcOffset (date
), brussels_sys
.GetUtcOffset (date
));
1001 Assert
.AreEqual (brussels
.IsDaylightSavingTime (date
), brussels_sys
.IsDaylightSavingTime (date
));
1007 public void FindIsraelStandardTime ()
1009 if (Environment
.OSVersion
.Platform
!= PlatformID
.Win32NT
)
1010 Assert
.Ignore ("Only applies to Windows.");
1012 TimeZoneInfo
.FindSystemTimeZoneById ("Israel Standard Time");
1016 public void SubminuteDSTOffsets ()
1018 if (Environment
.OSVersion
.Platform
!= PlatformID
.Unix
)
1021 var subMinuteDSTs
= new string [] {
1022 "Europe/Dublin", // Europe/Dublin has a DST offset of 34 minutes and 39 seconds in 1916.
1025 "Canada/Newfoundland",
1029 foreach (var tz
in subMinuteDSTs
) {
1030 TimeZoneInfo
.FindSystemTimeZoneById (tz
);
1035 [ExpectedException (typeof (TimeZoneNotFoundException
))]
1036 public void InvalidName ()
1038 TimeZoneInfo
.FindSystemTimeZoneById ("N/A");
1043 [Category ("NotWasm")]
1044 public class GetAmbiguousTimeOffsetsTests
1047 [ExpectedException (typeof(ArgumentException
))]
1048 public void DateIsNotAmbiguous ()
1050 TimeZoneInfo brussels
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Brussels"));
1051 DateTime date
= new DateTime (2007, 05, 11, 11, 40, 00);
1052 brussels
.GetAmbiguousTimeOffsets (date
);
1056 public void AmbiguousOffsets ()
1058 TimeZoneInfo brussels
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Brussels"));
1059 DateTime date
= new DateTime (2007, 10, 28, 2, 30, 00);
1060 Assert
.IsTrue (brussels
.IsAmbiguousTime (date
));
1061 Assert
.AreEqual (2, brussels
.GetAmbiguousTimeOffsets (date
).Length
);
1062 Assert
.AreEqual (new TimeSpan
[] {new TimeSpan (1, 0, 0), new TimeSpan (2, 0, 0)}
, brussels
.GetAmbiguousTimeOffsets (date
));
1067 public class HasSameRulesTests
1070 public void NullAdjustments () //bnc #391011
1072 TimeZoneInfo utc
= TimeZoneInfo
.Utc
;
1073 TimeZoneInfo custom
= TimeZoneInfo
.CreateCustomTimeZone ("Custom", new TimeSpan (0), "Custom", "Custom");
1074 Assert
.IsTrue (utc
.HasSameRules (custom
));
1079 public class SerializationTests
1082 public void Serialization_Deserialization ()
1084 TimeZoneInfo
.TransitionTime start
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek
.Sunday
);
1085 TimeZoneInfo
.TransitionTime end
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek
.Sunday
);
1086 TimeZoneInfo
.AdjustmentRule rule
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (DateTime
.MinValue
.Date
, DateTime
.MaxValue
.Date
, new TimeSpan (1,0,0), start
, end
);
1087 TimeZoneInfo london
= TimeZoneInfo
.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo
.AdjustmentRule
[] {rule}
);
1088 MemoryStream stream
= new MemoryStream ();
1089 BinaryFormatter formatter
= new BinaryFormatter ();
1090 formatter
.Serialize (stream
, london
);
1091 stream
.Position
= 0;
1092 TimeZoneInfo deserialized
= (TimeZoneInfo
) formatter
.Deserialize (stream
);
1095 Assert
.IsTrue (london
.Equals (deserialized
));
1100 public class MultipleDaylightSavingTimeTests
{
1101 private TimeZoneInfo cairo
;
1102 private DateTime dst1Start
;
1103 private DateTime dst1End
;
1104 private DateTime dst2Start
;
1105 private DateTime dst2End
;
1107 private TimeSpan baseUtcOffset
;
1108 private TimeSpan dstUtcOffset
;
1109 private TimeSpan dstOffset
;
1112 public void CreateTimeZones ()
1115 From 1/1/2014 12:00:00 AM to 6/30/2014 12:00:00 AM
1117 Begins at 12:00 AM on 16 May
1118 Ends at 1:00 AM on 29 June
1119 From 7/1/2014 12:00:00 AM to 12/31/2014 12:00:00 AM
1121 Begins at 12:00 AM on 29 July
1122 Ends at 12:00 AM on 26 September
1124 dst1Start
= new DateTime (2014, 5, 16);
1125 dst1End
= new DateTime (2014, 6, 29);
1126 dst2Start
= new DateTime (2014, 7, 29);
1127 dst2End
= new DateTime (2014, 9, 26);
1129 baseUtcOffset
= new TimeSpan (2, 0, 0);
1130 dstUtcOffset
= new TimeSpan (3, 0, 0);
1131 dstOffset
= dstUtcOffset
- baseUtcOffset
;
1133 var rule1
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (
1134 new DateTime (2014, 1, 1), new DateTime (2014, 6, 30), dstOffset
,
1135 CreateFixedDateRule (dst1Start
), CreateFixedDateRule (dst1End
));
1137 var rule2
= TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (
1138 new DateTime (2014, 7, 1), new DateTime (2014, 12, 31), dstOffset
,
1139 CreateFixedDateRule (dst2Start
), CreateFixedDateRule (dst2End
));
1141 cairo
= TimeZoneInfo
.CreateCustomTimeZone ("Africa/Cairo", baseUtcOffset
, "Africa/Cairo", "EET", "EEST",
1142 new [] {rule1, rule2}
);
1145 private static TimeZoneInfo
.TransitionTime
CreateFixedDateRule (DateTime dateTime
)
1147 var time
= new DateTime (dateTime
.Ticks
- dateTime
.Date
.Ticks
);
1148 return TimeZoneInfo
.TransitionTime
.CreateFixedDateRule (time
, dateTime
.Month
, dateTime
.Day
);
1152 public void GetUtcOffset_FromUTC ()
1154 var d
= dst1Start
.Add (-baseUtcOffset
);
1155 d
= DateTime
.SpecifyKind (d
, DateTimeKind
.Utc
);
1156 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1157 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
));
1158 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1160 d
= dst1End
.Add (-baseUtcOffset
-dstOffset
);
1161 d
= DateTime
.SpecifyKind (d
, DateTimeKind
.Utc
);
1162 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1163 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
));
1164 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1166 d
= dst2Start
.Add (-baseUtcOffset
);
1167 d
= DateTime
.SpecifyKind (d
, DateTimeKind
.Utc
);
1168 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1169 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
));
1170 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1172 d
= dst2End
.Add (-baseUtcOffset
-dstOffset
);
1173 d
= DateTime
.SpecifyKind (d
, DateTimeKind
.Utc
);
1174 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1175 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
));
1176 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1180 public void GetUtcOffset_FromLocal ()
1182 var d
= dst1Start
.Add (-baseUtcOffset
);
1183 d
= DateTime
.SpecifyKind (d
, DateTimeKind
.Utc
);
1184 d
= d
.ToLocalTime ();
1185 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1186 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
));
1187 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1189 d
= dst1End
.Add (-baseUtcOffset
-dstOffset
);
1190 d
= DateTime
.SpecifyKind (d
, DateTimeKind
.Utc
);
1191 d
= d
.ToLocalTime ();
1192 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1193 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
));
1194 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1196 d
= dst2Start
.Add (-baseUtcOffset
);
1197 d
= DateTime
.SpecifyKind (d
, DateTimeKind
.Utc
);
1198 d
= d
.ToLocalTime ();
1199 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1200 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
));
1201 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1203 d
= dst2End
.Add (-baseUtcOffset
-dstOffset
);
1204 d
= DateTime
.SpecifyKind (d
, DateTimeKind
.Utc
);
1205 d
= d
.ToLocalTime ();
1206 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1207 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
));
1208 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1212 [Category ("MobileNotWorking")]
1213 public void GetUtcOffset_FromUnspecified ()
1215 var d
= dst1Start
.Add (dstOffset
);
1216 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1217 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
));
1218 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1220 d
= dst1End
.Add (-dstOffset
);
1221 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1222 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,1,0, 1))));
1224 d
= dst2Start
.Add (dstOffset
);
1225 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1226 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
));
1227 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0, 1))));
1229 d
= dst2End
.Add (-dstOffset
);
1230 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,0,0,-1))));
1231 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset (d
.Add (new TimeSpan(0,1,0, 1))));
1235 [Category ("MobileNotWorking")]
1236 public void GetUtcOffset_FromDateTimeOffset ()
1238 DateTimeOffset offset
;
1240 offset
= new DateTimeOffset(dst1Start
, baseUtcOffset
);
1241 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset(offset
.Add(new TimeSpan(0, 0, 0, -1))), "dst1Start_with_baseUtcOffset#before");
1242 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset(offset
), "dst1Start_with_baseUtcOffset#exact");
1243 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset(offset
.Add(new TimeSpan(0, 0, 0, 1))), "dst1Start_with_baseUtcOffset#after");
1245 offset
= new DateTimeOffset(dst1End
, dstOffset
+ baseUtcOffset
);
1246 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset(offset
.Add(new TimeSpan(0, 0, 0, -1))), "dst1End_with_dstOffset+baseUtcOffset#before");
1247 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset(offset
), "dst1End_with_dstOffset+baseUtcOffset#exact");
1248 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset(offset
.Add(new TimeSpan(0, 0, 0, 1))), "dst1End_with_dstOffset+baseUtcOffset#after");
1250 offset
= new DateTimeOffset(dst2Start
, baseUtcOffset
);
1251 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset(offset
.Add(new TimeSpan(0, 0, 0, -1))), "dst2Start_with_baseUtcOffset#before");
1252 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset(offset
), "dst2Start_with_baseUtcOffset#exact");
1253 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset(offset
.Add(new TimeSpan(0, 0, 0, 1))), "dst2Start_with_baseUtcOffset#after");
1255 offset
= new DateTimeOffset(dst2End
, baseUtcOffset
+ dstOffset
);
1256 Assert
.AreEqual(dstUtcOffset
, cairo
.GetUtcOffset(offset
.Add(new TimeSpan(0, 0, 0, -1))), "dst2End_with_dstOffset+baseUtcOffset#before");
1257 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset(offset
), "dst2End_with_dstOffset+baseUtcOffset#exact");
1258 Assert
.AreEqual(baseUtcOffset
, cairo
.GetUtcOffset(offset
.Add(new TimeSpan(0, 0, 0, 1))), "dst2End_with_dstOffset+baseUtcOffset#after");
1262 [Category ("MobileNotWorking")]
1263 public void DTS_WithMinimalDate ()
1265 TimeZoneInfo
.TransitionTime startTransition
, endTransition
;
1266 startTransition
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1, 1, 1, 4, 0, 0),
1267 10, 2, DayOfWeek
.Sunday
);
1268 endTransition
= TimeZoneInfo
.TransitionTime
.CreateFloatingDateRule (new DateTime (1, 1, 1, 3, 0, 0),
1269 3, 2, DayOfWeek
.Sunday
);
1271 var ctz
= TimeZoneInfo
.CreateCustomTimeZone ("test", TimeSpan
.FromHours (-5), "display", "sdisplay", "dst", new [] {
1272 TimeZoneInfo
.AdjustmentRule
.CreateAdjustmentRule (DateTime
.MinValue
, DateTime
.MaxValue
.Date
, TimeSpan
.FromHours (-1), startTransition
, endTransition
) });
1274 var offset
= ctz
.GetUtcOffset (DateTime
.MinValue
);
1275 Assert
.AreEqual (TimeSpan
.FromHours (-6), offset
);
1280 [Category ("NotWasm")]
1281 public class GetDaylightChanges
1283 private static void GetDaylightTime (TimeZoneInfo tz
, int year
, out DateTime start
, out DateTime end
, out TimeSpan delta
)
1286 var rule
= tz
.GetAdjustmentRules ().FirstOrDefault (r
=> r
.DateStart
.Year
<= year
&& r
.DateEnd
.Year
>= year
);
1288 start
= DateTime
.MinValue
;
1289 end
= DateTime
.MinValue
;
1290 delta
= TimeSpan
.Zero
;
1293 var method
= typeof (TimeZoneInfo
).GetMethod ("GetDaylightTime", BindingFlags
.Instance
| BindingFlags
.NonPublic
);
1294 var daylightTime
= method
.Invoke(tz
, new object[] { year, rule, null }
);
1295 var dts
= daylightTime
.GetType(); // internal readonly struct DaylightTimeStruct
1296 start
= (DateTime
) dts
.GetField ("Start").GetValue (daylightTime
);
1297 end
= (DateTime
) dts
.GetField ("End").GetValue (daylightTime
);
1298 delta
= (TimeSpan
) dts
.GetField ("Delta").GetValue (daylightTime
);
1300 MethodInfo getChanges
= typeof (TimeZoneInfo
).GetMethod ("GetDaylightChanges", BindingFlags
.Instance
| BindingFlags
.NonPublic
);
1301 var changes
= (DaylightTime
) getChanges
.Invoke (tz
, new object [] {year}
);
1302 start
= changes
.Start
;
1304 delta
= changes
.Delta
;
1309 [Category ("MobileNotWorking")]
1310 [Category ("NotOnWindows")]
1311 public void TestSydneyDaylightChanges ()
1313 TimeZoneInfo tz
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Australia/Sydney"));
1315 GetDaylightTime (tz
, 2014, out DateTime start
, out DateTime end
, out TimeSpan delta
);
1317 Assert
.AreEqual (new TimeSpan (1, 0, 0), delta
);
1318 Assert
.AreEqual (new DateTime (2014, 10, 6, 2, 0, 0), start
);
1319 Assert
.AreEqual (new DateTime (2014, 4, 6, 2, 59, 59), end
);
1323 [Category ("MobileNotWorking")]
1324 [Category ("NotOnWindows")]
1325 public void TestAthensDaylightChanges ()
1327 TimeZoneInfo tz
= TimeZoneInfo
.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Athens"));
1329 GetDaylightTime (tz
, 2014, out DateTime start
, out DateTime end
, out TimeSpan delta
);
1331 Assert
.AreEqual (new TimeSpan (0, 0, 0), delta
);
1332 Assert
.AreEqual (new DateTime (2014, 10, 27, 3, 0, 0), start
);
1333 Assert
.AreEqual (new DateTime (2014, 03, 30, 2, 59, 59), end
);
1337 public void AllTimeZonesDaylightChanges ()
1339 foreach (var tz
in TimeZoneInfo
.GetSystemTimeZones ()) {
1341 for (var year
= 1950; year
<= 2051; year
++)
1342 GetDaylightTime (tz
, year
, out DateTime start
, out DateTime end
, out TimeSpan delta
);
1343 } catch (Exception e
) {
1344 Assert
.Fail ("TimeZone " + tz
.Id
+ " exception: " + e
.ToString ());
1351 public class ParseTZBuffer
1353 MethodInfo parseTZBuffer
;
1358 var flags
= BindingFlags
.Static
| BindingFlags
.NonPublic
;
1359 parseTZBuffer
= typeof (TimeZoneInfo
).GetMethod ("ParseTZBuffer", flags
);
1363 [Category ("NotWorking")]
1364 public void Bug31432 ()
1366 // Europe/Moscow from failing device
1367 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=";
1369 var data
= Convert
.FromBase64String (base64Data
);
1371 var tz
= parseTZBuffer
.Invoke (null, new object[] { "Test", data, data.Length}
);
1372 Assert
.IsTrue (tz
!= null);