Where should the view values ​​be converted to layered architecture?

I am creating a multilingual, multitasking and n-tier application. All dates are stored in a database in UTC format, and all model objects are populated with UTC time. However, UTC is never displayed (unless the user has a time zone set to UTC).

This means that I need to re-convert the temporary properties into the correct user timezone. Repetition is always a sign of bad code or a better way, so I tried to devise a better strategy for implementation. Although this is the presentation logic, my thoughts have changed because it seems that the model should know the correct values ​​for the current user. So far my thoughts are:

  • Use a static helper class, and then call it every time a model property is used. It seems error prone or forgotten, and makes calculations cumbersome.

  • Wrap the model object in the viewmodel. This is also cumbersome, especially when working with object lists.

  • Write an extension method for the model that exists only in the view layer. It seems cleaner, but unintuitive.

  • Create a model-level interface for conversion. Deploy a helper in the presentation layer and give a realistic model level. Then the model has properties that use the interface to convert time. It seems like this should upset the separation of concerns, but it doesn't seem. If you have a default converter, you don’t have to worry about getting exceptions for the null object, however then for the model layer (currently POCO) you need a container for the conversion helper, which seems messy.

  • Create a conversion method to the local time zone on the model and go to the current time zone.

I am interested in opinions about these strategies or about any others that I should or could use instead.

Update , , - ITimeConvertor ITimeConvertorFactory . , . UTC, . factory UTC - getter setter. ( ) timeconvertor factory. - ITimeConvertorFactory ITimeConvertor WebTimeConvertorFactory WebTimeConvertor. WebTimeConvertor , . WebTimeConvertorFactory WebTimeConvertors. (application_onstart global.asax), factory . , UTC. , localtimes , factory. UTC , . , , ( ), .

.

+5
1

, , . .

- , , . , , (POCOs) . , , . , , UTC, .

Update: , , UTC , localtimes - , ( ). , UTC, , , . , readonly UTCToLocalTimeConverter -type POCO, ( ). ConvertToLocalTime, . , Session.

, , , , , . , . , .

+2

All Articles