javascript - Ensure a certain line of code is evaluated early enough -


i need set default timezone moment calls in app's lifetime, logical thing put setter in entry point file, turns out not first thing evaluated. 1 of reducers has moment().format() it's initial state, , it's evaluated before entry point. therefore, resulting datetime string has incorrect offset.

is there way ensure code gets evaluated before other? initial state issue can solved replacing object function, still wonder how approach solving such issue.

you shouldn't relying on execution order of disparate sections of code. if work in moment (pun intended), you're creating situation destined cause bugs down line due unrelated refactor or feature add elsewhere.

instead, write middleman function returns moment you, tz set correctly. like;

momentwithtz () {     return moment().tz("america/los_angeles"); } 

and use instead of traditional moment in rest of code, ensuring tz set explicitly instead of trusting set else unrelated.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -