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?
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
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
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()
Already doing that. I use the DateTime object to query based on the local timezone
.toUtc() still returns the time that is behind my timezone
What do you mean?
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?
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.
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
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
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
Did I make the use-case clearer? @Steven
The user must supply the input
it seems to be the way I shall go with
I will go this way now. I appreciate the time you took here 👋
Recommended threads
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...