Rank 3: Container
How to change the timezone that a cloud function with dart-runtime uses when creating DateTime objects? I have already changed the timezone fo the host, appwrite seems to have its own timezone configured?
Votes
0
Replies
18
Participants
Unknown
Messages
19
Rank 3: Container
How to change the timezone that a cloud function with dart-runtime uses when creating DateTime objects? I have already changed the timezone fo the host, appwrite seems to have its own timezone configured?
Rank 3: Container
Changing timezone in cloud function runtimes..
Can you expand further on what you're trying to do and what's going on?
When server-side, you should always work in UTC
Rank 3: Container
I have a cloud function that runs on the dart-runtime. There I use DateTime objects to make changes. The created DateTime objects are three hours behind my local timezone
Rank 3: Container
At first I thought the dart runtime reflects the system's timezone, just as how it does so on my own machine, but on appwrite it seems to be somewhat diffeernt
What exactly are you doing with the datetime objects? You should probably be doing DateTime().toUtc()
Rank 3: Container
Already doing that. I use the DateTime object to query based on the local timezone
Rank 3: Container
.toUtc() still returns the time that is behind my timezone
What do you mean?
Rank 3: Container
Sorry if I have not been clear.
The cloud function uses the current DateTime (the time it gets triggered) and uses it to find the documents that belong to the same DateTime (that's; $createdAt attribute). And the problem is that the DateTime in my dart runtime is three hours behind my local timezone, so whenever users trigger that function in the local timezone, the queried result will be inaccurate since it's going to be based on a DateTime with a different timezone. I hope it's clear
Belong to the same timezone? What do you mean? Can you explain in more detail what you're trying to do?
Rank 3: Container
Let's say my documents are created at different times in day 1,
And a user wants to query to the documents at a specific time, for that the user calls a cloud function to do that for him.. the cloud function does not take any input from the user but rather uses the current time it gets triggered and queries the docs per that.
Rank 3: Container
when the cloud function uses the current datetime, the result is not going to be the same as if the user has passed into the function its dateTime
Rank 3: Container
because as I described previously, in my console the DateTime (if I print out thru the dart runtime) appears 3 hours behind the time zone I need to operate in
Rank 3: Container
I'm currently just doing res.json({ 'areDevelopersAwesome': DateTime.now().toUtc().toString(), }); in my cloud function and the dateTime ain't the same as my host
Rank 3: Container
Did I make the use-case clearer? @Steven
The user must supply the input
Rank 3: Container
it seems to be the way I shall go with
Rank 3: Container
I will go this way now. I appreciate the time you took here 👋