sharepointdatetimecustom-field-type

Sharepoint RenderPattern and "neutral" DateTime values


I created a custom Sharepoint field and a custom renderplattern for it:

<RenderPattern Name="DisplayPattern">

          <Column Name="Date" HTMLEncode="FALSE" Format="DateTime"/>

</RenderPattern>

So basically it is writing out the raw value of the "Date" field. Currently I'm using the output clientside using Javascript:

...
var date = new Date(rawDateString);
...

Here I read the raw date string and parse it into a date object. This works fine so far, however I'm wondering if this is a stable solution. Will Sharepoint region/language/time settings have an impact on this? I want this to work across different settings.

Thanks for any help.


Solution

  • Yes, this will possibly cause problems. What format does your custom SharePoint field and render pattern output it in?

    JavaScript runs client side and the regional settings are not necessarily the same as the SharePoint site.

    For example what is the date "08-06-2010"? In the US its 6th August in Europe its 8th June.

    If you've got a user with UK regional settings on the desktop accessing a site with US regional settings what will happen?

    If you are only using the string in JavaScript and it doesn't need to be human readable and match the sites regional settings then use a format that stays exactly the same regardless of regional settings such as the RFC1123 format

    // c# - Gives "Mon, 15 Jun 2009 20:45:30 GMT" regardless of regional settings
    return date.ToString("R");