0

I am wondering the best place in my web application tiers to user regional settings to format date column output from a database results query.

I can get the regional settings from the HttpContext.Request and pass this as a string to the Business Layer and then use System.Globalisation in the Business Object Layer to create a DateTimeFormatInfo object.

ie. DateTimeFormatInfo dtfi = CultureInfo.CreateSpecificCulture(cultureString).DateTimeFormat;

The business layer fetches the data from a Data Access Layer and using a LINQ query selector the date column can be formatted with the dtfi object above.

However I am wondering if I really should be passing a string with the language-culture to the business layer and should instead load up another anonymous type with the data returned from the business layer and add the date formatting in the controller.

This would avoid the situation of a WPF app passing the culture info of the executing threa to the same call in the Business layer.

matthewbaskey
  • 1,027
  • 2
  • 17
  • 40
  • Yes I would not add it to the Business Layer, except that the Business layer returns an Anonymous Type and I need to reach into this object and find the collection of rows and then the rows which are dates and then format them. – matthewbaskey Jun 12 '13 at 10:42

1 Answers1

0

Personally, I prefer to deal with all the culture stuff as soon as possible for input and as late as possible for output, which means in the UI and the controller code. The business layer should only concern itself with a regular DateTime object.

Culture code is messy code and it is helpful to keep that messy code in one place and not let it seep through multiple layers of your code.

Jason Berkan
  • 8,734
  • 7
  • 29
  • 39
  • yeah I agree, its just all the controller action methods are short and concise, and I will have to load a new anonymous type to do date formatting on the data returned from the BizObject. – matthewbaskey Jun 11 '13 at 13:34