Skip to content

Commit a3d0a07

Browse files
committed
Added support for basic DateTimeFormat
1 parent 4d723ed commit a3d0a07

File tree

6 files changed

+278
-17
lines changed

6 files changed

+278
-17
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Cosmos.TestRunner;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Cosmos.Compiler.Tests.Bcl.System
9+
{
10+
class DateTimeFormatTest
11+
{
12+
public static void Execute()
13+
{
14+
DateTime date = new DateTime(2011, 6, 10);
15+
Assert.AreEqual("06/10/2011 00:00:00", date.ToString(), "Standard DateTime.ToString works");
16+
//Assert.AreEqual("June 10, 2011", date.ToString("MMMM dd, yyyy"), "Using DataTimeFormat for custom format works");
17+
}
18+
}
19+
}

source/Cosmos.Core_Plugs/Interop/GlobalizationImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class GlobalizationImpl
1111
[PlugMethod(Signature = "System_Int32__Interop_Globalization_LoadICU__")]
1212
public static int LoadICU()
1313
{
14-
throw new NotImplementedException();
14+
return 0; //this is required for at least DateTimeFormat
1515
}
1616
[PlugMethod(Signature = "System_Void__Interop_Globalization_ChangeCase_System_Char___System_Int32__System_Char___System_Int32__System_Boolean_")]
1717
public static unsafe void ChangeCase(char* aChar, int aInt, char* aChar2, int aInt2, bool Bool)

source/Cosmos.Core_Plugs/System/Globalization/CultureInfoImpl.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ namespace Cosmos.Core_Plugs.System.Globalization
88
[Plug(Target = typeof(CultureInfo))]
99
public static class CultureInfoImpl
1010
{
11-
public static void CCtor()
11+
public static void CCtor(CultureInfo aThis, [FieldAccess(Name = "System.Boolean System.Globalization.CultureInfo._isInherited")] ref bool aIsInherited)
1212
{
13+
aIsInherited = false;
1314
}
1415

1516
public static CultureInfo get_CurrentCulture() => CultureInfo.InvariantCulture;
@@ -26,19 +27,14 @@ public static bool Equals(CultureInfo aThis, object value)
2627

2728
public static CultureInfo GetCultureInfo(string name) => null;
2829

29-
public static object GetFormat(CultureInfo aThis, Type type)
30-
{
31-
throw new NotImplementedException();
32-
}
33-
34-
public static DateTimeFormatInfo get_DateTimeFormat(CultureInfo aThis)
30+
public static CultureInfo get_Parent(CultureInfo aThis)
3531
{
3632
throw new NotImplementedException();
3733
}
3834

39-
public static CultureInfo get_Parent(CultureInfo aThis)
35+
public static string GetUserDefaultLocaleName()
4036
{
41-
throw new NotImplementedException();
37+
return "GetUserDefaultLocaleName is not implemented";
4238
}
4339
}
4440
}
Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using IL2CPU.API.Attribs;
1+
using IL2CPU.API.Attribs;
72

