26Mar
By: Anton Nielsen On: March 26, 2021 In: APEX Developer Solutions, Instant Tips Comments: 0

As of version 20.2, the Automatic Time Zone setting in APEX presents two significant challenges:

1. It won’t account for changes in local time zones (such as EST to EDT)

2. It won’t work with public applications that do deep linking.

Anton solves both these issues by bypassing the ‘Automatic Time Zone encoding’ APEX feature. See his alternative in this week’s episode.

Detailed instructions on the solution

Create Page 0: Global Page Region and Item

Create Page Zero Region and Item

Create a Region named TZ Region

Note: if you don’t want this region and item to show, set the Template to “Inline Dialog”

Create a Region named TZ Region

Create an item P0_TZ

Item Type: Text Field Warn on Unsaved Changes: Ignore

Create an item P0_TZ

Note: if you would like this to be a Time Zone selector follow the instruction in the last section.

Create Page 0 Dynamic Action: Set Session Time Zone

Create Page 0 Dynamic Action: Set Session Time Zone

Create Dynamic Action as shown:

Create Dynamic Action as shown

Create True Action 1: Set Value

Create True Action 1

JavaScript Expression

Intl.DateTimeFormat().resolvedOptions().timeZone;
Create True Action 2: Execute Server-side Code

Create True Action 2

PL/SQL Code

begin
    apex_util.set_session_time_zone( P_TIME_ZONE => :P0_TZ);
end;
Create True Action 3: Execute JavaScript Code

Create True Action 3

JavaScript Code

location.reload();

Change to be a Time Zone Selector

Ensure that TZ Region and P0_TZ are visible on pages

Change P0_TZ to be a Select List

Change P0_TZ to be a Select List

Set the List of Values to be a SQL Query

Set the List of Values to be a SQL Query

select distinct tzname d, tzname  r
       from V$TIMEZONE_NAMES
  order by 1

Duplicate the Page Load Dynamic Action and make changes to it

Duplicate the Page Load Dynamic Action and make changes to it

Change the Name to “Change Time Zone” Change the “When” settings Change the Server-side Condition Delete the “Set Value” true action

Insum's APEX Instant Tips: Every Friday at 12:05pm EST

Join Anton and Hayden every Friday at 12:05pm EST live on our Facebook and YouTube channels, as they present a new APEX tip every week.

Subscribe and hit the bell to be notified so you never miss a thing!

View Past Episodes

Full episode list on YouTube here.

Share this:
Share

Leave reply:

Your email address will not be published. Required fields are marked *