I have an existing web application with 70+ projects; DB: 700+ tables, 500+ stored procedures. Currently there are many tables with Datetime/Date fields.

When saving date/datetime information in DB, i need to change them to UTC to support multiple time zone (since the application is going to be accessed across many regions - servers can also be hosted on multiple regions; currently it is accessed only from one region)

In order to do this i have come up with the below steps:

  1. Get the list of tables with date/datetime field.
  2. Check how its date time field is populated (ie. either through the application or through the procedure)
  3. List item.
  4. convert the datetime to UTC before saving it to DB.
  5. When displaying it in the user's browser, convert the time back to the user's timezone.
  6. Can write a query to update existing values with UTC.

The problem is the application by itself is very huge and there are too many places (both from the application & procedure) where datetime is updated; Though i can get the list of tables/procedure names through query directly, updating each procedure (in back end) /file (in front end) is a very tedious process

I would like to know the best approach/suggestions (change the application to support multiple timezone with minimal changes) to proceed in this situation.

Thanks!

有帮助吗?

解决方案

The ideal situation is that all dates are UTC, in the stored procedures, in process code, in API interfaces etc.

The only time it should not be UTC is directly before it is rendered for a human user

As you indicate a web application, this should be isolatable to just the HTML rendering areas, and this should be the only code you need to change after you switch the DB to UTC

You should just need two function changes:

  1. Decode human input into a valid date and convert into UTC from that sessions time zone (do this before any other processing logic)
  2. Convert date value from UTC to current sessions time zone, and format into human readable form (do this just before displaying date)

These two functions should already exist in your UI code for date formatting and validation, they just need tweeking

其他提示

It's too late for you, but when designing an application which puts a datestamp on any record changes, the correct thing to do is to write a SQL trigger that sets the date appropriately.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top