Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to convert date to UTC?

Tags:

asp.net-mvc

I was wondering which area would make the most sense to convert dates to UTC and back again. We store dates in UTC and convert to a users local time zone. Right now I think putting it in the repository layer makes the most sense because you don't need to remember to convert it each time you create service layer methods that require it. My teammate suggest putting it in the service layer because it is a business rule...

Where would you put these conversion function? Service layer or Repository layer? This could include looping through a list of objects and doing a convert on each one.

like image 676
chobo Avatar asked Feb 25 '23 04:02

chobo


1 Answers

Where would you put these conversion function? Service layer or Repository layer?

In neither of those layers. I would put it in the view model. If the view requires showing dates in local timezone and your dates are stored in UTC in the model then the view model is the perfect place to format data that is being shown on the view.

like image 104
Darin Dimitrov Avatar answered Mar 07 '23 18:03

Darin Dimitrov