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 TimeZoneInfo local = TimeZoneInfo.Local;
48 public class CreateCustomTimezoneTests
51 [ExpectedException (typeof (ArgumentNullException))]
52 public void IdIsNullException ()
54 TimeZoneInfo.CreateCustomTimeZone (null, new TimeSpan (0), null, null);
58 [ExpectedException (typeof (ArgumentException))]
59 public void IdIsEmptyString ()
61 TimeZoneInfo.CreateCustomTimeZone ("", new TimeSpan (0), null, null);
65 [ExpectedException (typeof (ArgumentException))]
66 public void OffsetIsNotMinutes ()
68 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (0, 0, 55), null, null);
72 [ExpectedException (typeof (ArgumentOutOfRangeException))]
73 public void OffsetTooBig ()
75 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (14, 1, 0), null, null);
79 [ExpectedException (typeof (ArgumentOutOfRangeException))]
80 public void OffsetTooSmall ()
82 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", - new TimeSpan (14, 1, 0), null, null);
87 [ExpectedException (typeof (ArgumentException))]
88 public void IdLongerThan32 ()
90 TimeZoneInfo.CreateCustomTimeZone ("12345678901234567890123456789012345", new TimeSpan (0), null, null);
95 [ExpectedException (typeof (InvalidTimeZoneException))]
96 public void AdjustmentRulesOverlap ()
98 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
99 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
100 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
101 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
102 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
103 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2004,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
104 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
108 [ExpectedException (typeof (InvalidTimeZoneException))]
109 public void RulesNotOrdered ()
111 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
112 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
113 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
114 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
115 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
116 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2006,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
117 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r2, r1});
121 [ExpectedException (typeof (InvalidTimeZoneException))]
122 public void OffsetOutOfRange ()
124 TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
125 TimeZoneInfo.TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
126 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (3,0,0), startTransition, endTransition);
127 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {rule});
131 [ExpectedException (typeof (InvalidTimeZoneException))]
132 public void NullRule ()
134 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (12,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {null});
138 [ExpectedException (typeof (InvalidTimeZoneException))]
139 public void MultiplesRulesForDate ()
141 TimeZoneInfo.TransitionTime s1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 3, 2, DayOfWeek.Sunday);
142 TimeZoneInfo.TransitionTime e1 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 10, 2, DayOfWeek.Sunday);
143 TimeZoneInfo.AdjustmentRule r1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2000,1,1), new DateTime (2005,1,1), new TimeSpan (1,0,0), s1, e1);
144 TimeZoneInfo.TransitionTime s2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 2, 2, DayOfWeek.Sunday);
145 TimeZoneInfo.TransitionTime e2 = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,4,0,0), 11, 2, DayOfWeek.Sunday);
146 TimeZoneInfo.AdjustmentRule r2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2005,1,1), new DateTime (2007,1,1), new TimeSpan (1,0,0), s2, e2);
147 TimeZoneInfo.CreateCustomTimeZone ("mytimezone", new TimeSpan (6,0,0),null,null,null,new TimeZoneInfo.AdjustmentRule[] {r1, r2});
152 public class IsDaylightSavingTimeTests
157 public void CreateTimeZones ()
159 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
160 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
161 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
162 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
166 public void NoDSTInUTC ()
168 DateTime june01 = new DateTime (2007, 06, 01);
169 Assert.IsFalse (TimeZoneInfo.Utc.IsDaylightSavingTime (june01));
173 public void DSTInLondon ()
175 DateTime june01 = new DateTime (2007, 06, 01);
176 DateTime xmas = new DateTime (2007, 12, 25);
177 Assert.IsTrue (london.IsDaylightSavingTime (june01), "June 01 is DST in London");
178 Assert.IsFalse (london.IsDaylightSavingTime (xmas), "Xmas is not DST in London");
182 public void DSTTransisions ()
184 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Unspecified);
185 DateTime startDST = new DateTime (2007, 03, 25, 2, 0, 0, DateTimeKind.Unspecified);
186 DateTime endDST = new DateTime (2007, 10, 28, 1, 59, 59, DateTimeKind.Unspecified);
187 DateTime afterDST = new DateTime (2007, 10, 28, 2, 0, 0, DateTimeKind.Unspecified);
188 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
189 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
190 Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
191 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
195 public void DSTTransisionsUTC ()
197 DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Utc);
198 DateTime startDST = new DateTime (2007, 03, 25, 1, 0, 0, DateTimeKind.Utc);
199 DateTime endDST = new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc);
200 DateTime afterDST = new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc);
201 Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
202 Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
203 Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
204 Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
209 public void MatchTimeZoneBehavior ()
211 TimeZone tzone = TimeZone.CurrentTimeZone;
212 TimeZoneInfo local = TimeZoneInfo.Local;
213 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)) {
214 date = DateTime.SpecifyKind (date, DateTimeKind.Local);
215 if (local.IsInvalidTime (date))
217 Assert.IsTrue (tzone.IsDaylightSavingTime (date) == local.IsDaylightSavingTime (date));
224 public class ConvertTimeTests
229 public void CreateTimeZones ()
231 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
232 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
233 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
234 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
238 [ExpectedException (typeof (ArgumentException))]
239 public void ConvertFromUtc_KindIsLocalException ()
241 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0, DateTimeKind.Local), TimeZoneInfo.Local);
245 [ExpectedException (typeof (ArgumentNullException))]
246 public void ConvertFromUtc_DestinationTimeZoneIsNullException ()
248 TimeZoneInfo.ConvertTimeFromUtc (new DateTime (2007, 5, 3, 11, 8, 0), null);
252 public void ConvertFromUtc_DestinationIsUTC ()
254 DateTime now = DateTime.UtcNow;
255 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (now, TimeZoneInfo.Utc);
256 Assert.AreEqual (now, converted);
260 public void ConvertFromUTC_ConvertInWinter ()
262 DateTime utc = new DateTime (2007, 12, 25, 12, 0, 0);
263 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
264 Assert.AreEqual (utc, converted);
268 public void ConvertFromUtc_ConvertInSummer ()
270 DateTime utc = new DateTime (2007, 06, 01, 12, 0, 0);
271 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
272 Assert.AreEqual (utc + new TimeSpan (1,0,0), converted);
276 public void ConvertToUTC_KindIsUtc ()
278 DateTime now = DateTime.UtcNow;
279 Assert.AreEqual (now.Kind, DateTimeKind.Utc);
280 DateTime converted = TimeZoneInfo.ConvertTimeToUtc (now);
281 Assert.AreEqual (now, converted);
285 [ExpectedException (typeof (ArgumentException))]
286 public void ConvertToUTC_KindIsUTCButSourceIsNot ()
288 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Utc), london);
292 [ExpectedException (typeof (ArgumentException))]
293 public void ConvertToUTC_KindIsLocalButSourceIsNot ()
295 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 8, 0, DateTimeKind.Local), london);
299 [ExpectedException (typeof (ArgumentException))]
300 public void ConvertToUTC_InvalidDate ()
302 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 3, 25, 1, 30, 0), london);
306 [ExpectedException (typeof (ArgumentNullException))]
307 public void ConvertToUTC_SourceIsNull ()
309 TimeZoneInfo.ConvertTimeToUtc (new DateTime (2007, 5, 3, 12, 16, 0), null);
314 public void ConvertToUtc_MatchDateTimeBehavior ()
316 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)) {
317 Assert.AreEqual (TimeZoneInfo.ConvertTimeToUtc (date), date.ToUniversalTime ());
323 public void ConvertFromToUtc ()
325 DateTime utc = DateTime.UtcNow;
326 Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
327 DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, london);
328 Assert.AreEqual (converted.Kind, DateTimeKind.Unspecified);
329 DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, london);
330 Assert.AreEqual (back.Kind, DateTimeKind.Utc);
331 Assert.AreEqual (utc, back);
337 public class IsInvalidTimeTests
342 public void CreateTimeZones ()
344 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
345 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
346 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
347 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
352 public void UTCDate ()
354 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)) {
355 date = DateTime.SpecifyKind (date, DateTimeKind.Utc);
356 Assert.IsFalse (london.IsInvalidTime (date));
361 public void InvalidDates ()
363 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 0, 59, 59)));
364 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 0, 0)));
365 Assert.IsTrue (london.IsInvalidTime (new DateTime (2007, 03, 25, 1, 59, 59)));
366 Assert.IsFalse (london.IsInvalidTime (new DateTime (2007, 03, 25, 2, 0, 0)));
371 public class IsAmbiguousTimeTests
376 public void CreateTimeZones ()
378 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
379 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
380 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
381 london = TimeZoneInfo.CreateCustomTimeZone ("Europe/London", new TimeSpan (0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule [] {rule});
385 public void AmbiguousDates ()
387 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0)));
388 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 1)));
389 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 0)));
390 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 1)));
394 public void AmbiguousUTCDates ()
396 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 0, DateTimeKind.Utc)));
397 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 1, DateTimeKind.Utc)));
398 Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc)));
399 Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc)));
404 public void AmbiguousInUTC ()
406 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)) {
407 Assert.IsFalse (TimeZoneInfo.Utc.IsAmbiguousTime (date));
414 public class GetSystemTimeZonesTests
417 public void NotEmpty ()
419 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
420 Assert.IsNotNull(systemTZ, "SystemTZ is null");
421 Assert.IsFalse (systemTZ.Count == 0, "SystemTZ is empty");
425 public void ContainsBrussels ()
427 global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> systemTZ = TimeZoneInfo.GetSystemTimeZones ();
428 foreach (TimeZoneInfo tz in systemTZ) {
429 if (tz.Id == "Europe/Brussels")
432 Assert.Fail ("Europe/Brussels not found in SystemTZ");
437 public class FindSystemTimeZoneByIdTests
440 [ExpectedException (typeof (ArgumentNullException))]
441 public void NullId ()
443 TimeZoneInfo.FindSystemTimeZoneById (null);
447 [ExpectedException (typeof (TimeZoneNotFoundException))]
448 public void NonSystemTimezone ()
450 TimeZoneInfo.FindSystemTimeZoneById ("Neverland/The_Lagoon");
454 public void FindBrusselsTZ ()
456 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
457 Assert.IsNotNull (brussels);
461 public void OffsetIsCorrectInKinshasa ()
463 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
464 Assert.AreEqual (new TimeSpan (1,0,0), kin.BaseUtcOffset, "BaseUtcOffset in Kinshasa is not +1h");
468 public void OffsetIsCorrectInBrussels ()
470 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
471 Assert.AreEqual (new TimeSpan (1,0,0), brussels.BaseUtcOffset, "BaseUtcOffset for Brussels is not +1h");
475 public void NoDSTInKinshasa ()
477 TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById ("Africa/Kinshasa");
478 Assert.IsFalse (kin.SupportsDaylightSavingTime);
482 public void BrusselsSupportsDST ()
484 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
485 Assert.IsTrue (brussels.SupportsDaylightSavingTime);
489 public void MelbourneSupportsDST ()
491 TimeZoneInfo melbourne = TimeZoneInfo.FindSystemTimeZoneById ("Australia/Melbourne");
492 Assert.IsTrue (melbourne.SupportsDaylightSavingTime);
496 public void RomeAndVaticanSharesTime ()
498 TimeZoneInfo rome = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Rome");
499 TimeZoneInfo vatican = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Vatican");
500 Assert.IsTrue (rome.HasSameRules (vatican));
505 public void BrusselsAdjustments ()
507 TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 3, 5, DayOfWeek.Sunday);
508 TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,3,0,0), 10, 5, DayOfWeek.Sunday);
509 TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
510 TimeZoneInfo brussels = TimeZoneInfo.CreateCustomTimeZone ("Europe/Brussels", new TimeSpan (1, 0, 0), "Europe/Brussels", "", "", new TimeZoneInfo.AdjustmentRule [] {rule});
512 TimeZoneInfo brussels_sys = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
514 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)) {
515 Assert.AreEqual (brussels.GetUtcOffset (date), brussels_sys.GetUtcOffset (date));
516 Assert.AreEqual (brussels.IsDaylightSavingTime (date), brussels_sys.IsDaylightSavingTime (date));
523 public class GetAmbiguousTimeOffsetsTests
526 [ExpectedException (typeof(ArgumentException))]
527 public void DateIsNotAmbiguous ()
529 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
530 DateTime date = new DateTime (2007, 05, 11, 11, 40, 00);
531 brussels.GetAmbiguousTimeOffsets (date);
535 public void AmbiguousOffsets ()
537 TimeZoneInfo brussels = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Brussels");
538 DateTime date = new DateTime (2007, 10, 28, 2, 30, 00);
539 Assert.IsTrue (brussels.IsAmbiguousTime (date));
540 Assert.AreEqual (2, brussels.GetAmbiguousTimeOffsets (date).Length);
541 Assert.AreEqual (new TimeSpan[] {new TimeSpan (1, 0, 0), new TimeSpan (2, 0, 0)}, brussels.GetAmbiguousTimeOffsets (date));