Time not showing accurately from hosted server

hi, I was wondering how does Time_zone work in a hosted django project in railway app, because when I use the project the time is working accurately , however the same project in railway server gives a different time.
22 Replies
Percy
Percy2y ago
Project ID: N/A
mattey
mattey2y ago
i think my projet id is arrivaapp03-production.up.railway.app
jackson
jackson2y ago
railway servers are in UTC unless you override this
mattey
mattey2y ago
oh, iv made mine in django to TIME_ZONE = 'Indian/Maldives' how ever the time is off, when i use it locally the time is working ok
jackson
jackson2y ago
django time won't do a whole lot if the system time and database times are different especially things like TimeFields, those are near impossible to work with across multiple time zones unless you do a bunch of manual calculation and offsets might just be me struggling with the concepts, but i had to do a lot of work to get stuff that worked fine on local to work in a production setting because of how django handles datetimes
mattey
mattey2y ago
oh, so what is the recommended way to handle time zones in a production server
jackson
jackson2y ago
depends on how you create, store, and then retrieve them
mattey
mattey2y ago
i mean, do i need to set the production servers' <time> manually in order for it to sync
jackson
jackson2y ago
not sure, if you create, store, and parse everything as a timezone aware datetime object it should work
mattey
mattey2y ago
ok, this is my database time, in my railway postgres app: railway=# select now(); ------------------------------- 2023-02-13 06:04:11.908534+00
jackson
jackson2y ago
yeah that's UTC
mattey
mattey2y ago
its actually : 023-02-13 11:04:11 in my localtime
jackson
jackson2y ago
and that's your local TZ
mattey
mattey2y ago
so it might be my db is not configured to my correct timezone right
jackson
jackson2y ago
PostgreSQL Documentation
SET
SET SET — change a run-time parameter Synopsis SET [ SESSION | LOCAL ] configuration_parameter { TO | = } …
jackson
jackson2y ago
yeah but be careful this may have unintended side effects
mattey
mattey2y ago
oh,, by looking in the doc, it seems i need to change the time zone in postgres to: SET timezone TO 'MVT'; Hi locally i can access my postgresql.conf file to update my timezone, where can i access the file in railway app's postgres service, or is there a way i can overide the default values because if i use SET the docs says: If SET (or equivalently SET SESSION) is issued within a transaction that is later aborted, and Once the surrounding transaction is committed, the effects will persist until the end of the session,
Adam
Adam2y ago
Best practice is to set to UTC do the conversion in your app
mattey
mattey2y ago
thanks, for the tip, but right now i'm looking for a way to update my railway's db to a specific timezone, that persists not just for a specific session because the app is already deployed to production with bunch of models that rely on date and time
Adam
Adam2y ago
Best practice would be to have the databases in utc and have all your projects that draw from it convert to your time zone Not sure how to change the timezone, that would have to happen when your app enters the data to your database
mattey
mattey2y ago
ok thanks one quick question, so everything I enter into the db should be in UTC time zone , so where ever and when ever i retrieve them I have to convert it to a my specific time zone right? one more, is there a way which I can override the railway apps db's server, from UTC to another timezone?
angelo
angelo2y ago
No not at the moment.
Want results from more Discord servers?
Add your server