There is a time in life of every developer when they have to clench their fists and… start learning Flow. Today’s topic – localized date time.
Flows run on a… in a …. wherever Flows run. Time is UTC in that world. So how does one bring the concept of a time, local to the user, into that world?
Let’s start with a simple case of a manual flow, a.k.a. push a button on your mobile device. Here’s the challenge – whatever button passes to the flow, including a timestamp, is in UTC. Challenge accepted.
- Read about trigger tokens, all device goodness is there but, as I said, timestamp is UTC.
- Latitude and longitude are also among trigger tokens and available when you run a button flow
Note: if you are using these values, your phone mobile device must have location services enabled otherwise:
Ok, now that we have latitude and longitude, we need to convert them into the time zone information.
- In your Azure account, add Bing Maps API for Enterprise (don’t worry, it’s free up to 10,000 transactions per month). Don’t have Azure account and really don’t want one? You can still use https://www.bingmapsportal.com/ for a time being to register an account and get yourself an API key. Check the usage rights because copyright message is very explicit:
This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.
- The API we are after is Find Time Zone and the call looks like this:
- Use Postman to get a sample response and then use Parse JSON action to extract values from the API response. The coveted value is
- Convert time zone action will give us the conversion we are after (button is kind to give us the timestamp when it was pushed)
- Finally, we can call a location API to get the place or neighborhood (full address is available as a trigger token) and then send a notification to ourselves telling us what was the time and where we pushed that button
The results are awesome:
I noticed that all posts about Flow are full of images. I fell into that trap too, it seems, but for the last time. Instead, download the flow (sans the keys) here and import into your environment to play with it.
(Cover photo by Ehimetalor Unuabona on Unsplash)