Skip to content

Commit

Permalink
Use named fields for days and months versions. Updated readme and demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinitiesLoop committed Jun 3, 2010
1 parent c6f786b commit 10e570f
Show file tree
Hide file tree
Showing 682 changed files with 10,043 additions and 3,436 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -296,19 +296,19 @@ jQuery.cultures.invariant = {
':': ":",
// the first day of the week (0 = Sunday, 1 = Monday, etc)
firstDay: 0,
days: [
days: {
// full day names
["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
names: ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
// abbreviated day names
["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],
namesAbbr: ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],
// shortest day names
["Su","Mo","Tu","We","Th","Fr","Sa"]
],
namesShort: ["Su","Mo","Tu","We","Th","Fr","Sa"]
},
months: [
// full month names (13 months for lunar calendars -- 13th month should be "" if not lunar)
["January","February","March","April","May","June","July","August","September","October","November","December",""],
names: ["January","February","March","April","May","June","July","August","September","October","November","December",""],
// abbreviated month names
["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""]
namesAbbr: ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""]
],
// AM and PM designators in one of these forms:
// The usual view, and the upper and lower case versions
Expand Down Expand Up @@ -421,7 +421,7 @@ Parsing with parseInt and parseFloat also accepts any of these formats.
<a name="dates"></a>
<h2 id="dates">Date Formatting</h2>
<p>
Date formatting varies wildly by culture, not just in the spelling of month and day names, and the date separator, but by the expected order of the various date components, whether to use a 12 or 24 hour clock, and how months and days are abbreivated. Many cultures even include "genative" month names, which are different from the typical names and are used only in certain cases.
Date formatting varies wildly by culture, not just in the spelling of month and day names, and the date separator, but by the expected order of the various date components, whether to use a 12 or 24 hour clock, and how months and days are abbreivated. Many cultures even include "genitive" month names, which are different from the typical names and are used only in certain cases.
</p>
<p>
Also, each culture has a set of "standard" or "typical" formats. For example, in en-US, when displaying a date in its fullest form, it looks like "Saturday, November 05, 1955". Note the non-abbreivated day and month name, the zero padded date, and four digit year. So, jQuery.glob.js defines a certain set of "standard" formatting strings for dates that are aliases to the specific formats for the culture. See the 2nd table below for the meaning of each token in the en-US examples.
Expand Down
22 changes: 16 additions & 6 deletions demo/demo.html
Expand Up @@ -129,7 +129,7 @@
<td>Days</td>
<td colspan="3">
<ol>
{{each days[0]}}
{{each days.names}}
<li>{{=}}</li>
{{/each}}
</ol>
Expand All @@ -139,7 +139,17 @@
<td>Days (abbreviated)</td>
<td colspan="3">
<ol>
{{each days[1]}}
{{each days.namesAbbr}}
<li>{{=}}</li>
{{/each}}
</ol>
</td>
</tr>
<tr>
<td>Days (shortest)</td>
<td colspan="3">
<ol>
{{each days.namesShort}}
<li>{{=}}</li>
{{/each}}
</ol>
Expand All @@ -149,7 +159,7 @@
<td>Months</td>
<td colspan="3">
<ol>
{{each months[0]}}
{{each months.names}}
<li>{{=}}</li>
{{/each}}
</ol>
Expand All @@ -159,7 +169,7 @@
<td>Months (abbreviated)</td>
<td colspan="3">
<ol>
{{each months[1]}}
{{each months.namesAbbr}}
<li>{{=}}</li>
{{/each}}
</ol>
Expand All @@ -168,9 +178,9 @@
{{if typeof monthsGenitive !== 'undefined'}}
<tr>
<td>Months (Genitive)</td>
<td>${monthsGenitive[0]}</td>
<td>${monthsGenitive.names}</td>
<td>Months (Abbr. Gen.)</td>
<td>${monthsGenitive[1]}</td>
<td>${monthsGenitive.namesAbbr}</td>
</tr>
{{/if}}
<tr>
Expand Down
59 changes: 37 additions & 22 deletions generator/Program.cs
Expand Up @@ -148,18 +148,12 @@ public class GlobalizationInfo {
var df = culture.DateTimeFormat;
var info = new GlobalizationInfo.DateFormatInfo {
name = calendarName,
months = new string[][] {
df.MonthNames,
df.AbbreviatedMonthNames
},
monthsGenitive = new string[][] {
df.MonthGenitiveNames,
df.AbbreviatedMonthGenitiveNames
},
months = new DateFormatInfo.MonthInfo { names = df.MonthNames, namesAbbr = df.AbbreviatedMonthNames },
monthsGenitive = new DateFormatInfo.MonthInfo { names = df.MonthGenitiveNames, namesAbbr = df.AbbreviatedMonthGenitiveNames },
firstDay = (int) df.FirstDayOfWeek,
dateSeparator = df.DateSeparator,
timeSeparator = df.TimeSeparator,
days = new string[][] { df.DayNames, df.AbbreviatedDayNames, df.ShortestDayNames },
days = new DateFormatInfo.DayInfo { names = df.DayNames, namesAbbr = df.AbbreviatedDayNames, namesShort = df.ShortestDayNames },
eras = GetEraInfo(culture),
twoDigitYearMax = df.Calendar.TwoDigitYearMax,
patterns = GetPatterns(df)
Expand Down Expand Up @@ -318,9 +312,10 @@ public class GlobalizationInfo {
cal["convert"] = pair.Value.convertScriptBlock;
}
// remove redundant monthsGenitive array if it is equivilent to months
ArrayList months = cal.ContainsKey("months") ? (ArrayList)cal["months"] : null;
ArrayList monthsGenitive = cal.ContainsKey("monthsGenitive") ? (ArrayList)cal["monthsGenitive"] : null;
if (months != null && monthsGenitive != null && ListEquality((ArrayList)monthsGenitive[0], (ArrayList)months[0]) && ListEquality((ArrayList)monthsGenitive[1], (ArrayList)months[1])) {
Dictionary<String, Object> months = cal.ContainsKey("months") ? (Dictionary<String, Object>)cal["months"] : null;
Dictionary<String, Object> monthsGenitive = cal.ContainsKey("monthsGenitive") ? (Dictionary<String, Object>)cal["monthsGenitive"] : null;
Dictionary<String, Object> diff = (months != null && monthsGenitive != null) ? DiffGlobInfos(months, monthsGenitive) : null;
if (diff != null && diff.Count == 0) {
// the genitive months are the same as months, so remove it since it's optional
cal.Remove("monthsGenitive");
}
Expand Down Expand Up @@ -351,6 +346,11 @@ public class GlobalizationInfo {
}})(jQuery);", name, cultureFragment);
}

private static string Serialize(object value) {
// no need to escape single quotes
return _jss.Serialize(value).Replace("\\u0027", "'");
}

private static string ToJavaScript(CultureInfo culture, Dictionary<String, Object> dictionary, int level, bool isCalendars) {
StringBuilder sb = new StringBuilder();
string padding = _padding.Substring(0, level * 4);
Expand All @@ -372,25 +372,25 @@ public class GlobalizationInfo {
sb.AppendFormat("{0}convert: {{\n{1}\n{0}}}", padding, pair.Value);
}
else if (pair.Key.Equals("groupSeparator")) {
sb.AppendFormat("{0}',': {1}", padding, _jss.Serialize(pair.Value));
sb.AppendFormat("{0}',': {1}", padding, Serialize(pair.Value));
}
else if (pair.Key.Equals("decimalSeparator")) {
sb.AppendFormat("{0}'.': {1}", padding, _jss.Serialize(pair.Value));
sb.AppendFormat("{0}'.': {1}", padding, Serialize(pair.Value));
}
else if (pair.Key.Equals("positive")) {
sb.AppendFormat("{0}'+': {1}", padding, _jss.Serialize(pair.Value));
sb.AppendFormat("{0}'+': {1}", padding, Serialize(pair.Value));
}
else if (pair.Key.Equals("negative")) {
sb.AppendFormat("{0}'-': {1}", padding, _jss.Serialize(pair.Value));
sb.AppendFormat("{0}'-': {1}", padding, Serialize(pair.Value));
}
else if (pair.Key.Equals("dateSeparator")) {
sb.AppendFormat("{0}'/': {1}", padding, _jss.Serialize(pair.Value));
sb.AppendFormat("{0}'/': {1}", padding, Serialize(pair.Value));
}
else if (pair.Key.Equals("timeSeparator")) {
sb.AppendFormat("{0}':': {1}", padding, _jss.Serialize(pair.Value));
sb.AppendFormat("{0}':': {1}", padding, Serialize(pair.Value));
}
else {
sb.AppendFormat("{0}{1}: {2}", padding, pair.Key, _jss.Serialize(pair.Value));
sb.AppendFormat("{0}{1}: {2}", padding, pair.Key, Serialize(pair.Value));
}
}
return sb.ToString();
Expand Down Expand Up @@ -493,9 +493,12 @@ public class DateFormatInfo {
public string dateSeparator;
public string timeSeparator;
public int firstDay;
public string[][] days;
public string[][] months;
public string[][] monthsGenitive;
public DayInfo days;
//public string[][] days;
public MonthInfo months;
public MonthInfo monthsGenitive;
//public string[][] months;
//public string[][] monthsGenitive;
public string[] AM;
public string[] PM;
public EraInfo[] eras;
Expand All @@ -508,7 +511,19 @@ public class EraInfo {
public long? start;
public long offset;
}

public class MonthInfo {
public string[] names;
public string[] namesAbbr;
}

public class DayInfo {
public string[] names;
public string[] namesAbbr;
public string[] namesShort;
}
}

}

public class Program {
Expand Down
11 changes: 9 additions & 2 deletions globinfo/jQuery.glob.af-ZA.js
Expand Up @@ -19,8 +19,15 @@
calendars: {
standard: $.extend(true, {}, standard, {
name: "Gregorian_Localized",
days: [["Sondag","Maandag","Dinsdag","Woensdag","Donderdag","Vrydag","Saterdag"],["Son","Maan","Dins","Woen","Dond","Vry","Sat"],["So","Ma","Di","Wo","Do","Vr","Sa"]],
months: [["Januarie","Februarie","Maart","April","Mei","Junie","Julie","Augustus","September","Oktober","November","Desember",""],["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Aug","Sep","Okt","Nov","Des",""]],
days: {
names: ["Sondag","Maandag","Dinsdag","Woensdag","Donderdag","Vrydag","Saterdag"],
namesAbbr: ["Son","Maan","Dins","Woen","Dond","Vry","Sat"],
namesShort: ["So","Ma","Di","Wo","Do","Vr","Sa"]
},
months: {
names: ["Januarie","Februarie","Maart","April","Mei","Junie","Julie","Augustus","September","Oktober","November","Desember",""],
namesAbbr: ["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Aug","Sep","Okt","Nov","Des",""]
},
patterns: {
d: "yyyy/MM/dd",
D: "dd MMMM yyyy",
Expand Down
2 changes: 1 addition & 1 deletion globinfo/jQuery.glob.af-ZA.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions globinfo/jQuery.glob.af.js
Expand Up @@ -19,8 +19,15 @@
calendars: {
standard: $.extend(true, {}, standard, {
name: "Gregorian_Localized",
days: [["Sondag","Maandag","Dinsdag","Woensdag","Donderdag","Vrydag","Saterdag"],["Son","Maan","Dins","Woen","Dond","Vry","Sat"],["So","Ma","Di","Wo","Do","Vr","Sa"]],
months: [["Januarie","Februarie","Maart","April","Mei","Junie","Julie","Augustus","September","Oktober","November","Desember",""],["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Aug","Sep","Okt","Nov","Des",""]],
days: {
names: ["Sondag","Maandag","Dinsdag","Woensdag","Donderdag","Vrydag","Saterdag"],
namesAbbr: ["Son","Maan","Dins","Woen","Dond","Vry","Sat"],
namesShort: ["So","Ma","Di","Wo","Do","Vr","Sa"]
},
months: {
names: ["Januarie","Februarie","Maart","April","Mei","Junie","Julie","Augustus","September","Oktober","November","Desember",""],
namesAbbr: ["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Aug","Sep","Okt","Nov","Des",""]
},
patterns: {
d: "yyyy/MM/dd",
D: "dd MMMM yyyy",
Expand Down
2 changes: 1 addition & 1 deletion globinfo/jQuery.glob.af.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 10e570f

Please sign in to comment.