Deluge Script to convert timezone if required
Hi there, I have written a deluge script to convert a time string to account for timezone differences.
In short, in my CRM I have 4 fields that are being referenced:
1. RH2 Appointment Time - this is a text string, that shows as "09:00 am" (or other time, in this same format)2. Specialist State During Booking= this is a text string, and shows what State the specialist will be in - i.e "VIC" (Victoria, Australia).3. ClaimantState During Booking = this is a text string, and shows what State the claimant will be in - i.e. "TAS" (Tasmania, Australia).
4. Appointment Time at Claimant Location - this is a text string field that I want Deluge to convert the time from using 1 and 2, to the relevant time based on 3.
The below code works to an extent, but it seems to assume the time entered in 1 is based on the CRM timezone of Queensland Australia.So when i run the code on a booking where 2=VIC, and 3=TAS, it increments the time by 1 hour (which is the difference between QLD and TAS). But actually, VIC and TAS are on the same timezone.Can anyone help me identify what i've missed in my code, so it will work as expected?- bookingid = zoho.crm.getRecordById("Bookings",bID);
- appointment_start = bookingid.get("RHO_Appointment_Time");
- ApptSpecState = bookingid.get("Specialist_State_During_Booking");
- ApptClientState = bookingid.get("Claimant_State_During_Booking");
- claimant_timezone = "";
- if(ApptSpecState != ApptClientState)
- {
- if(ApptClientState == "QLD")
- {
- claimant_timezone = "Australia/Queensland";
- }
- else if(ApptClientState == "TAS")
- {
- claimant_timezone = "Australia/Tasmania";
- }
- else if(ApptClientState == "NSW")
- {
- claimant_timezone = "Australia/NSW";
- }
- else if(ApptClientState == "VIC")
- {
- claimant_timezone = "Australia/Victoria";
- }
- else if(ApptClientState == "SA")
- {
- claimant_timezone = "Australia/Adelaide";
- }
- else if(ApptClientState == "WA")
- {
- claimant_timezone = "Australia/Perth";
- }
- else if(ApptClientState == "NT")
- {
- claimant_timezone = "Australia/Darwin";
- }
- else if(ApptClientState == "ACT")
- {
- claimant_timezone = "Australia/Canberra";
- }
- else
- {
- claimant_timezone = "Australia/Queensland";
- }
- appointment_in_local_time = "";
- appointment_in_local_time = appointment_start.toTime("hh:mm a").toString("hh:mm a",claimant_timezone);
- zoho.crm.updateRecord("Bookings",bID,{"Appointment_Time_at_Claimant_Location":appointment_in_local_time});
- }