83
namespace Cosmos.Core_Plugs.System.Globalization
94
{
@@ -15,9 +10,79 @@ public static string get_DecimalSeparator(global::System.Globalization.DateTimeF
1510
return ".";
1611
}
1712

13+
public static string get_TimeSeparator(global::System.Globalization.DateTimeFormatInfo aThis)
14+
{
15+
return ":";
16+
}
17+
public static string get_ShortDatePattern(global::System.Globalization.DateTimeFormatInfo aThis)
18+
{
19+
return "h:mm tt";
20+
}
21+
22+
public static string get_LongTimePattern(global::System.Globalization.DateTimeFormatInfo aThis)
23+
{
24+
return "h:mm:ss tt";
25+
}
26+
27+
public static string get_AMDesignator(global::System.Globalization.DateTimeFormatInfo aThis)
28+
{
29+
return "AM";
30+
}
31+
32+
public static string get_PMDesignator(global::System.Globalization.DateTimeFormatInfo aThis)
33+
{
34+
return "PM";
35+
}
36+
37+
public static string[] get_AbbreviatedDayNames(global::System.Globalization.DateTimeFormatInfo aThis)
38+
{
39+
return new[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
40+
}
41+
1842
public static string[] get_AbbreviatedMonthNames(global::System.Globalization.DateTimeFormatInfo aThis)
1943
{
2044
return new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "" }; // its 13 for some reason
2145
}
46+
47+
[PlugMethod(Signature = "System_Array_System_Globalization_CalendarId_System_Globalization_DateTimeFormatInfo__get_OptionalCalendars")]
48+
public static ushort[] get_OptionalCalendars(global::System.Globalization.DateTimeFormatInfo aThis)
49+
{
50+
return new ushort[] { 1 }; // 1 is Gregorian
51+
}
52+
53+
public static string get_MonthDayPattern(global::System.Globalization.DateTimeFormatInfo aThis)
54+
{
55+
return "MMMM dd";
56+
}
57+
58+
public static string GetEraName(global::System.Globalization.DateTimeFormatInfo aThis, int aInt)
59+
{
60+
return "C.E.";
61+
}
62+
63+
public static string[] InternalGetGenitiveMonthNames(global::System.Globalization.DateTimeFormatInfo aThis, bool aBool)
64+
{
65+
return new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "" }; // its 13 for some reason
66+
}
67+
68+
public static string[] InternalGetLeapYearMonthNames(global::System.Globalization.DateTimeFormatInfo aThis)
69+
{
70+
return new string[0];
71+
}
72+
73+
public static string[] InternalGetAbbreviatedMonthNames(global::System.Globalization.DateTimeFormatInfo aThis)
74+
{
75+
return new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "" }; // its 13 for some reason
76+
}
77+
78+
public static string[] InternalGetAbbreviatedDayOfWeekNames(global::System.Globalization.DateTimeFormatInfo aThis)
79+
{
80+
return new[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
81+
}
82+
83+
public static string[] InternalGetDayOfWeekNames(global::System.Globalization.DateTimeFormatInfo aThis)
84+
{
85+
return new[] { "Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday" };
86+
}
2287
}
2388
}

source/Cosmos.System2_Plugs/System/Globalization/CalendarDataImpl.cs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,72 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using Cosmos.Debug.Kernel;
67
using IL2CPU.API.Attribs;
78

