mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Added a few more members to the IDateTimeFormatProvider abstraction and its implementations. Removed the hard coded assumption of concatenating the short date pattern and short time pattern together to form the full date time pattern, and replaced it with proper information supplied by CultureInto.
This commit is contained in:
@@ -64,7 +64,7 @@ namespace Orchard.Localization.Services {
|
||||
|
||||
public string ShortDateTimeFormat {
|
||||
get {
|
||||
return String.Format("{0} {1}", ShortDateFormat, ShortTimeFormat);
|
||||
return T("M/d/yyyy h:mm tt").Text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,25 @@ namespace Orchard.Localization.Services {
|
||||
|
||||
public string LongDateTimeFormat {
|
||||
get {
|
||||
return String.Format("{0} {1}", LongDateFormat, LongTimeFormat);
|
||||
return T("dddd, MMMM d, yyyy h:mm:ss tt").Text;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllDateFormats {
|
||||
get {
|
||||
return new[] { ShortDateFormat, LongDateFormat };
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllTimeFormats {
|
||||
get {
|
||||
return new[] { ShortTimeFormat, LongTimeFormat };
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllDateTimeFormats {
|
||||
get {
|
||||
return new[] { ShortDateTimeFormat, LongDateTimeFormat };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +130,12 @@ namespace Orchard.Localization.Services {
|
||||
}
|
||||
}
|
||||
|
||||
public string DateSeparator {
|
||||
get {
|
||||
return "/"; // Since we can't do it with TimeSeparator why do it with this one...
|
||||
}
|
||||
}
|
||||
|
||||
public string TimeSeparator {
|
||||
get {
|
||||
return ":"; // No good way to put a colon through a colon-separated translation process...
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
|
||||
@@ -62,7 +63,10 @@ namespace Orchard.Localization.Services {
|
||||
|
||||
public string ShortDateTimeFormat {
|
||||
get {
|
||||
return String.Format("{0} {1}", ShortDateFormat, ShortTimeFormat);
|
||||
// From empirical testing I am fairly certain this invariably evaluates to
|
||||
// the pattern actually used when printing using the 'g' (i.e. general date/time
|
||||
// pattern with short time) standard format string. /DS
|
||||
return CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('g').First();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +84,44 @@ namespace Orchard.Localization.Services {
|
||||
|
||||
public string LongDateTimeFormat {
|
||||
get {
|
||||
return String.Format("{0} {1}", LongDateFormat, LongTimeFormat);
|
||||
return CurrentCulture.DateTimeFormat.FullDateTimePattern;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllDateFormats {
|
||||
get {
|
||||
var patterns = new List<string>();
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('d'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('D'));
|
||||
// The standard format strings 'M' (month/day pattern) and 'Y' (year/month
|
||||
// pattern) are excluded because they can not be round-tripped with full
|
||||
// date fidelity.
|
||||
return patterns.Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllTimeFormats {
|
||||
get {
|
||||
var patterns = new List<string>();
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('t'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('T'));
|
||||
return patterns.Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllDateTimeFormats {
|
||||
get {
|
||||
var patterns = new List<string>();
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('f'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('F'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('g'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('G'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('o'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('r'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('s'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('u'));
|
||||
patterns.AddRange(CurrentCulture.DateTimeFormat.GetAllDateTimePatterns('U'));
|
||||
return patterns.Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +139,12 @@ namespace Orchard.Localization.Services {
|
||||
}
|
||||
}
|
||||
|
||||
public string DateSeparator {
|
||||
get {
|
||||
return CurrentCulture.DateTimeFormat.DateSeparator;
|
||||
}
|
||||
}
|
||||
|
||||
public string TimeSeparator {
|
||||
get {
|
||||
return CurrentCulture.DateTimeFormat.TimeSeparator;
|
||||
|
@@ -64,8 +64,7 @@ namespace Orchard.Localization.Services {
|
||||
if (!parts.HasValue) {
|
||||
return null;
|
||||
}
|
||||
var calendar = CurrentCalendar;
|
||||
return new DateTime(parts.Value.Date.Year, parts.Value.Date.Month, parts.Value.Date.Day, parts.Value.Time.Hour, parts.Value.Time.Minute, parts.Value.Time.Second, parts.Value.Time.Millisecond, calendar);
|
||||
return new DateTime(parts.Value.Date.Year, parts.Value.Date.Month, parts.Value.Date.Day, parts.Value.Time.Hour, parts.Value.Time.Minute, parts.Value.Time.Second, parts.Value.Time.Millisecond, CurrentCalendar);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -72,7 +72,6 @@ namespace Orchard.Localization.Services {
|
||||
get;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a custom DateTime format string used to format dates for long time display.
|
||||
/// </summary>
|
||||
@@ -87,6 +86,27 @@ namespace Orchard.Localization.Services {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full list of custom DateTime format strings supported to format dates for date display.
|
||||
/// </summary>
|
||||
IEnumerable<string> AllDateFormats {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full list of custom DateTime format strings supported to format dates for time display.
|
||||
/// </summary>
|
||||
IEnumerable<string> AllTimeFormats {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full list of custom DateTime format strings supported to format dates for date and time display.
|
||||
/// </summary>
|
||||
IEnumerable<string> AllDateTimeFormats {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the first day of the week, where 0 is Sunday, 1 is Monday etc.
|
||||
/// </summary>
|
||||
@@ -102,7 +122,14 @@ namespace Orchard.Localization.Services {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string that separates the components of time, that is, the hour, minutes, and seconds.
|
||||
/// Gets the string that separates the components of date, that is, the year, month and day.
|
||||
/// </summary>
|
||||
string DateSeparator {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string that separates the components of time, that is, the hour, minute, and second.
|
||||
/// </summary>
|
||||
string TimeSeparator {
|
||||
get;
|
||||
|
Reference in New Issue
Block a user