views:

191

answers:

4

Where in code should conversions be done? client, server, business, or db?

We currently do conversions of timezones and unit of measure in our database and the performance is killing us and would like to move the logic. Where do you think the best location for this is?

Thanks

+2  A: 

Typically those are client/UI choices. but that preference can be passed to the server or the business rules.

I would do it in the client to normalize data everywhere else.

EDIT:

If you have a really thin client and do not want to add logic to it, then find the next place where you have code/rules/etc and add them there. Find the outermost/client side code and put it with that.

Tim
A: 

We are trying to do them "as early as it is possible" (in our case it is where clients are connected) and work with unified data end-to-end on a server. Of course, when sent back, data is converted appropriately.

Dmitry Khalatov
A: 

I'm not sure what you mean by "conversions." If you mean localization, then that is traditionally done in the GUI layer.

Glenn
+5  A: 

I would definitely get that code out of the DB. You want to store data all in a common set of units whenever you can. Having your time data stored for one specific locale (usually your own) is common.

I wouldn't put it in the business tier either, because then you'll run into situations where you have to do calculations using times from different locales, and you'll need them to have the same starting reference. Again, you should leave them all at a common base, and the most logical thing here is to just let that base be whatever locale you're storing them in.

I think the most logical thing to do is to have time converted to the user's locale at the last possible moment, right before you display it. This puts it firmly in the GUI layer.

Bill the Lizard
Definitely agree. Also ensure that you track the user's and (staff member's) preferred time zone/offset for converting back to their local time. I always recommend UTC/GMT as a base zone.
devstuff
I agree with the UTC/GMT recommendation. Having one standard can really help integrate applications.
Bill the Lizard
Agree - ALL datetimes should be stored and transmitted across the wire as UTC and converted only when needed. I had to maintain code once where times were stored and sent with a variety of timezones and it was a nightmare figuring out durations and such. +1.
paxdiablo