For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.
Zoho Creator/Deluge: Calculating with Timezone Offset

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 Creator :: Article: 325

Accreditation

Badge - Zoho Creator Certified Developer Associate
Badge - Zoho Deluge Certified Developer
Badge - Certified Zoho CRM Developer

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 bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF

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: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience 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