[corlib] In a TimeZone test, UtcOffset is taken for the current year, so take Dayligh...
[mono.git] / mcs / class / corlib / Test / System / TimeZoneTest.cs
1 //
2 // TimeZoneTest.cs - NUnit Test Cases for the System.TimeZone struct
3 //
4 // Authors:
5 //      Martin Baulig (martin@gnome.org)
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 //   (C) 2002 Martin Baulig
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
11
12 using NUnit.Framework;
13 using System;
14 using System.IO;
15 using System.Threading;
16 using System.Globalization;
17 using System.Runtime.Serialization.Formatters.Binary;
18
19 namespace MonoTests.System {
20
21 [TestFixture]
22 public class TimeZoneTest {
23
24         private void CET (TimeZone t1) 
25         {
26                 Assert.AreEqual("CET", t1.StandardName, "A01");
27                 Assert.AreEqual("CEST", t1.DaylightName, "A02");
28         
29                 DaylightTime d1 = t1.GetDaylightChanges (2002);
30                 Assert.AreEqual("03/31/2002 02:00:00", d1.Start.ToString ("G"), "A03");
31                 Assert.AreEqual("10/27/2002 03:00:00", d1.End.ToString ("G"), "A04");
32                 Assert.AreEqual(36000000000L, d1.Delta.Ticks, "A05");
33         
34                 DaylightTime d2 = t1.GetDaylightChanges (1996);
35                 Assert.AreEqual("03/31/1996 02:00:00", d2.Start.ToString ("G"), "A06");
36                 Assert.AreEqual("10/27/1996 03:00:00", d2.End.ToString ("G"), "A07");
37                 Assert.AreEqual(36000000000L, d2.Delta.Ticks, "A08");
38         
39                 DateTime d3 = new DateTime (2002,2,25);
40                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d3), "A09");
41                 DateTime d4 = new DateTime (2002,4,2);
42                 Assert.AreEqual(true, t1.IsDaylightSavingTime (d4), "A10");
43                 DateTime d5 = new DateTime (2002,11,4);
44                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d5), "A11");
45         
46                 Assert.AreEqual(36000000000L, t1.GetUtcOffset (d3).Ticks, "A12");
47                 Assert.AreEqual(72000000000L, t1.GetUtcOffset (d4).Ticks, "A13");
48                 Assert.AreEqual(36000000000L, t1.GetUtcOffset (d5).Ticks, "A14");
49         }
50
51         private void EST (TimeZone t1) 
52         {
53                 // It could be EST though...
54                 //Assert.AreEqual("Eastern Standard Time", t1.StandardName, "B01");
55                 //Assert.AreEqual("Eastern Daylight Time", t1.DaylightName, "B02");
56
57                 DaylightTime d1 = t1.GetDaylightChanges (2002);
58                 Assert.AreEqual("04/07/2002 02:00:00", d1.Start.ToString ("G"), "B03");
59                 Assert.AreEqual("10/27/2002 02:00:00", d1.End.ToString ("G"), "B04");
60                 Assert.AreEqual(36000000000L, d1.Delta.Ticks, "B05");
61
62                 DaylightTime d2 = t1.GetDaylightChanges (1996);
63                 Assert.AreEqual("04/07/1996 02:00:00", d2.Start.ToString ("G"), "B06");
64                 Assert.AreEqual("10/27/1996 02:00:00", d2.End.ToString ("G"), "B07");
65                 Assert.AreEqual(36000000000L, d2.Delta.Ticks, "B08");
66
67                 DateTime d3 = new DateTime (2002,2,25);
68                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d3), "B09");
69                 DateTime d4 = new DateTime (2002,4,8);
70                 Assert.AreEqual(true, t1.IsDaylightSavingTime (d4), "B10");
71                 DateTime d5 = new DateTime (2002,11,4);
72                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d5), "B11");
73
74                 Assert.AreEqual(-180000000000L, t1.GetUtcOffset (d3).Ticks, "B12");
75                 Assert.AreEqual(-144000000000L, t1.GetUtcOffset (d4).Ticks, "B13");
76                 Assert.AreEqual(-180000000000L, t1.GetUtcOffset (d5).Ticks, "B14");
77         }
78
79         private void TST (TimeZone t1) 
80         {
81                 Assert.AreEqual("Tokyo Standard Time", t1.StandardName, "C01");
82                 Assert.AreEqual("Tokyo Standard Time", t1.DaylightName, "C02");
83
84                 DateTime d3 = new DateTime (2002,2,25);
85                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d3), "C09");
86                 DateTime d4 = new DateTime (2002,4,8);
87                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d4), "C10");
88                 DateTime d5 = new DateTime (2002,11,4);
89                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d5), "C11");
90
91                 Assert.AreEqual(324000000000L, t1.GetUtcOffset (d3).Ticks, "C12");
92                 Assert.AreEqual(324000000000L, t1.GetUtcOffset (d4).Ticks, "C13");
93                 Assert.AreEqual(324000000000L, t1.GetUtcOffset (d5).Ticks, "C14");
94         }
95
96         private void GMT (TimeZone t1) {
97                 // Probably wont work on MS.NET, but is better than nothing. Where do
98                 // we change our implementation to match theirs?
99                 
100                 Assert.AreEqual("GMT", t1.StandardName, "D01");
101                 Assert.IsTrue("BST" == t1.DaylightName || "IST" == t1.DaylightName, "D02");
102         
103                 DaylightTime d1 = t1.GetDaylightChanges (2002);
104                 Assert.AreEqual("03/31/2002 01:00:00", d1.Start.ToString ("G"), "D03");
105                 Assert.AreEqual("10/27/2002 02:00:00", d1.End.ToString ("G"), "D04");
106                 Assert.AreEqual(36000000000L, d1.Delta.Ticks, "D05");
107         
108                 DaylightTime d2 = t1.GetDaylightChanges (1996);
109                 Assert.AreEqual("03/31/1996 01:00:00", d2.Start.ToString ("G"), "D06");
110                 Assert.AreEqual("10/27/1996 02:00:00", d2.End.ToString ("G"), "D07");
111                 Assert.AreEqual(36000000000L, d2.Delta.Ticks, "D08");
112         
113                 DateTime d3 = new DateTime (2002,2,25);
114                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d3), "D09");
115                 DateTime d4 = new DateTime (2002,4,2);
116                 Assert.AreEqual(true, t1.IsDaylightSavingTime (d4), "D10");
117                 DateTime d5 = new DateTime (2002,11,4);
118                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d5), "D11");
119         
120                 Assert.AreEqual(0L, t1.GetUtcOffset (d3).Ticks, "D12");
121                 Assert.AreEqual(36000000000L, t1.GetUtcOffset (d4).Ticks, "D13");
122                 Assert.AreEqual(0L, t1.GetUtcOffset (d5).Ticks, "D14");
123         }
124
125         private void NZST(TimeZone t1) {
126                 Assert.AreEqual("NZST", t1.StandardName, "E01");
127                 Assert.AreEqual("NZDT", t1.DaylightName, "E02");
128
129                 DaylightTime d1 = t1.GetDaylightChanges (2013);
130                 Assert.AreEqual("09/29/2013 02:00:00", d1.Start.ToString ("G"), "E03");
131                 Assert.AreEqual("04/07/2013 03:00:00", d1.End.ToString ("G"), "E04");
132                 Assert.AreEqual(36000000000L, d1.Delta.Ticks, "E05");
133
134                 DaylightTime d2 = t1.GetDaylightChanges (2001);
135                 Assert.AreEqual("10/07/2001 02:00:00", d2.Start.ToString ("G"), "E06");
136                 Assert.AreEqual("03/18/2001 03:00:00", d2.End.ToString ("G"), "E07");
137                 Assert.AreEqual(36000000000L, d2.Delta.Ticks, "E08");
138
139                 DateTime d3 = new DateTime(2013,02,15);
140                 Assert.AreEqual(true, t1.IsDaylightSavingTime (d3), "E09");
141                 DateTime d4 = new DateTime(2013,04,30);
142                 Assert.AreEqual(false, t1.IsDaylightSavingTime (d4), "E10");
143                 DateTime d5 = new DateTime(2013,11,03);
144                 Assert.AreEqual(true, t1.IsDaylightSavingTime (d5), "E11");
145
146                 Assert.AreEqual(36000000000L /*hour*/ * 13L, t1.GetUtcOffset (d3).Ticks, "E12");
147                 Assert.AreEqual(36000000000L /*hour*/ * 12L, t1.GetUtcOffset (d4).Ticks, "E13");
148                 Assert.AreEqual(36000000000L /*hour*/ * 13L, t1.GetUtcOffset (d5).Ticks, "E14");
149         }
150
151         [Test]
152         [Culture ("")]
153         public void TestCtors ()
154         {
155                 TimeZone t1 = TimeZone.CurrentTimeZone;
156                 switch (t1.StandardName) {
157                         case "CET":
158                                 CET (t1);
159                                 break;
160                         case "Eastern Standard Time":
161                         case "EST":
162                                 EST (t1);
163                                 break;
164                         case "Tokyo Standard Time":
165                                 TST (t1);
166                                 break;
167                         case "GMT":
168                                 GMT (t1);
169                                 break;
170                         case "NZST":
171                                 NZST (t1);
172                                 break;
173                         default:
174                                 NUnit.Framework.Assert.Ignore ("Your time zone (" + t1.StandardName + ") isn't defined in the test case");
175                                 break;
176                 }
177         }
178
179         [Test]
180         public void CurrentTimeZone_SerializationRoundtrip ()
181         {
182                 TimeZone tz = TimeZone.CurrentTimeZone;
183                 BinaryFormatter bf = new BinaryFormatter ();
184                 MemoryStream ms = new MemoryStream ();
185                 bf.Serialize (ms, tz);
186
187                 ms.Position = 0;
188                 TimeZone clone = (TimeZone) bf.Deserialize (ms);
189
190                 Assert.AreEqual (tz.DaylightName, clone.DaylightName, "DaylightName");
191                 Assert.AreEqual (tz.StandardName, clone.StandardName, "StandardName");
192         }
193
194         static private byte[] serialized_timezone = {
195 #if NET_2_0
196                 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 
197                 0x1C, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6E, 0x74, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x54, 
198                 0x69, 0x6D, 0x65, 0x5A, 0x6F, 0x6E, 0x65, 0x04, 0x00, 0x00, 0x00, 0x17, 0x6D, 0x5F, 0x43, 0x61, 0x63, 0x68, 0x65, 0x64, 0x44, 0x61, 
199                 0x79, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x43, 0x68, 0x61, 0x6E, 0x67, 0x65, 0x73, 0x0D, 0x6D, 0x5F, 0x74, 0x69, 0x63, 0x6B, 0x73, 0x4F, 
200                 0x66, 0x66, 0x73, 0x65, 0x74, 0x0E, 0x6D, 0x5F, 0x73, 0x74, 0x61, 0x6E, 0x64, 0x61, 0x72, 0x64, 0x4E, 0x61, 0x6D, 0x65, 0x0E, 0x6D, 
201                 0x5F, 0x64, 0x61, 0x79, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x4E, 0x61, 0x6D, 0x65, 0x03, 0x00, 0x01, 0x01, 0x1C, 0x53, 0x79, 0x73, 0x74, 
202                 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x73, 0x2E, 0x48, 0x61, 0x73, 0x68, 0x74, 0x61, 0x62, 
203                 0x6C, 0x65, 0x09, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x29, 0x17, 0xD6, 0xFF, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x00, 0x15, 
204                 0x45, 0x61, 0x73, 0x74, 0x65, 0x72, 0x6E, 0x20, 0x53, 0x74, 0x61, 0x6E, 0x64, 0x61, 0x72, 0x64, 0x20, 0x54, 0x69, 0x6D, 0x65, 0x0A, 
205                 0x04, 0x02, 0x00, 0x00, 0x00, 0x1C, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 0x65, 0x63, 0x74, 0x69, 0x6F, 
206                 0x6E, 0x73, 0x2E, 0x48, 0x61, 0x73, 0x68, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x07, 0x00, 0x00, 0x00, 0x0A, 0x4C, 0x6F, 0x61, 0x64, 0x46, 
207                 0x61, 0x63, 0x74, 0x6F, 0x72, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x08, 0x43, 0x6F, 0x6D, 0x70, 0x61, 0x72, 0x65, 0x72, 
208                 0x10, 0x48, 0x61, 0x73, 0x68, 0x43, 0x6F, 0x64, 0x65, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x08, 0x48, 0x61, 0x73, 0x68, 
209                 0x53, 0x69, 0x7A, 0x65, 0x04, 0x4B, 0x65, 0x79, 0x73, 0x06, 0x56, 0x61, 0x6C, 0x75, 0x65, 0x73, 0x00, 0x00, 0x03, 0x03, 0x00, 0x05, 
210                 0x05, 0x0B, 0x08, 0x1C, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x73, 
211                 0x2E, 0x49, 0x43, 0x6F, 0x6D, 0x70, 0x61, 0x72, 0x65, 0x72, 0x24, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 
212                 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x73, 0x2E, 0x49, 0x48, 0x61, 0x73, 0x68, 0x43, 0x6F, 0x64, 0x65, 0x50, 0x72, 0x6F, 0x76, 0x69, 
213                 0x64, 0x65, 0x72, 0x08, 0xEC, 0x51, 0x38, 0x3F, 0x03, 0x00, 0x00, 0x00, 0x0A, 0x0A, 0x0B, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 
214                 0x00, 0x09, 0x05, 0x00, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x08, 0xCC, 0x07, 0x00, 0x00, 0x08, 
215                 0x08, 0xD5, 0x07, 0x00, 0x00, 0x08, 0x08, 0xD2, 0x07, 0x00, 0x00, 0x10, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x09, 0x06, 
216                 0x00, 0x00, 0x00, 0x09, 0x07, 0x00, 0x00, 0x00, 0x09, 0x08, 0x00, 0x00, 0x00, 0x04, 0x06, 0x00, 0x00, 0x00, 0x21, 0x53, 0x79, 0x73, 
217                 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x44, 0x61, 0x79, 0x6C, 
218                 0x69, 0x67, 0x68, 0x74, 0x54, 0x69, 0x6D, 0x65, 0x03, 0x00, 0x00, 0x00, 0x07, 0x6D, 0x5F, 0x73, 0x74, 0x61, 0x72, 0x74, 0x05, 0x6D, 
219                 0x5F, 0x65, 0x6E, 0x64, 0x07, 0x6D, 0x5F, 0x64, 0x65, 0x6C, 0x74, 0x61, 0x00, 0x00, 0x00, 0x0D, 0x0D, 0x0C, 0x00, 0x10, 0xFA, 0x0F, 
220                 0x3D, 0xF2, 0xBC, 0x88, 0x00, 0x50, 0xD5, 0xB1, 0xC1, 0x91, 0xBD, 0x88, 0x00, 0x68, 0xC4, 0x61, 0x08, 0x00, 0x00, 0x00, 0x01, 0x07, 
221                 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x50, 0x23, 0xFA, 0x07, 0x06, 0xC7, 0x88, 0x00, 0xD0, 0xE2, 0xC4, 0x0C, 0xAB, 0xC7, 
222                 0x88, 0x00, 0x68, 0xC4, 0x61, 0x08, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x50, 0x0C, 0x0F, 
223                 0xEF, 0xAB, 0xC3, 0x88, 0x00, 0x90, 0xE7, 0xB0, 0x73, 0x4B, 0xC4, 0x88, 0x00, 0x68, 0xC4, 0x61, 0x08, 0x00, 0x00, 0x00, 0x0B
224 #else
225                 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 
226                 0x1C, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6E, 0x74, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x54, 
227                 0x69, 0x6D, 0x65, 0x5A, 0x6F, 0x6E, 0x65, 0x04, 0x00, 0x00, 0x00, 0x17, 0x6D, 0x5F, 0x43, 0x61, 0x63, 0x68, 0x65, 0x64, 0x44, 0x61, 
228                 0x79, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x43, 0x68, 0x61, 0x6E, 0x67, 0x65, 0x73, 0x0D, 0x6D, 0x5F, 0x74, 0x69, 0x63, 0x6B, 0x73, 0x4F, 
229                 0x66, 0x66, 0x73, 0x65, 0x74, 0x0E, 0x6D, 0x5F, 0x73, 0x74, 0x61, 0x6E, 0x64, 0x61, 0x72, 0x64, 0x4E, 0x61, 0x6D, 0x65, 0x0E, 0x6D, 
230                 0x5F, 0x64, 0x61, 0x79, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x4E, 0x61, 0x6D, 0x65, 0x03, 0x00, 0x01, 0x01, 0x1C, 0x53, 0x79, 0x73, 0x74, 
231                 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x73, 0x2E, 0x48, 0x61, 0x73, 0x68, 0x74, 0x61, 0x62, 
232                 0x6C, 0x65, 0x09, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x29, 0x17, 0xD6, 0xFF, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x00, 0x15, 
233                 0x45, 0x61, 0x73, 0x74, 0x65, 0x72, 0x6E, 0x20, 0x53, 0x74, 0x61, 0x6E, 0x64, 0x61, 0x72, 0x64, 0x20, 0x54, 0x69, 0x6D, 0x65, 0x0A, 
234                 0x04, 0x02, 0x00, 0x00, 0x00, 0x1C, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 0x65, 0x63, 0x74, 0x69, 0x6F, 
235                 0x6E, 0x73, 0x2E, 0x48, 0x61, 0x73, 0x68, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x07, 0x00, 0x00, 0x00, 0x0A, 0x4C, 0x6F, 0x61, 0x64, 0x46, 
236                 0x61, 0x63, 0x74, 0x6F, 0x72, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x08, 0x43, 0x6F, 0x6D, 0x70, 0x61, 0x72, 0x65, 0x72, 
237                 0x10, 0x48, 0x61, 0x73, 0x68, 0x43, 0x6F, 0x64, 0x65, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x08, 0x48, 0x61, 0x73, 0x68, 
238                 0x53, 0x69, 0x7A, 0x65, 0x04, 0x4B, 0x65, 0x79, 0x73, 0x06, 0x56, 0x61, 0x6C, 0x75, 0x65, 0x73, 0x00, 0x00, 0x03, 0x03, 0x00, 0x05, 
239                 0x05, 0x0B, 0x08, 0x1C, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x73, 
240                 0x2E, 0x49, 0x43, 0x6F, 0x6D, 0x70, 0x61, 0x72, 0x65, 0x72, 0x24, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 
241                 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x73, 0x2E, 0x49, 0x48, 0x61, 0x73, 0x68, 0x43, 0x6F, 0x64, 0x65, 0x50, 0x72, 0x6F, 0x76, 0x69, 
242                 0x64, 0x65, 0x72, 0x08, 0xEC, 0x51, 0x38, 0x3F, 0x02, 0x00, 0x00, 0x00, 0x0A, 0x0A, 0x0B, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 
243                 0x00, 0x09, 0x05, 0x00, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x08, 0xCC, 0x07, 0x00, 0x00, 0x08, 
244                 0x08, 0xD2, 0x07, 0x00, 0x00, 0x10, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x09, 0x06, 0x00, 0x00, 0x00, 0x09, 0x07, 0x00, 
245                 0x00, 0x00, 0x04, 0x06, 0x00, 0x00, 0x00, 0x21, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x69, 
246                 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x44, 0x61, 0x79, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x54, 0x69, 0x6D, 0x65, 0x03, 0x00, 0x00, 
247                 0x00, 0x07, 0x6D, 0x5F, 0x73, 0x74, 0x61, 0x72, 0x74, 0x05, 0x6D, 0x5F, 0x65, 0x6E, 0x64, 0x07, 0x6D, 0x5F, 0x64, 0x65, 0x6C, 0x74, 
248                 0x61, 0x00, 0x00, 0x00, 0x0D, 0x0D, 0x0C, 0x00, 0x10, 0xFA, 0x0F, 0x3D, 0xF2, 0xBC, 0x08, 0x00, 0x50, 0xD5, 0xB1, 0xC1, 0x91, 0xBD, 
249                 0x08, 0x00, 0x68, 0xC4, 0x61, 0x08, 0x00, 0x00, 0x00, 0x01, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x50, 0x0C, 0x0F, 
250                 0xEF, 0xAB, 0xC3, 0x08, 0x00, 0x90, 0xE7, 0xB0, 0x73, 0x4B, 0xC4, 0x08, 0x00, 0x68, 0xC4, 0x61, 0x08, 0x00, 0x00, 0x00, 0x0B
251 #endif
252         };
253
254         [Test]
255         [Category ("NotWorking")] 
256         // 1.x - deserialize but strings are null
257         // 2.x - eexception when creating a datetime with a negative value
258         public void DeserializeKnownValue ()
259         {
260                 MemoryStream ms = new MemoryStream (serialized_timezone);
261                 BinaryFormatter bf = new BinaryFormatter ();
262                 TimeZone tz = (TimeZone) bf.Deserialize (ms);
263                 Assert.AreEqual ("Eastern Daylight Time", tz.DaylightName, "DaylightName");
264                 Assert.AreEqual ("Eastern Standard Time", tz.StandardName, "StandardName");
265         }
266
267         [Test]
268         public void ToLocalTimeAtDSTBoundaries ()
269         {
270                 TimeZone tz = TimeZone.CurrentTimeZone;
271                 DateTime dst_start_utc = tz.GetDaylightChanges(2007).Start.ToUniversalTime ();
272
273                 if (dst_start_utc == DateTime.MinValue)
274                         Assert.Ignore ("Couldn't get beginning of daylight saving time in 2007.");
275                 Assert.IsTrue (tz.ToLocalTime (dst_start_utc.Subtract (new TimeSpan (0, 1, 0))) < tz.ToLocalTime (dst_start_utc), "0:1:59 < 0:3:00");
276                 Assert.IsTrue (tz.ToLocalTime (dst_start_utc) < tz.ToLocalTime (dst_start_utc.Add (new TimeSpan (0, 1, 0))), "0:3:00 < 0:3:01");
277                 Assert.IsTrue (tz.ToLocalTime (dst_start_utc.Add (new TimeSpan (0, 1, 0))) < tz.ToLocalTime (dst_start_utc.Add (new TimeSpan (0, 59, 0))), "0:3:01 < 0:3:59");
278                 Assert.IsTrue (tz.ToLocalTime (dst_start_utc.Add (new TimeSpan (0, 59, 0))) < tz.ToLocalTime (dst_start_utc.Add (new TimeSpan (1, 0, 0))), "0:3:59 < 0:4:00");
279                 Assert.IsTrue (tz.ToLocalTime (dst_start_utc.Add (new TimeSpan (1, 0, 0))) < tz.ToLocalTime (dst_start_utc.Add (new TimeSpan (1, 1, 0))), "0:4:00 < 0:4:01");
280         }
281
282                 [Test]
283                 public void GetUtcOffsetAtDSTBoundary ()
284                 {
285                         /*
286                          * Getting a definitive list of timezones which do or don't observe Daylight
287                          * Savings is difficult (can't say America's or USA definitively) and lengthy see 
288                          *
289                          * http://en.wikipedia.org/wiki/Daylight_saving_time_by_country
290                          *
291                          * as a good starting point for a list.
292                          *
293                          * The following are SOME of the timezones/regions which do support daylight savings.
294                          *
295                          * Pacific/Auckland
296                          * Pacific/Sydney
297                          * USA (EST, CST, MST, PST, AKST) note this does not cover all states or regions
298                          * Europe/London (GMT)
299                          * CET (member states of the European Union)
300                          *
301                          * This test should work in all the above timezones
302                          */
303
304
305                         TimeZone tz = TimeZone.CurrentTimeZone;
306                         int year = DateTime.Now.Year;
307                         DaylightTime daylightChanges = tz.GetDaylightChanges(year);
308                         DateTime dst_end = daylightChanges.End;
309
310                         if (dst_end == DateTime.MinValue)
311                                 Assert.Ignore (tz.StandardName + " did not observe daylight saving time during " + year + ".");
312
313                         var standardOffset = tz.GetUtcOffset(daylightChanges.Start.AddMinutes(-1));
314
315                         Assert.AreEqual(standardOffset, tz.GetUtcOffset (dst_end));
316                         Assert.AreEqual(standardOffset, tz.GetUtcOffset (dst_end.Add (daylightChanges.Delta.Negate ().Add (TimeSpan.FromSeconds(1)))));
317                         Assert.AreEqual(standardOffset, tz.GetUtcOffset (dst_end.Add(daylightChanges.Delta.Negate ())));
318                         Assert.AreNotEqual(standardOffset, tz.GetUtcOffset (dst_end.Add(daylightChanges.Delta.Negate ().Add (TimeSpan.FromSeconds(-1)))));
319                 }
320
321
322                 [Test]
323                 public void StaticProperties ()
324                 {
325                         Assert.IsNotNull (TimeZoneInfo.Local, "Local");
326                         Assert.IsNotNull (TimeZoneInfo.Utc, "Utc");
327                 }
328                 
329                 [Test]
330                 public void FindSystemTimeZoneById ()
331                 {
332                         TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById ("Canada/Eastern");
333                         Assert.AreEqual ("EDT", tzi.DaylightName, "DaylightName");
334                         Assert.AreEqual ("EST", tzi.StandardName, "StandardName");
335                         Assert.IsTrue (tzi.SupportsDaylightSavingTime, "SupportsDaylightSavingTime");
336                 }
337
338 #if MOBILE
339                 // On device we cannot read the OS file system to look for /etc/localtime
340                 // and /usr/share/zoneinfo - so we must initialize the BCL TimeZoneInfo
341                 // from NSTimeZoneInfo. The tests here check the code paths between the
342                 // two types - if they break then TimeZoneInfo work work at all
343                 // ref: http://bugzilla.xamarin.com/show_bug.cgi?id=1790
344                 
345                 bool incomplete_data_on_simulator_only_bug;
346
347                 [Test]
348                 public void GetSystemTimeZones ()
349                 {
350                         // if test is executed a second time then it report less than 400 (about 127) items available
351                         if (incomplete_data_on_simulator_only_bug)
352                                 Assert.Ignore ("known to fail on some iOS simulator versions - see source comments");
353                         
354                         try {
355                                 Assert.That (TimeZoneInfo.GetSystemTimeZones ().Count, Is.GreaterThan (400), "GetSystemTimeZones");
356                         } catch (NullReferenceException) {
357                                 // that's a weird one. It failed on iOS 5.1 *beta* simulator (on Lion) but it worked on *final*
358                                 // now it fails on Snow Leopard the same way (incomplete data) with iOS5 simulator (OS update ?)
359                                 // but it *never*ever* failed on devices
360                                 incomplete_data_on_simulator_only_bug = true;
361 #if XAMCORE_2_0
362                                 if (ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.SIMULATOR)
363 #else
364                                 if (MonoTouch.ObjCRuntime.Runtime.Arch == MonoTouch.ObjCRuntime.Arch.SIMULATOR)
365 #endif
366                                         Assert.Ignore ("known to fail on some iOS simulator versions - see source comments");
367                         }
368                 }
369 #endif
370         }
371 }