I’m looking to convert timezones from the logged in user/client to a specified timezone, in order to successfully do this I would need the client ip address or the user timezone. Is there a way in weweb that this information is available/bindable to a workflow so that I can make this work?
This is what the API would look like: ```
https://timezone.abstractapi.com/v1/convert_time
? api_key = YOUR_API_KEY
& base_location = Los Angeles, CA
& base_datetime = 2020-05-01 07:00:00
& target_location = Oxford, United Kingdom
1 Like
If you want the timezone one option is accessing the browser one. You can use a custom formula for that:
const DEFAULT_TIMEZONE = "Europe/London";
let timezone;
try {
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
} catch (e) {
timezone = DEFAULT_TIMEZONE;
}
return timezone;
The timezone returned in this way is just the browser one and may not be the same as the physical location of the user (e.g. the user can travel but does not update the device locale).
In my experience if the exact timezone is critical to the app logic it is better to ask the user for it (assuming the user understands timezones, which is not always the case).
2 Likes
Great solution for timezone.
I’m also looking to get the current user’s IP address. Is there a way?
@AmbroiseDhenain generally speaking, you’ll need to use an external API endpoint to complete this need. IP addresses arent exposed in the browser BUT if you make a call to an external source, the iP will be revealed in the headers server side.
send a request from your client to this endpoint and it will return your users ip address
https://api.ipify.org?format=json
2 Likes