For Zoho Services only:


I'm actually part of a bigger team at Ascent Business Solutions where we have support technicians and project consultants. Support is for smaller technical fixes but this can include developments, reports or integrations; depending on the size of the task. Projects are for more time-consuming developments such as revamps of the Zoho Suite of apps or on-site training. The advantage of a team is that if I am out-of-office for a day or so, there is always someone at Ascent Business Solutions who can deal with any queries/issues you may have.

Our support rates can be found and purchased at http://ascentbusiness.co.uk/zoho-support-2. A support bundle doesn't have an expiry date. So whether we can do what you want within the bundle and a year later need further support, if there are minutes left on the bundle then there is no additional charge.

Our project rates for bigger developments can be found at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices and will involve a dedicated project consultant along with developers who will hold your hand through the development process.

If you want help building a solution for one of the Zoho Apps in the Zoho Suite, contact us on 0121 392 8140 (UK) or by email at info@ascentbusiness.co.uk. You can also visit our website at http://ascentbusiness.co.uk.

I regularly build and specialize in 2-way API integrations for Xero, Shopify and eBay.

Zoho Creator/Deluge: Calculating with Timezone Offset

What?
This is an article to remind me how to calculate various times for an appointment booking system based on the timezones of each party.

Why?
The use-case scenario is that our Creator server uses the US datacenter but has it's server timezone set to "US/Eastern" or "America/New_York" (-05:00). Our sales person is on the west coast in the timezone "America/Los_Angeles" (-08:00). And our customer is in "Europe/Luxembourg" (+01:00).

We want to tell our customer they have an appointment at 4pm their time in Luxembourg; tell the agent/salesperson to call the customer at 7am in Los Angeles; and tell headquarters or the system calendar that the appointment is at 10am.

How?
So adding a datetime field and calling this one the "Customers Appointment Time" is the wrong first step. Reason being is that datetime fields hold the time zone they are set in (ZohoCreator > Settings > Date and Time Settings); so as soon as you try to insert a date time and perhaps accompany that value with a timezone, several calculations happen in real-time making it really difficult to extract and use.

