#Cant tell if time.Now() is screwed up

59 messages ยท Page 1 of 1 (latest)

next vortex
#

Sqlc gives me a time 8:07 pm

#

When it should be 7:07pm

fossil lantern
#

Time zone issue ?

next vortex
#

I've tried everything on the frontend

fossil lantern
#

Well

#

UTC is universal ain't it

next vortex
#

ive converted to the local timezone, while that fixed the timestamp sqlc gives, the one timestamp that i send when a user sends a message is an hour early

fossil lantern
#

So not a time zone problem

#

Oh so maybe

next vortex
#

I cant really tell, since even that timestamp would go through the conversion and yet it stays the same.

#

Well

#

Rather that the timezone conversion fixes sqlc, while it screws up the timestamp I send when a user sends a message.

#

So either way you flip it you have an issue

#

My only thought is that it's just screwed up cause this makes no sense

foggy stump
#

what exactly is wrong about "Formatted Time (UTC): 6:08 PM"? it is currently 6:14 UTC

#

that is correct

next vortex
#

what matters to me is local time, so i display it, it's off, it's either an hour ahead or an hour earlier, an hour earlier is the issue if i convert timezones but its an hour ahead if i dont

foggy stump
#

this just sounds like you need to format in local time zone on the front-end

next vortex
#

well it sounds like that but you use the local timezone, while it fixes the first issue now you have another

foggy stump
#

then it sounds like your front-end is providing incorrect or ambiguous information to the back-end

#

timezones should really only come into play in displaying things, not the absolute value of timestamps

#

i fail to see how this has anything to do with Go's time handling

next vortex
#

i have no idea

#

ive never had this issue because i dont typically use go for something like this

foggy stump
#

i really don't think it does

#

i would focus on your front-end here

#

note that because RFC 3339 contains timezone information, there are multiple equivalent ways to represent a time

#

e.g., 2024-11-30T18:08:32Z is the exact same time as 2024-11-30T19:08:32+01:00

#

it provides a hint towards what timezone might be correct to display, but they are the same time

#

one is not more right than the other

next vortex
#

well look, 2024-11-30T19:23:08.283Z 2024-11-30T18:23:44.000Z

#

the 1st one is when messages are fetched

foggy stump
#

how is that time being generated?

next vortex
#

2nd one is when a user sends a message and i'm generating a timestamp with time.Now().UTC().Format(time.RFC3339)

foggy stump
#

the first

next vortex
#

it's postgres

#

and im using sqlc/pgx

foggy stump
#

be specific, please

#

what is generating it

next vortex
#

how can i be more specific

#

I convert to isostring() on the frontend, so that both are formatted the same way. now

fossil lantern
#

When you said the 1st is when messages are being fetched. You mean that's the time that the frontend said it first requested information?

foggy stump
#

what is creating that timestamp?

#

what is inserting it into the database?

next vortex
#

it's being pulled from the database

foggy stump
#

inserting

next vortex
#

TIMESTAMP DEFAULT NOW()

foggy stump
#

okay, that's the specificity i was after. ๐Ÿ™‚

#

you should use TIMESTAMP WITH TIME ZONE

#

otherwise, the database stores local-time timestamps without time zone information

next vortex
#

alright

foggy stump
#

this makes it impossible to interpret the data without assuming that the timestamp was the same at insertion time as it is at query time

#

and even if you assume that, you still need to have more logic to incorporate that local time offset

next vortex
#

i even had some issues sorting, so that must have been caused by that too maybe.

#

Alright that fixed it

#

no need for anything kind of timezone conversion or anything like that

#

just works now

foggy stump
#

yep ๐Ÿ™‚

#

regardless of what timezone the database chooses, it doesn't matter, because it includes that information in the timestamp itself