Correcting an ancient wrong: Years ago I set my timezone to local. Can I undo this, page by page, by using setTimeZone?

Good day,

Years ago – like, 20 years ago, with MacroMedia Coldfusion – I set my server settings up with the time zone being in local time. As I migrated towards Lucee, all of the application was still set up under the assumption that the server’s master timezone setting was in local time, not UTC. I am now, of course, fully aware of the huge amount of complications this can cause and workarounds required. Sometimes it’s easier to just keep using bandaids, but I’d like to resolve this, some day. (MySQL is in UTC, the OS is in UTC, Nginx is in UTC, just Lucee over here being a pain because of my dumb configuration decision 20 years ago.)

What I’m wondering is if I can use the setTimeZone function on each, individual page as a method for correcting this mistake, page by page, piece by piece.

What I’m hoping would work is that, one by one, I insert this at the top of each page I need to fix:

<cfscript> setTimeZone('UTC') </cfscript>

Then make all the corrections needed. Eventually, when every page is correctly fixed, I’m hoping I would be able to go into the server settings and switch from local time to UTC and none of the time-related functions of the application would be affected.

So, my question: Is it safe to assume that this method would work to correct this issue? I appreciate any help this community of folks is able to offer. Thank you.

@gooutside If you set the timezone in Application file or sever admin is the easiest way instead of you setting the timezone in every page.

I’d really say, it’s not dumb at all. That was how we did things back when the millenium came (just remembered the Y2K-Bug… Sigh)

@cfmitrah, it seems you may have missed the key point @gooutside was asking. They realize they COULD set it at the Admin level (or app level). They wondered if anyone had any argument against using this settimezone function on a page-by-page basis.

Specifically, they wondered if they could use it to make some “corrections needed [in that page and THEN]…when every page is correctly fixed…go into the server settings and switch from local time to UTC.” I don’t see any problem with that, but I can’t speak from experience.

One might wonder if the only purpose for this setimezone() was for setting the timezone at the application level (to override the admin), but if that was so then Lucee (and ACF, which added the function in CF2021) would seemingly have instead implemented it as an application setting (like this. in application.cfc, or on cfapplication in application.cfm).

Since instead they did it as a function, it would seem they had @gooutside’s use case in mind. But maybe someone with more specific experience can speak to that.

1 Like

@carehart Thanks for correcting me…

@gooutside The page level setting would actually work, as setTimezone() will just set the timezone for the current request itself… So whatever the pages you placed setTimeZone('UTC') will use UTC & all other pages will keep the server’s timezone…

My 2cents is: It sounds like your going to have to adjust each page anyway ( and I think you know that)… So I think your asking more of a : Where is the Best place to BASE times from as you are currently looking working with the Lucee Server settings.

I Rarely go to the Server Scope… and I think long and hard before putting anything there…
In this case… I would go to Server Scope within the application.

But, still… The : OnRequest would be just as legit… and probably easier to reference in the future for yourself or other DEVs that might come across it as the Server scope is 2 levels up and could be confusing…

The application scope (as) mentioned above is just as legit… so really… it’s more a matter of preference on those scopes at this point now that your ready to fix this…