The key trick I used was to actually use a single-line text to store the customer's requested time. Let's use the appointment example mentioned above for a customer in UTC+1 @ 4pm their time. The server is on Eastern time UTC-5 and the agent is in Los Angeles UTC-8. For this first example, we're not bother with Daylight Savings Time. The field is a text line field called Customers_Requested_Time and I have added a few more date time fields called GMT_Date_Time_Start, GMT_Date_Time_End, System_Date_Time_Start, System_Date_Time_End, Agent_Date_Time_Start, and Agent_Date_Time_End:
copyraw
// defaults
v_AppointmentDuration = 30;
//
// get customer's requested time
v_CustomersRequestedTime = input.Customers_Requested_Time.toTime();
v_CustomerTimeZoneName = "(+01:00) Europe/Luxembourg";
v_CustomerOffset = "+01:00";
//
// calculate GMT
v_CustomerPlusMinus = v_CustomerOffset.subString(0,1);
v_CustomerHours = v_CustomerOffset.subString(1,3).toLong();
v_CustomerMinutes = v_CustomerOffset.subString(4,6).toLong();
if(v_CustomerPlusMinus == "+")
{
    input.GMT_Date_Time_Start = v_CustomersRequestedTime.subHour(v_CustomerHours).subMinutes(v_CustomerMinutes);
}
else
{
    input.GMT_Date_Time_Start = v_CustomersRequestedTime.addHour(v_CustomerHours).addMinutes(v_CustomerMinutes);
}
if(!isnull(input.GMT_Date_Time_Start))
{
    input.GMT_Date_Time_End = input.GMT_Date_Time_Start.addMinutes(v_AppointmentDuration);
}
//
// calculate Eastern time (System HQ)
if(!isnull(input.GMT_Date_Time_Start))
{
    // subtract 5 hours from GMT as system is based in US/Eastern time
    input.System_Date_Time_Start = input.GMT_Date_Time_Start.subHour(5);
    input.System_Date_Time_End = input.System_Date_Time_Start.addMinutes(v_AppointmentDuration);
}
//
// calculate Agents time
v_AgentTimeZoneName = "(-08:00) America/Los_Angeles";
v_AgentOffset = "-08:00";
v_AgentPlusMinus = v_AgentOffset.subString(0,1);
v_AgentHours = v_AgentOffset.subString(1,3).toLong();
v_AgentMinutes = v_AgentOffset.subString(4,6).toLong();
if(v_AgentPlusMinus == "+")
{
    input.Agent_Date_Time_Start = input.GMT_Date_Time_Start.addHour(v_AgentHours).addMinutes(v_AgentMinutes);
    input.Agent_Date_Time_End = input.Agent_Date_Time_Start.addMinutes(v_AppointmentDuration);
}
else
{
    input.Agent_Date_Time_Start = input.GMT_Date_Time_Start.subHour(v_AgentHours).subMinutes(v_AgentMinutes);
    input.Agent_Date_Time_End = input.Agent_Date_Time_Start.addMinutes(v_AppointmentDuration);
}
//
// display confirmation text
v_ResultInformation = "<table>";
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Customer:</b></td><td>" + input.Name + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Phone:</b></td><td>" + input.Phone_Number + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Email:</b></td><td>" + input.Email + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Event:</b></td><td>" + v_AppointmentType + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Duration:</b></td><td>" + v_AppointmentDuration + " Minutes</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Customer's Appointment Date/Time:</b>   </td>");
v_ResultInformation = v_ResultInformation.concat("<td>" + v_CustomersRequestedTime.toString("EEEE, MMMM dd, yyyy @ h:mma") + "   " + v_CustomerTimeZoneName + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Agent's Appointment Date/Time:</b></td>");
v_ResultInformation = v_ResultInformation.concat("<td>" + input.Agent_Date_Time_Start.toString("EEEE, MMMM dd, yyyy @ h:mma") + "   " + v_AgentTimeZoneName + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("</table>");
input.Note_BookedTimeSelection = v_ResultInformation;
  1.  // defaults 
  2.  v_AppointmentDuration = 30
  3.  // 
  4.  // get customer's requested time 
  5.  v_CustomersRequestedTime = input.Customers_Requested_Time.toTime()
  6.  v_CustomerTimeZoneName = "(+01:00) Europe/Luxembourg"
  7.  v_CustomerOffset = "+01:00"
  8.  // 
  9.  // calculate GMT 
  10.  v_CustomerPlusMinus = v_CustomerOffset.subString(0,1)
  11.  v_CustomerHours = v_CustomerOffset.subString(1,3).toLong()
  12.  v_CustomerMinutes = v_CustomerOffset.subString(4,6).toLong()
  13.  if(v_CustomerPlusMinus == "+") 
  14.  { 
  15.      input.GMT_Date_Time_Start = v_CustomersRequestedTime.subHour(v_CustomerHours).subMinutes(v_CustomerMinutes)
  16.  } 
  17.  else 
  18.  { 
  19.      input.GMT_Date_Time_Start = v_CustomersRequestedTime.addHour(v_CustomerHours).addMinutes(v_CustomerMinutes)
  20.  } 
  21.  if(!isnull(input.GMT_Date_Time_Start)) 
  22.  { 
  23.      input.GMT_Date_Time_End = input.GMT_Date_Time_Start.addMinutes(v_AppointmentDuration)
  24.  } 
  25.  // 
  26.  // calculate Eastern time (System HQ) 
  27.  if(!isnull(input.GMT_Date_Time_Start)) 
  28.  { 
  29.      // subtract 5 hours from GMT as system is based in US/Eastern time 
  30.      input.System_Date_Time_Start = input.GMT_Date_Time_Start.subHour(5)
  31.      input.System_Date_Time_End = input.System_Date_Time_Start.addMinutes(v_AppointmentDuration)
  32.  } 
  33.  // 
  34.  // calculate Agents time 
  35.  v_AgentTimeZoneName = "(-08:00) America/Los_Angeles"
  36.  v_AgentOffset = "-08:00"
  37.  v_AgentPlusMinus = v_AgentOffset.subString(0,1)
  38.  v_AgentHours = v_AgentOffset.subString(1,3).toLong()
  39.  v_AgentMinutes = v_AgentOffset.subString(4,6).toLong()
  40.  if(v_AgentPlusMinus == "+") 
  41.  { 
  42.      input.Agent_Date_Time_Start = input.GMT_Date_Time_Start.addHour(v_AgentHours).addMinutes(v_AgentMinutes)
  43.      input.Agent_Date_Time_End = input.Agent_Date_Time_Start.addMinutes(v_AppointmentDuration)
  44.  } 
  45.  else 
  46.  { 
  47.      input.Agent_Date_Time_Start = input.GMT_Date_Time_Start.subHour(v_AgentHours).subMinutes(v_AgentMinutes)
  48.      input.Agent_Date_Time_End = input.Agent_Date_Time_Start.addMinutes(v_AppointmentDuration)
  49.  } 
  50.  // 
  51.  // display confirmation text 
  52.  v_ResultInformation = "<table>"
  53.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Customer:</b></td><td>" + input.Name + "</td></tr>")
  54.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Phone:</b></td><td>" + input.Phone_Number + "</td></tr>")
  55.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Email:</b></td><td>" + input.Email + "</td></tr>")
  56.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Event:</b></td><td>" + v_AppointmentType + "</td></tr>")
  57.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Duration:</b></td><td>" + v_AppointmentDuration + " Minutes</td></tr>")
  58.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Customer's Appointment Date/Time:</b>   </td>")
  59.  v_ResultInformation = v_ResultInformation.concat("<td>" + v_CustomersRequestedTime.toString("EEEE, MMMM dd, yyyy @ h:mma") + "   " + v_CustomerTimeZoneName + "</td></tr>")
  60.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Agent's Appointment Date/Time:</b></td>")
  61.  v_ResultInformation = v_ResultInformation.concat("<td>" + input.Agent_Date_Time_Start.toString("EEEE, MMMM dd, yyyy @ h:mma") + "   " + v_AgentTimeZoneName + "</td></tr>")
  62.  v_ResultInformation = v_ResultInformation.concat("</table>")
  63.  input.Note_BookedTimeSelection = v_ResultInformation; 

Additional: Daylight Savings Time
Just to cover all aspects of this, I create a Zoho Creator form with the timezone names, their offset and their DST offset as well as a boolean to say whether Daylight Savings Time is in effect for this timezone or not. So let's pretend we have a creator form wth the following fields:
  • TZ Database Name (single-line)
  • UTC Offset (single-line)
  • UTC DST Offset (single-line)
  • DST In Effect (boolean)
Zoho Creator/Deluge: Calculating with Timezone Offset: Creator form
Zoho Creator/Deluge: Calculating with Timezone Offset: Creator Report

With the addition of 2 lookup fields to our booking form: one called "Customer's TimeZone" and the other called "Agent TimeZone", then our code needs to take these into account and will look more like the following:
copyraw
// defaults
v_AppointmentType = "Initial Consultation";
v_AppointmentDuration = 30;
v_CustomerTimeZoneName = "(+01:00 :: Europe/Luxembourg)";
v_CustomerOffset = "+01:00";
v_AgentTimeZoneName = "(-08:00 :: America/Los_Angeles)";
v_AgentOffset = "-08:00";
//
// get customer's requested time
v_CustomersRequestedTime = input.Customers_Requested_Time.toTime();
if(!isnull(input.Customer_s_TimeZone))
{
    r_CustomerTimezone = TimeZones[ID == input.Customer_s_TimeZone];
    if(r_CustomerTimezone.count() > 0)
    {
        if(r_CustomerTimezone.DST_In_Effect)
        {
            v_CustomerOffset = r_CustomerTimezone.UTC_DST_Offset;
        }
        else
        {
            v_CustomerOffset = r_CustomerTimezone.UTC_Offset;
        }
        v_CustomerTimeZoneName = "(" + v_CustomerOffset + " :: " + r_CustomerTimezone.TZ_Database_Name + ")";
    }
}
//
// calculate GMT
v_CustomerPlusMinus = v_CustomerOffset.subString(0,1);
v_CustomerHours = v_CustomerOffset.subString(1,3).toLong();
v_CustomerMinutes = v_CustomerOffset.subString(4,6).toLong();
if(v_CustomerPlusMinus == "+")
{
    input.GMT_Date_Time_Start = v_CustomersRequestedTime.subHour(v_CustomerHours).subMinutes(v_CustomerMinutes);
}
else
{
    input.GMT_Date_Time_Start = v_CustomersRequestedTime.addHour(v_CustomerHours).addMinutes(v_CustomerMinutes);
}
if(!isnull(input.GMT_Date_Time_Start))
{
    input.GMT_Date_Time_End = input.GMT_Date_Time_Start.addMinutes(v_AppointmentDuration);
}
//
// calculate Eastern time (System HQ)
if(!isnull(input.GMT_Date_Time_Start))
{
    // subtract 5 hours from GMT as system is based in US/Eastern time
    input.System_Date_Time_Start = input.GMT_Date_Time_Start.subHour(5);
    input.System_Date_Time_End = input.System_Date_Time_Start.addMinutes(v_AppointmentDuration);
}
//
// calculate Agents time
if(!isnull(input.Agent_TimeZone))
{
    r_AgentTimezone = TimeZones[ID == input.Agent_TimeZone];
    if(r_AgentTimezone.count() > 0)
    {
        if(r_AgentTimezone.DST_In_Effect)
        {
            v_AgentOffset = r_AgentTimezone.UTC_DST_Offset;
        }
        else
        {
            v_AgentOffset = r_AgentTimezone.UTC_Offset;
        }
        v_AgentTimeZoneName = "(" + v_AgentOffset + " :: " + r_AgentTimezone.TZ_Database_Name + ")";
        
    }
}
v_AgentPlusMinus = v_AgentOffset.subString(0,1);
v_AgentHours = v_AgentOffset.subString(1,3).toLong();
v_AgentMinutes = v_AgentOffset.subString(4,6).toLong();
if(v_AgentPlusMinus == "+")
{
    input.Agent_Date_Time_Start = input.GMT_Date_Time_Start.addHour(v_AgentHours).addMinutes(v_AgentMinutes);
    input.Agent_Date_Time_End = input.Agent_Date_Time_Start.addMinutes(v_AppointmentDuration);
}
else
{
    input.Agent_Date_Time_Start = input.GMT_Date_Time_Start.subHour(v_AgentHours).subMinutes(v_AgentMinutes);
    input.Agent_Date_Time_End = input.Agent_Date_Time_Start.addMinutes(v_AppointmentDuration);
}
//
// display confirmation text
v_ResultInformation = "<table>";
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Customer:</b></td><td>" + input.Name + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Phone:</b></td><td>" + input.Phone_Number + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Email:</b></td><td>" + input.Email + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Event:</b></td><td>" + v_AppointmentType + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Duration:</b></td><td>" + v_AppointmentDuration + " Minutes</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Customer's Appointment Date/Time:</b>   </td>");
v_ResultInformation = v_ResultInformation.concat("<td>" + v_CustomersRequestedTime.toString("EEEE, MMMM dd, yyyy @ h:mma") + "   " + v_CustomerTimeZoneName + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Agent Appointment Date/Time:</b></td>");
v_ResultInformation = v_ResultInformation.concat("<td>" + input.Agent_Date_Time_Start.toString("EEEE, MMMM dd, yyyy @ h:mma") + "   " + v_AgentTimeZoneName + "</td></tr>");
v_ResultInformation = v_ResultInformation.concat("</table>");
input.Note_BookedTimeSelection = v_ResultInformation;
  1.  // defaults 
  2.  v_AppointmentType = "Initial Consultation"
  3.  v_AppointmentDuration = 30
  4.  v_CustomerTimeZoneName = "(+01:00 :: Europe/Luxembourg)"
  5.  v_CustomerOffset = "+01:00"
  6.  v_AgentTimeZoneName = "(-08:00 :: America/Los_Angeles)"
  7.  v_AgentOffset = "-08:00"
  8.  // 
  9.  // get customer's requested time 
  10.  v_CustomersRequestedTime = input.Customers_Requested_Time.toTime()
  11.  if(!isnull(input.Customer_s_TimeZone)) 
  12.  { 
  13.      r_CustomerTimezone = TimeZones[ID == input.Customer_s_TimeZone]
  14.      if(r_CustomerTimezone.count() > 0) 
  15.      { 
  16.          if(r_CustomerTimezone.DST_In_Effect) 
  17.          { 
  18.              v_CustomerOffset = r_CustomerTimezone.UTC_DST_Offset; 
  19.          } 
  20.          else 
  21.          { 
  22.              v_CustomerOffset = r_CustomerTimezone.UTC_Offset; 
  23.          } 
  24.          v_CustomerTimeZoneName = "(" + v_CustomerOffset + :: " + r_CustomerTimezone.TZ_Database_Name + ")"
  25.      } 
  26.  } 
  27.  // 
  28.  // calculate GMT 
  29.  v_CustomerPlusMinus = v_CustomerOffset.subString(0,1)
  30.  v_CustomerHours = v_CustomerOffset.subString(1,3).toLong()
  31.  v_CustomerMinutes = v_CustomerOffset.subString(4,6).toLong()
  32.  if(v_CustomerPlusMinus == "+") 
  33.  { 
  34.      input.GMT_Date_Time_Start = v_CustomersRequestedTime.subHour(v_CustomerHours).subMinutes(v_CustomerMinutes)
  35.  } 
  36.  else 
  37.  { 
  38.      input.GMT_Date_Time_Start = v_CustomersRequestedTime.addHour(v_CustomerHours).addMinutes(v_CustomerMinutes)
  39.  } 
  40.  if(!isnull(input.GMT_Date_Time_Start)) 
  41.  { 
  42.      input.GMT_Date_Time_End = input.GMT_Date_Time_Start.addMinutes(v_AppointmentDuration)
  43.  } 
  44.  // 
  45.  // calculate Eastern time (System HQ) 
  46.  if(!isnull(input.GMT_Date_Time_Start)) 
  47.  { 
  48.      // subtract 5 hours from GMT as system is based in US/Eastern time 
  49.      input.System_Date_Time_Start = input.GMT_Date_Time_Start.subHour(5)
  50.      input.System_Date_Time_End = input.System_Date_Time_Start.addMinutes(v_AppointmentDuration)
  51.  } 
  52.  // 
  53.  // calculate Agents time 
  54.  if(!isnull(input.Agent_TimeZone)) 
  55.  { 
  56.      r_AgentTimezone = TimeZones[ID == input.Agent_TimeZone]
  57.      if(r_AgentTimezone.count() > 0) 
  58.      { 
  59.          if(r_AgentTimezone.DST_In_Effect) 
  60.          { 
  61.              v_AgentOffset = r_AgentTimezone.UTC_DST_Offset; 
  62.          } 
  63.          else 
  64.          { 
  65.              v_AgentOffset = r_AgentTimezone.UTC_Offset; 
  66.          } 
  67.          v_AgentTimeZoneName = "(" + v_AgentOffset + :: " + r_AgentTimezone.TZ_Database_Name + ")"
  68.   
  69.      } 
  70.  } 
  71.  v_AgentPlusMinus = v_AgentOffset.subString(0,1)
  72.  v_AgentHours = v_AgentOffset.subString(1,3).toLong()
  73.  v_AgentMinutes = v_AgentOffset.subString(4,6).toLong()
  74.  if(v_AgentPlusMinus == "+") 
  75.  { 
  76.      input.Agent_Date_Time_Start = input.GMT_Date_Time_Start.addHour(v_AgentHours).addMinutes(v_AgentMinutes)
  77.      input.Agent_Date_Time_End = input.Agent_Date_Time_Start.addMinutes(v_AppointmentDuration)
  78.  } 
  79.  else 
  80.  { 
  81.      input.Agent_Date_Time_Start = input.GMT_Date_Time_Start.subHour(v_AgentHours).subMinutes(v_AgentMinutes)
  82.      input.Agent_Date_Time_End = input.Agent_Date_Time_Start.addMinutes(v_AppointmentDuration)
  83.  } 
  84.  // 
  85.  // display confirmation text 
  86.  v_ResultInformation = "<table>"
  87.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Customer:</b></td><td>" + input.Name + "</td></tr>")
  88.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Phone:</b></td><td>" + input.Phone_Number + "</td></tr>")
  89.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Email:</b></td><td>" + input.Email + "</td></tr>")
  90.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Event:</b></td><td>" + v_AppointmentType + "</td></tr>")
  91.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Duration:</b></td><td>" + v_AppointmentDuration + " Minutes</td></tr>")
  92.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Customer's Appointment Date/Time:</b>   </td>")
  93.  v_ResultInformation = v_ResultInformation.concat("<td>" + v_CustomersRequestedTime.toString("EEEE, MMMM dd, yyyy @ h:mma") + "   " + v_CustomerTimeZoneName + "</td></tr>")
  94.  v_ResultInformation = v_ResultInformation.concat("<tr><td><b>Agent Appointment Date/Time:</b></td>")
  95.  v_ResultInformation = v_ResultInformation.concat("<td>" + input.Agent_Date_Time_Start.toString("EEEE, MMMM dd, yyyy @ h:mma") + "   " + v_AgentTimeZoneName + "</td></tr>")
  96.  v_ResultInformation = v_ResultInformation.concat("</table>")
  97.  input.Note_BookedTimeSelection = v_ResultInformation; 

Source(s):
Category: Zoho :: Article: 790

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 bc1qjtp4l4ra452wzvuk9a45yfj82zkahsyy2z379y
© 2022 Joel Lipman .com. All Rights Reserved.