89
namespace Cosmos.System_Plugs.System.Globalization
910
{
11+
internal enum CalendarDataType
12+
{
13+
Uninitialized,
14+
NativeName,
15+
MonthDay,
16+
ShortDates,
17+
LongDates,
18+
YearMonths,
19+
DayNames,
20+
AbbrevDayNames,
21+
MonthNames,
22+
AbbrevMonthNames,
23+
SuperShortDayNames,
24+
MonthGenitiveNames,
25+
AbbrevMonthGenitiveNames,
26+
EraNames,
27+
AbbrevEraNames
28+
}
29+
1030
[Plug("System.Globalization.CalendarData, System.Private.CoreLib")]
1131
class CalendarDataImpl
1232
{
1333
[PlugMethod(Signature = "System_Boolean__System_Globalization_CalendarData_GetCalendarInfo__System_String_System_Globalization_CalendarId_System_Globalization_CalendarDataType_System_String__")]
14-
public unsafe static bool GetCalendarInfo(string localeName, object calendarId, object dataType, out string calendarString)
34+
public unsafe static bool GetCalendarInfo(string localeName, object calendarId, CalendarDataType aDataType, out string calendarString)
1535
{
36+
switch (aDataType)
37+
{
38+
case CalendarDataType.Uninitialized:
39+
break;
40+
case CalendarDataType.NativeName:
41+
break;
42+
case CalendarDataType.MonthDay:
43+
break;
44+
case CalendarDataType.ShortDates:
45+
break;
46+
case CalendarDataType.LongDates:
47+
break;
48+
case CalendarDataType.YearMonths:
49+
break;
50+
case CalendarDataType.DayNames:
51+
break;
52+
case CalendarDataType.AbbrevDayNames:
53+
break;
54+
case CalendarDataType.MonthNames:
55+
break;
56+
case CalendarDataType.AbbrevMonthNames:
57+
break;
58+
case CalendarDataType.SuperShortDayNames:
59+
break;
60+
case CalendarDataType.MonthGenitiveNames:
61+
break;
62+
case CalendarDataType.AbbrevMonthGenitiveNames:
63+
break;
64+
case CalendarDataType.EraNames:
65+
break;
66+
case CalendarDataType.AbbrevEraNames:
67+
break;
68+
default:
69+
break;
70+
}
71+
Debugger.DoSendNumber((int)aDataType);
1672
throw new NotImplementedException();
1773
}
1874
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using IL2CPU.API.Attribs;
8+
9+
namespace Cosmos.System_Plugs.System.Globalization
10+
{
11+
[Plug("System.Globalization.CultureData, System.Private.CoreLib")]
12+
class CultureDataImpl
13+
{
14+
public static string get_TimeSeparator(object aThis)
15+
{
16+
return ":";
17+
}
18+
19+
public static string get_AMDesignator(object aThis)
20+
{
21+
return "AM";
22+
}
23+
24+
public static string get_PMDesignator(object aThis)
25+
{
26+
return "PM";
27+
}
28+
29+
public static string[] get_LongTimes(object aThis)
30+
{
31+
return new string[] { "h:mm:ss tt" };
32+
}
33+
34+
[PlugMethod(Signature = "System_String____System_Globalization_CultureData_LongDates_System_Globalization_CalendarId_")]
35+
public static string[] LongDates(object aThis, ushort aCalendarId)
36+
{
37+
return new string[] { "MM/dd/yyyy" };
38+
}
39+
40+
[PlugMethod(Signature = "System_String____System_Globalization_CultureData_ShortDates_System_Globalization_CalendarId_")]
41+
public static string[] ShortDates(object aThis, ushort aCalendarId)
42+
{
43+
return new string[] { "MM/dd/yyyy" };
44+
}
45+
46+
[PlugMethod(Signature = "System_String____System_Globalization_CultureData_YearMonths_System_Globalization_CalendarId_")]
47+
public static string[] YearMonths(object aThis, ushort aCalendarId)
48+
{
49+
return new string[] { "MMMM dd" };
50+
}
51+
52+
public static string[] get_ShortTimes(object aThis)
53+
{
54+
return new string[] { "h:mm tt" };
55+
}
56+
57+
58+
public static int get_FirstDayOfWeek(object aThis)
59+
{
60+
return 0; // Sunday is 0 and standard value
61+
}
62+
63+
public static int get_CalendarWeekRule(object aThis)
64+
{
65+
return 0; // FirstDay is 0 and standard value
66+
}
67+
68+
[PlugMethod(Signature = "System_String____System_Globalization_CultureData_MonthNames_System_Globalization_CalendarId_")]
69+
public static string[] MonthNames(object aThis, ushort aCalendarId)
70+
{
71+
return new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "" };
72+
}
73+
74+
[PlugMethod(Signature = "System_String__System_Globalization_CultureData_GetLocaleInfoCoreUserOverride__System_Globalization_CultureData_LocaleStringData")]
75+
public static string GetLocaleInfoCoreUserOverride(object aThis, uint aLocaleStringData)
76+
{
77+
throw new NotImplementedException("GetLocaleInfoCoreUserOverride");
78+
}
79+
80+
public static int GetLocaleInfoExInt(string aString, uint aUint)
81+
{
82+
throw new NotImplementedException("GetLocaleInfoExInt");
83+
}
84+
85+
public static string get_PercentSymbol(object aThis)
86+
{
87+
return "%";
88+
}
89+
90+
public static string get_PerMilleSymbol(object aThis)
91+
{
92+
return "‰";
93+
}
94+
95+
public static string get_NegativeInfinitySymbol(object aThis)
96+
{
97+
return "-Infinity";
98+
}
99+
100+
public static string get_PositiveInfinitySymbol(object aThis)
101+
{
102+
return "Infinity";
103+
}
104+
105+
public static string get_NaNSymbol(object aThis)
106+
{
107+
return "NaN";
108+
}
109+
110+
public static int[] get_NumberGroupSizes(object aThis)
111+
{
112+
return new int[] { 3 };
113+
}
114+
115+
public static int[] get_CurrencyGroupSizes(object aThis)
116+
{
117+
return new int[] { 3 };
118+
}
119+
120+
public static Calendar get_DefaultCalendar(object aThis)
121+
{
122+
return new GregorianCalendar();
123+
}
124+
}
125+
}

0 commit comments

Comments
 (0)