2 // DateTimeFormatInfo.cs
5 // Ben Maurer <bmaurer@andrew.cmu.edu>
7 // Copyright (C) 2005 Novell (http://www.novell.com)
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.
30 using NUnit
.Framework
;
32 using System
.Globalization
;
35 namespace MonoTests
.System
.Globalization
38 public class DateTimeFormatInfoTest
41 public void GetAllDateTimePatterns_ret_diff_obj ()
43 // We need to return different objects for security reasons
44 DateTimeFormatInfo dtfi
= CultureInfo
.InvariantCulture
.DateTimeFormat
;
46 string [] one
= dtfi
.GetAllDateTimePatterns ();
47 string [] two
= dtfi
.GetAllDateTimePatterns ();
48 Assert
.IsTrue (one
!= two
);
52 public void EraName ()
54 CultureInfo en_US
= new CultureInfo ("en-US");
55 DateTimeFormatInfo dtfi
= en_US
.DateTimeFormat
;
56 Assert
.AreEqual ("AD", dtfi
.GetAbbreviatedEraName (0), "#1");
57 Assert
.AreEqual ("A.D.", dtfi
.GetEraName (1), "#2");
58 Assert
.AreEqual (1, dtfi
.GetEra ("A.D."), "#3");
59 Assert
.AreEqual (1, dtfi
.GetEra ("AD"), "#4");
60 Assert
.AreEqual (-1, dtfi
.GetEra ("C.E"), "#5");
61 Assert
.AreEqual (-1, dtfi
.GetEra ("Common Era"), "#6");
65 public void MonthNames ()
67 CultureInfo c
= CultureInfo
.CreateSpecificCulture ("en");
68 string [] monthNamesA
= c
.DateTimeFormat
.MonthNames
;
69 Assert
.AreEqual (13, monthNamesA
.Length
, "#A1");
70 Assert
.AreEqual ("January", monthNamesA
[0], "#A2");
71 Assert
.AreEqual ("February", monthNamesA
[1], "#A3");
72 Assert
.AreEqual ("March", monthNamesA
[2], "#A4");
73 Assert
.AreEqual ("April", monthNamesA
[3], "#A5");
74 Assert
.AreEqual ("May", monthNamesA
[4], "#A6");
75 Assert
.AreEqual ("June", monthNamesA
[5], "#A7");
76 Assert
.AreEqual ("July", monthNamesA
[6], "#A8");
77 Assert
.AreEqual ("August", monthNamesA
[7], "#A9");
78 Assert
.AreEqual ("September", monthNamesA
[8], "#A10");
79 Assert
.AreEqual ("October", monthNamesA
[9], "#A11");
80 Assert
.AreEqual ("November", monthNamesA
[10], "#A12");
81 Assert
.AreEqual ("December", monthNamesA
[11], "#A13");
82 Assert
.AreEqual (string.Empty
, monthNamesA
[12], "#A14");
84 c
.DateTimeFormat
.MonthNames
= c
.DateTimeFormat
.MonthNames
;
86 string [] monthNamesB
= c
.DateTimeFormat
.MonthNames
;
87 Assert
.AreEqual (monthNamesA
, monthNamesB
, "#B1");
88 Assert
.IsFalse (object.ReferenceEquals (monthNamesA
, monthNamesB
), "#B2");
92 public void TestSpecificCultureFormats_es_ES ()
94 CultureInfo ci
= new CultureInfo ("es-ES");
95 DateTimeFormatInfo di
= ci
.DateTimeFormat
;
96 Assert
.AreEqual ("dddd, dd' de 'MMMM' de 'yyyy", di
.LongDatePattern
, "#1");
97 Assert
.AreEqual ("H:mm:ss", di
.LongTimePattern
, "#2");
98 Assert
.AreEqual ("dddd, dd' de 'MMMM' de 'yyyy H:mm:ss", di
.FullDateTimePattern
, "#3");
99 Assert
.AreEqual ("MMMM' de 'yyyy", di
.YearMonthPattern
, "#4");
100 Assert
.AreEqual ("dd MMMM", di
.MonthDayPattern
, "#5");
105 public void Bug78569 ()
107 DateTime dt
= DateTime
.Now
;
108 CultureInfo ci
= new CultureInfo ("en-GB");
109 string s
= dt
.ToString (ci
);
110 DateTime dt2
= DateTime
.Parse (s
, ci
);
111 Assert
.AreEqual (dt
.Month
, dt2
.Month
);