Next.js Discord

Discord Forum

Incorrect data in vercel production server

Answered
Patrick MacDonald posted this in #help-forum
Open in Discord
I have a next JS project in typescript using postgres serverless. In a local environment the dev server and a production environment run locally I do not have an issue. However while hosting on Vercel it's loading the incorrect information. I am fetching a timestamp from the postgres server of when the trip was created. Locally or with a production server locally it loads the correct time stamp. However in the Vercel production server it does not load the correct time. The time in the database is correct as well I've tried clearing the cache and even storing new trips. Is there a known issue with using the next JS SDK to retrieve a timestamp from a postgres serverless database. I'm just not sure why it's showing incorrect information from the database I do not manipulate the information after fetching it so I don't understand what the issue is.
Answered by Coffee Coke
probably its because of the time zones, server is probably located in the different timezone or just using different standard. I recommend setting standard timezone and converting your time into it
View full answer

67 Replies

Answer
There is a time zone inside of the stamp though, and I don't mutate the information should it not be the timestamp that is stored inside of the database?
It's literally mutating specifically the time, the date is correct and in the same format
Should the server action be mutating a value that it receives from the back end without being told to? Or the client changing information it has received?
@Patrick MacDonald It's literally mutating specifically the time, the date is correct and in the same format
could you give an example? the time it should show and what it is showing
Sorry I'm not at home I mixed up my pictures I can provide updated information when I get home sorry about that
that's ok, ping me when available
Ty just at work for another two hours
Ok here we go
Time shows up as 8:25 and I created it at 2:25 the time in the bottom right hand corner of the picture is the time stored in the database
1425 is what should be showing up
time difference is 6 hours
time in your database in the GMT-06
server is on the GMT-0
if you were in the GMT+04 zone, it would be 12:25
as I said, time zone problem
move the database times in the GMT-0 timezone
or UTC
same
So convert the timestamps to GMT 0 while inputting them to the database? And then convert them on the client back to GMT 6? I'm just confused if they're saved in the database as GMT 6 how do I just pull that information out without it being mutated? I just don't understand if I save it with a timestamp can I not retrieve it with the same time stamp?
I guess what I'm saying is why does it even let me save it with a gmt6 timestamp if I can't retrieve it without it being mutated
Also when I get home I will check that the difference in time being displayed is the same difference between all trips
I will give that a try as soon as I get home
if might live in the GMT -6 but user could be in the different time zone
Thank you for giving me something to try so quick after asking for help I appreciate your assistance
Ok I'm running in to some strange outcomes with out changing any client other then removing the date time inputbox. In the server action I use current time stamp, and this works 50% inputtime in the db is saved at the dbs local time how ever it still includes the gmt 600 and mountain time. I checked the constraints of the field in pg. and it says timestamp with out time zone. I wonder if the tag is some how using the clients timezone but the servers time? Heres where it gets funny locally when I run the web site with out changing the value in any way I get the time listed in the db the server time. However when I run the Vercel deployment I get the correct time again with out changing anything. I'm wondering if that tag at the end with the gmt has anything to to do with it? So my questions now are will the current fix work in other time zones and if the clients time zone will be listed or have I some how defaulted to Calgary time in my set up, will users from others places have the correct gmt tag and will they have the correct time? I would be willing to let someone test the site out if it would help answer these questions. I need to know how the gmt tag gets there , if its from the client or if its some how a default and if Vercel is changing data based on it?
sign in by clicking top right hand side. if you click on the nav bar links b4 signing in it will let you sign in but then 404 you lol. thats minor and I can fix not worried. lol tldr click login to login and then all link will work corerctly
after that click create a trip after that it will take you to current trips and load your trips ( Hopefully with your time zone or at the very least your correct time lol)
I can delete your user after if it makes you feel better as well
@Patrick MacDonald https://pats-pretrip.vercel.app/
it looks like db error
I can fix that sorry I Just integrated off kit the other day so what's happening is my action that creates a new user is not working correctly I'm sorry I will work on this immediately I think I can have it fixed shortly
so I can't help with the "time zone" problem?
I could manually insert your email into the database
well lets do that
dm me or send it on here?
I already have an account, if you can see it
ends with 382
ok i added it from my users in auth kit to my pg db you should be able to add a trip now. I'm sorry the logic is so strange Because I just integrated auth kit to an already existing project I just made it work without fully integrating it I guess ideally it would make more sense to drop my user table and just use an email instead of a user id foreign key
But it is also comes down to logic I did this code on the wrong page so your users was never added to my pg users table untill i just did it manully
well its correct here
All I can do is describe this as witchcraft
But in all seriousness the program takes a timestamp from the client saves the time locally and then Varcel takes this time stamp and magically updates the time on the client side to the correct time without any code but ran locally it just outputs the gmt tag and the server's time.
is it a bug or a feature
confussing
Sometimes things are both
and the problem is fixed?
In theory as long as I make exceptions for the time being incorrect on local builds'
And then Vercel and Postgres work seamlessly to display the correct time with no code at all
"if it works don't touch it"
this code here gives both the wrong time and the correct time depending on the environment
is inputdate users local date?
input date is created by using this sql but heres where it gets wacky from what i can tell it save the time as server time but the gmt time zone from the clinet
wait even more wacky
heres how it saves in the db
Am I missing something? Why is it saving in the servers time but my gmt and then displaying in your time and gmt
and how could anyone have ever figured this out with out testing from a different time zone?
@Patrick MacDonald heres how it saves in the db
maybe db is showing you in ur local time?
and vercel Automatically assumes your database timestamps are in database local to the db time and then they automatically mutate all time and date requests from Pg db to the client's time zone?
well, you got me there
lol
how would anyone ever know this