Query Results in Local Timezone?

Hi,
I have to convert all my time based API queries to UTC and the results are also received only in UTC.
Is there any way to have them in local timezone (we have set the correct local timezone in SH site settings)?

I can live with having to send queries in UTC (though not ideal), but receiving results and then having to convert every single line entry in every single query is insane - can you pls suggest a solution?

Thank you
Raj

Hey @Raj,

Thanks for reaching out.
I’ll look into this and let you know if there’s anything that can be done.

Please let me know if you have any questions or concerns.

Best,
RayanP

1 Like

Hey @sh-agent, were you able to find out more here?
Thank you!

Hey @Raj,

Thanks for hanging in there while I looked into this.

Unfortunately, I wasn’t able to find a solution on our end to change the queried results to the users native timezone.

Please let me know if you have any questions or concerns.

Best,
RayanP

You can do this automatically in Pyhton using a pydantic validator:

For example:

from datetime import datetime, timezone
from pydantic import BaseModel, validator
...

class MyModel(BaseModel):
    allocated_at: datetime

    @validator('allocated_at')
    def assign_utc_timezone(cls, value):
        return value.replace(tzinfo=timezone('UTC'))

Then all your datetime objects are timezone aware and it’s easy to convert to your local time. For example using pendulum:

import pendulum
# Can be done in one line as well
allocated_at = pendulum.instance(datetime_obj_to_convert)
local_allocated_at = allocated_at.in_timezone('America/New_York')
1 Like