mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-08-01 19:24:00 +08:00
Using .NET culture information for Date/Time input
--HG-- branch : 1.4.x
This commit is contained in:
parent
d60af14ac6
commit
daf188c57e
@ -5,4 +5,4 @@ ff3ea8b4174d011d030f561209f34191fb171889 src/Orchard.Web/Modules/Orchard.Rules
|
||||
b2e564aeb77515626fc504ad1093514a68b32f5f src/Orchard.Web/Modules/Orchard.Tokens
|
||||
4ed51e0e76c2aacc2de90ce9984fd00cfdfae2ce src/orchard.web/Modules/Orchard.Alias
|
||||
4f643eeb97d77e1cf9d2be31d28c99ee2658fee6 src/orchard.web/Modules/Orchard.Projections
|
||||
5dd65a4847f217d7b02bc38386287e758d0fe566 src/orchard.web/modules/Orchard.Fields
|
||||
cd596804ecb3476bfeb89184342d88562bdaf39b src/orchard.web/modules/Orchard.Fields
|
||||
|
@ -3,18 +3,14 @@ using System.Globalization;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Shapes.Localization;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Core.Common.DateEditor {
|
||||
public class DateEditorDriver : ContentPartDriver<CommonPart> {
|
||||
private readonly IDateTimeLocalization _dateTimeLocalization;
|
||||
private readonly Lazy<CultureInfo> _cultureInfo;
|
||||
|
||||
public DateEditorDriver(
|
||||
IOrchardServices services,
|
||||
IDateTimeLocalization dateTimeLocalization) {
|
||||
_dateTimeLocalization = dateTimeLocalization;
|
||||
IOrchardServices services) {
|
||||
T = NullLocalizer.Instance;
|
||||
Services = services;
|
||||
|
||||
@ -61,8 +57,8 @@ namespace Orchard.Core.Common.DateEditor {
|
||||
// date and time are formatted using the same patterns as DateTimePicker is, preventing other cultures issues
|
||||
var createdLocal = TimeZoneInfo.ConvertTimeFromUtc(part.CreatedUtc.Value, Services.WorkContext.CurrentTimeZone);
|
||||
|
||||
model.CreatedDate = createdLocal.ToString(_dateTimeLocalization.ShortDateFormat.Text, _cultureInfo.Value);
|
||||
model.CreatedTime = createdLocal.ToString(_dateTimeLocalization.ShortTimeFormat.Text, _cultureInfo.Value);
|
||||
model.CreatedDate = createdLocal.ToString("d", _cultureInfo.Value);
|
||||
model.CreatedTime = createdLocal.ToString("t", _cultureInfo.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,10 +69,9 @@ namespace Orchard.Core.Common.DateEditor {
|
||||
DateTime createdUtc;
|
||||
|
||||
string parseDateTime = String.Concat(model.CreatedDate, " ", model.CreatedTime);
|
||||
var dateTimeFormat = _dateTimeLocalization.ShortDateFormat + " " + _dateTimeLocalization.ShortTimeFormat;
|
||||
|
||||
// use current culture
|
||||
if (DateTime.TryParseExact(parseDateTime, dateTimeFormat, _cultureInfo.Value, DateTimeStyles.None, out createdUtc)) {
|
||||
if (DateTime.TryParse(parseDateTime, _cultureInfo.Value, DateTimeStyles.None, out createdUtc)) {
|
||||
|
||||
// the date time is entered locally for the configured timezone
|
||||
part.CreatedUtc = TimeZoneInfo.ConvertTimeToUtc(createdUtc, Services.WorkContext.CurrentTimeZone);
|
||||
|
@ -6,7 +6,6 @@ using Orchard.ArchiveLater.ViewModels;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Shapes.Localization;
|
||||
using Orchard.Localization;
|
||||
using System.Globalization;
|
||||
|
||||
@ -14,15 +13,12 @@ namespace Orchard.ArchiveLater.Drivers {
|
||||
public class ArchiveLaterPartDriver : ContentPartDriver<ArchiveLaterPart> {
|
||||
private const string TemplateName = "Parts/ArchiveLater";
|
||||
private readonly IArchiveLaterService _archiveLaterService;
|
||||
private readonly IDateTimeLocalization _dateTimeLocalization;
|
||||
private readonly Lazy<CultureInfo> _cultureInfo;
|
||||
|
||||
public ArchiveLaterPartDriver(
|
||||
IOrchardServices services,
|
||||
IArchiveLaterService archiveLaterService,
|
||||
IDateTimeLocalization dateTimeLocalization) {
|
||||
IArchiveLaterService archiveLaterService) {
|
||||
_archiveLaterService = archiveLaterService;
|
||||
_dateTimeLocalization = dateTimeLocalization;
|
||||
T = NullLocalizer.Instance;
|
||||
Services = services;
|
||||
|
||||
@ -51,8 +47,8 @@ namespace Orchard.ArchiveLater.Drivers {
|
||||
var model = new ArchiveLaterViewModel(part) {
|
||||
ScheduledArchiveUtc = part.ScheduledArchiveUtc.Value,
|
||||
ArchiveLater = part.ScheduledArchiveUtc.Value.HasValue,
|
||||
ScheduledArchiveDate = part.ScheduledArchiveUtc.Value.HasValue ? localDate.Value.ToString(_dateTimeLocalization.ShortDateFormat.Text, _cultureInfo.Value) : String.Empty,
|
||||
ScheduledArchiveTime = part.ScheduledArchiveUtc.Value.HasValue ? localDate.Value.ToString(_dateTimeLocalization.ShortTimeFormat.Text, _cultureInfo.Value) : String.Empty
|
||||
ScheduledArchiveDate = part.ScheduledArchiveUtc.Value.HasValue ? localDate.Value.ToString("d", _cultureInfo.Value) : String.Empty,
|
||||
ScheduledArchiveTime = part.ScheduledArchiveUtc.Value.HasValue ? localDate.Value.ToString("t", _cultureInfo.Value) : String.Empty
|
||||
};
|
||||
|
||||
return ContentShape("Parts_ArchiveLater_Edit",
|
||||
@ -66,10 +62,9 @@ namespace Orchard.ArchiveLater.Drivers {
|
||||
if ( model.ArchiveLater ) {
|
||||
DateTime scheduled;
|
||||
var parseDateTime = String.Concat(model.ScheduledArchiveDate, " ", model.ScheduledArchiveTime);
|
||||
var dateTimeFormat = _dateTimeLocalization.ShortDateFormat + " " + _dateTimeLocalization.ShortTimeFormat;
|
||||
|
||||
// use an english culture as it is the one used by jQuery.datepicker by default
|
||||
if (DateTime.TryParseExact(parseDateTime, dateTimeFormat, _cultureInfo.Value, DateTimeStyles.None, out scheduled)) {
|
||||
if (DateTime.TryParse(parseDateTime, _cultureInfo.Value, DateTimeStyles.None, out scheduled)) {
|
||||
// the date time is entered locally for the configured timezone
|
||||
var timeZone = Services.WorkContext.CurrentTimeZone;
|
||||
|
||||
|
@ -3,7 +3,6 @@ using System.Xml;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Shapes.Localization;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.PublishLater.Models;
|
||||
using Orchard.PublishLater.Services;
|
||||
@ -18,7 +17,6 @@ namespace Orchard.PublishLater.Drivers {
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IPublishLaterService _publishLaterService;
|
||||
private readonly IClock _clock;
|
||||
private readonly IDateTimeLocalization _dateTimeLocalization;
|
||||
|
||||
private readonly Lazy<CultureInfo> _cultureInfo;
|
||||
|
||||
@ -26,12 +24,10 @@ namespace Orchard.PublishLater.Drivers {
|
||||
IOrchardServices services,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IPublishLaterService publishLaterService,
|
||||
IClock clock,
|
||||
IDateTimeLocalization dateTimeLocalization) {
|
||||
IClock clock) {
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_publishLaterService = publishLaterService;
|
||||
_clock = clock;
|
||||
_dateTimeLocalization = dateTimeLocalization;
|
||||
T = NullLocalizer.Instance;
|
||||
Services = services;
|
||||
|
||||
@ -62,8 +58,8 @@ namespace Orchard.PublishLater.Drivers {
|
||||
var localDate = new Lazy<DateTime>( () => TimeZoneInfo.ConvertTimeFromUtc(part.ScheduledPublishUtc.Value.Value, Services.WorkContext.CurrentTimeZone));
|
||||
var model = new PublishLaterViewModel(part) {
|
||||
ScheduledPublishUtc = part.ScheduledPublishUtc.Value,
|
||||
ScheduledPublishDate = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? localDate.Value.ToString(_dateTimeLocalization.ShortDateFormat.Text, _cultureInfo.Value) : String.Empty,
|
||||
ScheduledPublishTime = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? localDate.Value.ToString(_dateTimeLocalization.ShortTimeFormat.Text, _cultureInfo.Value) : String.Empty,
|
||||
ScheduledPublishDate = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? localDate.Value.ToString("d", _cultureInfo.Value) : String.Empty,
|
||||
ScheduledPublishTime = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? localDate.Value.ToString("t", _cultureInfo.Value) : String.Empty,
|
||||
};
|
||||
|
||||
return ContentShape("Parts_PublishLater_Edit",
|
||||
@ -80,10 +76,9 @@ namespace Orchard.PublishLater.Drivers {
|
||||
DateTime scheduled;
|
||||
|
||||
string parseDateTime = String.Concat(model.ScheduledPublishDate, " ", model.ScheduledPublishTime);
|
||||
var dateTimeFormat = _dateTimeLocalization.ShortDateFormat + " " + _dateTimeLocalization.ShortTimeFormat;
|
||||
|
||||
// use current culture
|
||||
if (DateTime.TryParseExact(parseDateTime, dateTimeFormat, _cultureInfo.Value, DateTimeStyles.None, out scheduled)) {
|
||||
if (DateTime.TryParse(parseDateTime, _cultureInfo.Value, DateTimeStyles.None, out scheduled)) {
|
||||
|
||||
// the date time is entered locally for the configured timezone
|
||||
var timeZone = Services.WorkContext.CurrentTimeZone;
|
||||
|
@ -25,8 +25,8 @@
|
||||
// convert .NET format into jQuery format
|
||||
// http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
|
||||
// http://docs.jquery.com/UI/Datepicker/formatDate
|
||||
|
||||
var dateFormat = dateTimeLocalization.ShortDateFormat.Text
|
||||
|
||||
var dateFormat = cultureInfo.DateTimeFormat.ShortDatePattern
|
||||
.Replace("yyyy", "YY")
|
||||
.Replace("yy", "Y")
|
||||
.Replace("Y", "y")
|
||||
|
Loading…
Reference in New Issue
Block a user