Back

Changing timezone in cloud function runtimes..

  • 0
  • Functions
Arrow
14 Jul, 2023, 22:44

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?

TL;DR
The user is asking how to change the timezone in their cloud function runtime. They are currently experiencing a three-hour difference between their local timezone and the DateTime objects in their cloud function. They've mentioned that they have already changed the timezone of the host, but it seems that Appwrite has its own timezone configured. They are seeking guidance on how to change the timezone in their cloud function runtime. There is no solution provided in the support thread.
Arrow
14 Jul, 2023, 22:44

Changing timezone in cloud function runtimes..

Drake
15 Jul, 2023, 00:47

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

Arrow
15 Jul, 2023, 10:14

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

Arrow
15 Jul, 2023, 10:18

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

Drake
15 Jul, 2023, 14:55

What exactly are you doing with the datetime objects? You should probably be doing DateTime().toUtc()

Arrow
16 Jul, 2023, 06:28

Already doing that. I use the DateTime object to query based on the local timezone

Arrow
16 Jul, 2023, 06:29

.toUtc() still returns the time that is behind my timezone

Drake
16 Jul, 2023, 15:37

What do you mean?

Arrow
16 Jul, 2023, 17:52

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

Drake
16 Jul, 2023, 18:06

Belong to the same timezone? What do you mean? Can you explain in more detail what you're trying to do?

Arrow
16 Jul, 2023, 18:21

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.

Arrow
16 Jul, 2023, 18:21

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

Arrow
16 Jul, 2023, 18:22

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

Arrow
16 Jul, 2023, 18:24

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

Arrow
16 Jul, 2023, 18:25

Did I make the use-case clearer? @Steven

Drake
16 Jul, 2023, 18:30

The user must supply the input

Arrow
16 Jul, 2023, 18:31

it seems to be the way I shall go with

Arrow
16 Jul, 2023, 18:33

I will go this way now. I appreciate the time you took here 👋

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more