Localization and date fields

Hi,

I just installed the DHTMLX Scheduler for ASP.NET MVC component to see if it suits my needs, but I notice that when I set the localization to Dutch, the date from the form doesn’t translate properly to the date in the Save method parameter.

For instance, when I select November 18 (11/18/2012 in US date format, 18-11-2012 in NL date format), the start_date and end_date properties in my Event object will both be 1-1-0001 00:00:00. If I select November 10 (11/10/2012 in US date format, 10-11-2012 in NL date format), the start_date and end_date properties in my Event object will both be 11-10-2012 with the actual entered time. Obviously this is still wrong, as it changed the date to October 11 (NL format) and stores it as such in the Database.

Is this something that I need to configure on an IIS / OS level or is this strange behavior in the product?

Hello,

the date from the form doesn’t translate properly to the date in the Save method parameter.
Defaultly scheduler uses MM/dd/yyyy HH:mm format for dates, you may change it by overriding some configurations

Scheduler initialization: var scheduler = new DHXScheduler(this); scheduler.Config.xml_date = "%d/%m/%Y %H:%i";
Data action also should return dates in specified format:public ActionResult Data(){ var data = new SchedulerAjaxData(tasks); data.DateFormat = "%d/%m/%Y %H:%i"; return data; }
here is some details on scheduler date formats
scheduler-net.com/docs/format_string.html

Thanks for the reply, Aliaksandr. I’m still seeing the same behavior with the below code:

[code] private DHXScheduler _scheduler;
private DataClassesDataContext _dataContext = new DataClassesDataContext();

    public ActionResult Index()
    {
        _scheduler = new DHXScheduler(this)
            {
                LoadData = true,
                EnableDataprocessor = true
            };
        _scheduler.Config.xml_date = "%d/%m/%Y %H:%i";
        _scheduler.Localization.Set(SchedulerLocalization.Localizations.Dutch, false);
        
        return View(_scheduler);
    }

    public ActionResult Data()
    {
        return new SchedulerAjaxData(_dataContext.Appointments) { DateFormat = "%d/%m/%Y %H:%i" };
    }[/code]

Any ideas?

How do you process ‘save’ event, can you post the code where event object is created from the request parameters?
Since the date is parsed incorrectly, you can do it manually with DateTime Parse of ParseExact methods changedEvent.start_date = DateTime.Parse(context.Request.Form["start_date"], new CultureInfo("en-US"));
If you use DHXEventsHelper for creating event from request values, you may also specify cultureInfo there
blog.scheduler-net.com/post/2012 … n-use.aspx

[code]public ActionResult Save(Appointment updatedAppointment, FormCollection formData)
{
// Fix for localized dates and en-US SQL server
updatedAppointment.start_date = DateTime.Parse(formData[“start_date”], new CultureInfo(“nl-NL”));
updatedAppointment.end_date = DateTime.Parse(formData[“end_date”], new CultureInfo(“nl-NL”));

var action = new DataAction(formData);

try
{
    switch (action.Type)
    {
        case DataActionTypes.Insert:
            _dataContext.Appointments.InsertOnSubmit(updatedAppointment);
            break;
        case DataActionTypes.Delete:
            updatedAppointment = _dataContext.Appointments.SingleOrDefault(ev => ev.ID == updatedAppointment.ID);
            if (updatedAppointment != null) _dataContext.Appointments.DeleteOnSubmit(updatedAppointment);
            break;
        default:
            updatedAppointment = _dataContext.Appointments.SingleOrDefault(ev => ev.ID == updatedAppointment.ID);
            UpdateModel(updatedAppointment);
            break;
    }
    _dataContext.SubmitChanges();
    if (updatedAppointment != null) action.TargetId = updatedAppointment.ID;
}
catch (Exception)
{
    action.Type = DataActionTypes.Error;
}
return (new AjaxSaveResponse(action));

}[/code]That’s what I got now, which seems to parse the Date correctly, but when I edit I get an FormatException on var action = new DataAction(formData); saying Input string was not in a correct format. Somehow this still doesn’t seem like the proper solution to this problem…

Hi,

default: updatedAppointment = _dataContext.Appointments.SingleOrDefault(ev => ev.ID == updatedAppointment.ID); UpdateModel(updatedAppointment); break;UpdateModel doesn’t actually uses start_date and end_date that you’ve assigned to the appointment,
according to msdn:
Controller.UpdateModel Method
Updates the specified model instance using values from the controller’s current value provider.

The value provider contains incorrect dates as they was parsed from the request values; So there is a two ways, either to change xml_date format to match the date format of your locale(you can also explicitly set CultureInfo for the whole application, in order not to run into the same problem, when you deploy application on remote server), or to manually update Appointment instance in the database