Thank you.
But this still does not solve my initial problem with passing DateTime to server. I still get that exception even when use your conversions. I think it could be due to different culture on server. But now I don't know how to set culture for Controls.InputDatepicker? -Or any other formlet control.

Thanks again.

By on 4/18/2012 8:13 AM ()

Ok, the exception (above) is not caused exactly by passed DateTime value, but try this:

1
2
3
4
5
6
7
[<Rpc>]
let TestRpc (s:string) (dt1:DateTime) (dt2:DateTime) (a:int)= "ok"

[<JavaScript>]
let TestClient () =
   let test = TestRpc "s" DateTime.Today DateTime.Today 42
   test

After calling TestRpc I am getting that exception in response. It is strange, perhaps bug.

By on 4/18/2012 11:04 AM ()

Well, it is all right now! I had 2.4.38 and upgraded to this week beta realese now and it is good. Could you advise me with formlet culture configuration yet please? ;)

Thank you

By on 4/18/2012 1:34 PM ()

What exactly do you expect to happen by configuring the culture? I don't quite see what the client's culture would have to do with Loic's conversion functions.

By on 4/18/2012 4:44 PM ()

With Loic's functions it has nothing common. It is for new top question perhaps. I simply want to change culture in my Controls.InputDatepicker.

By on 4/19/2012 12:03 AM ()

AFAIK there is no concept of culture in JavaScript/WebSharper. You will have to roll your own.

By on 4/25/2012 6:05 AM ()

I was thinking about something like this:
[link:docs.jquery.com]
-setting property $.datepicker.regional is probably possible, but how to plugged it to formlet Controls.InputDatepicker?

By on 4/25/2012 6:55 AM ()

There is no DatePicker in formlets. Which extension are you using?

By on 4/25/2012 7:42 AM ()

Exactly this: IntelliFactory.WebSharper.Formlet.JQueryUI.Controls.InputDatepicker

By on 4/25/2012 7:46 AM ()

I checked localization options for JQuery UI calendar. The reference is:

[link:jqueryui.com] (Localization section)

The quick and dirty way of enabling JQuery UI localization for your formlets is to explicitly include the localization file, for example by adding this line to your template file:

1
2
    <meta name="generator" content="websharper" data-replace="scripts" />
    <script type="text/javascript" src="http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-cs.js"></script>

At a first glance there does not appear to be a more elegant or a better way of integrating this into WebSharper, but we will have a look at it.

By on 5/7/2012 1:02 PM ()

Hi, unfortunately your code seems to work for me just fine. Could you get the exception trace or send us a zip with the complete solution? Are you using the latest WebSharper? Thanks! --A

By on 4/18/2012 11:59 AM ()

(Edited) To put it in a different way: you can't use System.DateTime instances without restrictions on the client ATM (technically, because there is no WebSharper proxy for them that provides a full implementation, at least not right now). This is largely due to the fact that System.DateTime is hard to support faithfully (e.g. with the same logic, including cultures, formats, etc.) on different clients.

So in general, to work with dates and times, you can use EcmaScript.Date on the client and System.DateTime on the server, and apply the conversion functions Loic showed above.

By on 4/18/2012 8:29 AM ()

There is indeed no server-side mapping for the EcmaScript.Date class, so as you guessed, you need to convert to a System.DateTime which has a client-side proxy.

Conversion functions between .NET and EcmaScript dates are something we intend to provide in a future version of WebSharper, either as extension methods on System.DateTime or in another way.

In the meantime, here is the (client-side) code I use in applications we develop:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Date =

    /// Convert a .NET date object to a JavaScript standard date object.
    [<JavaScript>]
    let toEcma (d: System.DateTime) =
        EcmaScript.Date(
            // January is 1 on .NET and 0 in JavaScript, hence `.Month - 1`
            d.Year, d.Month - 1, d.Day,
            d.Hour, d.Minute, d.Second, d.Millisecond)

    /// Convert a JavaScript standard date object to a .NET date object.
    [<JavaScript>]
    let ofEcma (d: EcmaScript.Date) =
        System.DateTime(
            // January is 1 on .NET and 0 in JavaScript, hence `.Month + 1`
            d.GetFullYear(), d.GetMonth() + 1, d.GetDay(),
            d.GetHours(), d.GetMinutes(), d.GetSeconds(), d.GetMilliseconds())
By on 4/18/2012 5:23 AM ()

In ofEcma should be d.GetDate() instead of d.GetDay().

By on 4/19/2012 1:24 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper