To avoid the task of republishing the flow whenever the time zone springs forward or falls back, as in the previous example, you can use collection variables to consider offsets for a time zone. While this option requires more work initially, it eliminates the need for managing offsets stored in flow-level variables and offers more simplicity than using expressions.
This method uses a parallel array approach and saves the desired offsets that consider the bias offset for a timezone given a UTC DateTime value. This example is a setup of integer collection variables for Eastern timezone DateTime value calculations.
Note: The offset is -5 hours. Manually apply the daylight savings time bias to entries in the Flow.LocalTimeZoneMinuteOffsetCollection items as appropriate.
| Collection Item | Flow.UtcDateTimeCollection | Flow.LocalTimezoneMinuteOffsetCollection |
|---|
| Item 0 | Sunday, March 13, 2016 at 7:00 AM | -300 Note: -300 represents -300 minutes or -5 hours. |
| Item 1 | Sunday, November 6, 2016 at 8:00 AM | -240 Note: -240 represents -240 minutes or -4 hours. In this case, after Sunday, March 13, 2016 at 7:00 a.m. UTC (the first item in the collection) until Sunday, November 6, 2016 at 8:00 a.m. UTC, the system should offset a UTC DateTime value by -240 minutes, which ensures it is in the correct local time. |
| Item 2 | Sunday, March 12, 2017 at 7:00 AM | -300 |
| Item 3 | Sunday, November 5, 2017 at 8:00 AM | -240 |
| Item 4 | Sunday, March 11, 2018 at 7:00 AM | -300 |
| Item 5 | Sunday, November 4, 2018 at 8:00 AM | -240 |
| Item 6 | Sunday, March 10, 2019 at 7:00 AM | -300 |
| Item 7 | Sunday, November 3, 2019 at 8:00 AM | -240 |
| Item 8 | Sunday, March 8, 2020 at 7:00 AM | -300 |
| Item 9* | Sunday, November 1, 2020 at 8:00 AM | -240 |
* Add more entries for call flows that run past the year 2020.
This collection is a set of UTC DateTime values for when the Eastern time zone springs forward or falls back. Now, build a task that, when a flow initiates, looks for a local time based on DST and time zone considerations:
- Determine the UTC DateTime value for which the flow author wishes to get a local DateTime. For example, use an Update Data action or a Flow.StartDateTimeUtc to save off GetCurrentDateTimeUtc() to Flow.UtcDateTimeToCheck, or in this case, use Flow.StartDateTimeUtc.
- Add and configure a Loop action:
- Starting at Index 0, loop through the Flow.UTCDateTimeCollection.
- For the first value found in Flow.UTCDateTimeCollection greater than or equal to Flow.UtcDateTimeToCheck, save the corresponding minute offset from the same item index in Flow.LocalTimezoneMinuteOffsetCollection to Flow.MinuteOffsetToApply.
- After the loop, if no value is assigned to Flow.MinuteOffsetToApply, assign a default minute offset; for example, 300. In this situation, the UTC DateTime value for checking time does not have an entry greater than or equal to it in the Flow.UtcDateTimeCollection variable.
- Next, use the following expression to obtain the local time from the algorithm above:
Flow.MyLocalDateTimeToUse = AddMinutes(Flow.UtcDateTimeToCheck, Flow.MinuteOffsetToApply)
You now have a local time with the appropriate bias applied to it that you can use for calculations. The applied bias is based on the lookup value in the Flow.LocalTimezoneMinuteOffset collection.