5 * Stephane Delcroix <stephane@delcroix.org>
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using System.Collections;
30 using NUnit.Framework;
32 namespace MonoTests.System
34 public class TimeZoneInfoTest
37 public class PropertiesTests
40 public void GetLocal ()
42 if (Environment.OSVersion.Platform != PlatformID.Unix)
44 TimeZoneInfo local = TimeZoneInfo.Local;
50 public class CreateCustomTimezoneTests
53 [ExpectedException (typeof (ArgumentNullException))]
54 public void IdIsNullException ()
56 TimeZoneInfo.CreateCustomTimeZone (null, new TimeSpan (0), null, null);
60 [ExpectedException (typeof (ArgumentException))]
61 public void IdIsEmptyString ()
63 TimeZoneInfo.CreateCustomTimeZone ("", new TimeSpan (0), null, null);
67 [ExpectedException (typeof (ArgumentException))]
68 public void OffsetIsNotMinutes ()
70 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (0, 0, 55), null, null);
74 [ExpectedException (typeof (ArgumentOutOfRangeException))]
75 public void OffsetTooBig ()
77 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (14, 1, 0), null, null);
81 [ExpectedException (typeof (ArgumentOutOfRangeException))]
82 public void OffsetTooSmall ()
84 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", - new TimeSpan (14, 1, 0), null, null);
89 [ExpectedException (typeof (ArgumentException))]
90 public void IdLongerThan32 ()
92 TimeZoneInfo.CreateCustomTimeZone ("12345678901234567890123456789012345", new TimeSpan (0), null, null);
97 [ExpectedException (typeof (InvalidTimeZoneException))]
98 public void AdjustmentRulesOverlap ()
100 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
101 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
102 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
103 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
104 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
105 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2004,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
106 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
110 [ExpectedException (typeof (InvalidTimeZoneException))]
111 public void RulesNotOrdered ()
113 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
114 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
115 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
116 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
117 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
118 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2006,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
119 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r2, r1});
123 [ExpectedException (typeof (InvalidTimeZoneException))]
124 public void OffsetOutOfRange ()
126 TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
127 TimeZoneInfo.TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
128 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (3,0,0), startTransition, endTransition);
129 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {rule});
133 [ExpectedException (typeof (InvalidTimeZoneException))]
134 public void NullRule ()
136 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {null});
140 [ExpectedException (typeof (InvalidTimeZoneException))]
141 public void MultiplesRulesForDate ()
143 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
144 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
145 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
146 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
147 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
148 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2005,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
149 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
154 public class IsDaylightSavingTimeTests
159 public void CreateTimeZones ()
161 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
162 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
163 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
164 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
168 public void NoDSTInUTC ()
170 DateTime june01 = new DateTime (2007, 06, 01);
171 Assert.IsFalse (TimeZoneInfo.Utc.IsDaylightSavingTime (june01));
175 public void DSTInLondon ()
177 if (Environment.OSVersion.Platform != PlatformID.Unix)
179 DateTime june01 = new DateTime (2007, 06, 01);
180 DateTime xmas = new DateTime (2007, 12, 25);
181 Assert.IsTrue (london.IsDaylightSavingTime (june01), "June 01 is DST in London");
182 Assert.IsFalse (london.IsDaylightSavingTime (xmas), "Xmas is not DST in London");
186 public void DSTTransisions ()
188 if (Environment.OSVersion.Platform != PlatformID.Unix)
190 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Unspecified);
191 DateTime startDST = new DateTime (2007, 03, 25, 2, 0, 0, DateTimeKind.Unspecified);
192 DateTime endDST = new DateTime (2007, 10, 28, 1, 59, 59, DateTimeKind.Unspecified);
193 DateTime afterDST = new DateTime (2007, 10, 28, 2, 0, 0, DateTimeKind.Unspecified);
194 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
195 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
196 Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
197 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
201 public void DSTTransisionsUTC ()
203 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Utc);
204 DateTime startDST = new DateTime (2007, 03, 25, 1, 0, 0, DateTimeKind.Utc);
205 DateTime endDST = new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc);
206 DateTime afterDST = new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc);
207 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
208 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
209 Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
210 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
215 public void MatchTimeZoneBehavior ()
217 TimeZone tzone = TimeZone.CurrentTimeZone;
218 TimeZoneInfo local = TimeZoneInfo.Local;
219 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)) {
220 date = DateTime.SpecifyKind (date, DateTimeKind.Local);
221 if (local.IsInvalidTime (date))
223 Assert.IsTrue (tzone.IsDaylightSavingTime (date) == local.IsDaylightSavingTime (date));
230 public class ConvertTimeTests
235 public void CreateTimeZones ()
237 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
238 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
239 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
240 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
244 [ExpectedException (typeof (ArgumentException))]
245 public void ConvertFromUtc_KindIsLocalException ()
247 if (Environment.OSVersion.Platform != PlatformID.Unix)
248 throw new ArgumentException ();
249 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0, DateTimeKind.Local), TimeZoneInfo.Local);
253 [ExpectedException (typeof (ArgumentNullException))]
254 public void ConvertFromUtc_DestinationTimeZoneIsNullException ()
256 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0), null);
260 public void ConvertFromUtc_DestinationIsUTC ()
262 DateTime now = DateTime.UtcNow;
263 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (now, TimeZoneInfo.Utc);
264 Assert.AreEqual (now, converted);
268 public void ConvertFromUTC_ConvertInWinter ()
270 if (Environment.OSVersion.Platform != PlatformID.Unix)
272 DateTime utc = new DateTime (2007, 12, 25, 12, 0, 0);
273 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
274 Assert.AreEqual (utc, converted);
278 public void ConvertFromUtc_ConvertInSummer ()
280 if (Environment.OSVersion.Platform != PlatformID.Unix)
282 DateTime utc = new DateTime (2007, 06, 01, 12, 0, 0);
283 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
284 Assert.AreEqual (utc + new TimeSpan (1,0,0), converted);
288 public void ConvertToUTC_KindIsUtc ()
290 DateTime now = DateTime.UtcNow;
291 Assert.AreEqual (now.Kind, DateTimeKind.Utc);
292 DateTime converted = TimeZoneInfo.ConvertTimeToUtc (now);
293 Assert.AreEqual (now, converted);
297 [ExpectedException (typeof (ArgumentException))]
298 public void ConvertToUTC_KindIsUTCButSourceIsNot ()
300 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Utc), london);
304 [ExpectedException (typeof (ArgumentException))]
305 public void ConvertToUTC_KindIsLocalButSourceIsNot ()
307 if (Environment.OSVersion.Platform != PlatformID.Unix)
308 throw new ArgumentException ();
309 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Local), london);
313 [ExpectedException (typeof (ArgumentException))]
314 public void ConvertToUTC_InvalidDate ()
316 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 3, 25, 1, 30, 0), london);
320 [ExpectedException (typeof (ArgumentNullException))]
321 public void ConvertToUTC_SourceIsNull ()
323 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 16, 0), null);
328 public void ConvertToUtc_MatchDateTimeBehavior ()
330 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)) {
331 Assert.AreEqual (TimeZoneInfo.ConvertTimeToUtc (date), date.ToUniversalTime ());
337 public void ConvertFromToUtc ()
339 if (Environment.OSVersion.Platform != PlatformID.Unix)
341 DateTime utc = DateTime.UtcNow;
342 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
343 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
344 Assert.AreEqual (converted.Kind, DateTimeKind.Unspecified);
345 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, london);
346 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
347 Assert.AreEqual (utc, back);
353 public class IsInvalidTimeTests
358 public void CreateTimeZones ()
360 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
361 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
362 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
363 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
368 public void UTCDate ()
370 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)) {
371 date = DateTime.SpecifyKind (date, DateTimeKind.Utc);
372 Assert.IsFalse (london.IsInvalidTime (date));
377 public void InvalidDates ()
379 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 0, 59, 59)));
380 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 0, 0)));
381 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 59, 59)));
382 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 2, 0, 0)));
387 public class IsAmbiguousTimeTests
392 public void CreateTimeZones ()
394 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
395 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
396 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
397 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
401 public void AmbiguousDates ()
403 if (Environment.OSVersion.Platform != PlatformID.Unix)
405 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0)));
406 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 1)));
407 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 0)));
408 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 1)));
412 public void AmbiguousUTCDates ()
414 if (Environment.OSVersion.Platform != PlatformID.Unix)
416 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 0, DateTimeKind.Utc)));
417 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 1, DateTimeKind.Utc)));
418 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc)));
419 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc)));
424 public void AmbiguousInUTC ()
426 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)) {
427 Assert.IsFalse (TimeZoneInfo.Utc.IsAmbiguousTime (date));
434 public class GetSystemTimeZonesTests
437 public void NotEmpty ()
439 if (Environment.OSVersion.Platform != PlatformID.Unix)
441 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
442 Assert.IsNotNull(systemTZ, "SystemTZ is null");
443 Assert.IsFalse (systemTZ.Count == 0, "SystemTZ is empty");
447 public void ContainsBrussels ()
449 if (Environment.OSVersion.Platform != PlatformID.Unix)
451 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
452 foreach (TimeZoneInfo tz in systemTZ) {
453 if (tz.Id == "Europe/Brussels")
456 Assert.Fail ("Europe/Brussels not found in SystemTZ");
461 public class FindSystemTimeZoneByIdTests
464 [ExpectedException (typeof (ArgumentNullException))]
465 public void NullId ()
467 TimeZoneInfo.FindSystemTimeZoneById (null);
471 [ExpectedException (typeof (TimeZoneNotFoundException))]
472 public void NonSystemTimezone ()
474 if (Environment.OSVersion.Platform != PlatformID.Unix)
475 throw new TimeZoneNotFoundException ();
476 TimeZoneInfo.FindSystemTimeZoneById ("Neverland/The_Lagoon");
480 public void FindBrusselsTZ ()
482 if (Environment.OSVersion.Platform != PlatformID.Unix)
484 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
485 Assert.IsNotNull (brussels);
489 public void OffsetIsCorrectInKinshasa ()
491 if (Environment.OSVersion.Platform != PlatformID.Unix)
493 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
494 Assert.AreEqual (new TimeSpan (1,0,0), kin.BaseUtcOffset, "BaseUtcOffset in Kinshasa is not +1h");
498 public void OffsetIsCorrectInBrussels ()
500 if (Environment.OSVersion.Platform != PlatformID.Unix)
502 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
503 Assert.AreEqual (new TimeSpan (1,0,0), brussels.BaseUtcOffset, "BaseUtcOffset for Brussels is not +1h");
507 public void NoDSTInKinshasa ()
509 if (Environment.OSVersion.Platform != PlatformID.Unix)
511 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
512 Assert.IsFalse (kin.SupportsDaylightSavingTime);
516 public void BrusselsSupportsDST ()
518 if (Environment.OSVersion.Platform != PlatformID.Unix)
520 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
521 Assert.IsTrue (brussels.SupportsDaylightSavingTime);
525 public void MelbourneSupportsDST ()
527 if (Environment.OSVersion.Platform != PlatformID.Unix)
529 TimeZoneInfo melbourne = TimeZoneInfo.FindSystemTimeZoneById ("Australia/Melbourne");
530 Assert.IsTrue (melbourne.SupportsDaylightSavingTime);
534 public void RomeAndVaticanSharesTime ()
536 if (Environment.OSVersion.Platform != PlatformID.Unix)
538 TimeZoneInfo rome = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Rome");
539 TimeZoneInfo vatican = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Vatican");
540 Assert.IsTrue (rome.HasSameRules (vatican));
545 public void BrusselsAdjustments ()
547 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 3, 5, DayOfWeek.Sunday);
548 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,3,0,0), 10, 5, DayOfWeek.Sunday);
549 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
550 TimeZoneInfo brussels = TimeZoneInfo.CreateCustomTimeZone ("Europe/Brussels", new TimeSpan (1, 0, 0), "Europe/Brussels", "", "", new TimeZoneInfo.AdjustmentRule [] {rule});
552 TimeZoneInfo brussels_sys = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
554 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)) {
555 Assert.AreEqual (brussels.GetUtcOffset (date), brussels_sys.GetUtcOffset (date));
556 Assert.AreEqual (brussels.IsDaylightSavingTime (date), brussels_sys.IsDaylightSavingTime (date));
563 public class GetAmbiguousTimeOffsetsTests
566 [ExpectedException (typeof(ArgumentException))]
567 public void DateIsNotAmbiguous ()
569 if (Environment.OSVersion.Platform != PlatformID.Unix)
570 throw new ArgumentException ();
571 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
572 DateTime date = new DateTime (2007, 05, 11, 11, 40, 00);
573 brussels.GetAmbiguousTimeOffsets (date);
577 public void AmbiguousOffsets ()
579 if (Environment.OSVersion.Platform != PlatformID.Unix)
581 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
582 DateTime date = new DateTime (2007, 10, 28, 2, 30, 00);
583 Assert.IsTrue (brussels.IsAmbiguousTime (date));
584 Assert.AreEqual (2, brussels.GetAmbiguousTimeOffsets (date).Length);
585 Assert.AreEqual (new TimeSpan[] {new TimeSpan (1, 0, 0), new TimeSpan (2, 0, 0)}, brussels.GetAmbiguousTimeOffsets (date));