For a product to be accepted globally, it is very important that the product is flexible enough to function as per the suitability of the end-users, be it in USA or Africa or any other part of the world for that matter. One of the biggest challenges that a product needs to meet is the concept of Daylight Saving Time. Also called “Summer Time” in many places in the world, **Daylight Saving** **Time (DST)** is the practice of setting the clocks forward 1 hour from the standard time during the summer months, and back again in the fall, in order to make better use of natural **daylight**. To flexibly adjust to this arrangement is what Clinicea can boast of.

*We will take the example of Atlanta to walk through this functionality over a variety of situations as follows:*

*Atlanta Time Zone: UTC- 5*

In Atlanta** Daylight Time Saving** for 2017 began on 12 March and is set to end on 5 November. This is how it works:

*12 Mar 2017 – Daylight Saving Time Started*

*When local standard time was about to reach
Sunday, 12 March 2017, 02:00:00 clocks were turned forward 1 hour to
Sunday, 12 March 2017, 03:00:00 local daylight time instead.
Sunrise and sunset were about 1 hour later on 12 Mar 2017 than the day before. There was more light in the evening.*

*5 Nov 2017 – Daylight Saving Time Ends*

*When local daylight time is about to reach
Sunday, 5 November 2017, 02:00:00 clocks are turned backward 1 hour to
Sunday, 5 November 2017, 01:00:00 local standard time instead.*

*Sunrise and sunset will be about 1 hour earlier on 5 Nov 2017 than the day before. There will be more light in the morning.*

*Sunrise and sunset were about 1 hour later on 12 Mar 2017 than the day before. There was more light in the evening.*

**As a result, we will basically have a difference of 2 hours (03:00:00- 01:00:00) for one of the cycles with respect to the other.**

Now let us go through the various test cases possible for the same and find out if the adjustment is happening accordingly.

*1.Suppose, on April 1, sitting here in India you are making an appointment for a clinic in Atlanta for April 2 at 6 am. Atlanta Time Zone is UTC-5, which will be further subtracted by 2:00 (considering the daylight time saving). Hence, we need to create an appointment at 1 pm (our time) so that it is at parlance with their time. If this appointment is being viewed on April 2 from Atlanta it should show 6:00 am. Here is how it is achieved.*

We will use three variable to understand this logic:-

**T= Database Time, i.e, the time at which you saved the appointment in your database (13:00 in this case).
x= Time Zone Offset when Appointment was created (-7:00 in this case considering DTS)
y= Time zone offset of the system you are currently(for April 2 in this case) using to view the appointment. This also will be -7:00 for this case.**

The desired result of appointment time viewed from Atlanta on April 2 should be 6:00 am.

So ** T+ x ** should give us the desired result. However at the very core of everything we have JavaScript which is used send data to the Web Service and JavaScript usually uses the** time zone offset of the system you are currently using** and hence ignoring all the possible calculations that you want the data to undergo. This gives us the third variable for our experiment i.e, **y. **As a result even though all the calculations are meeting the desired result using the formula **T+ x**, in reality we might get an entirely different result depending on the data that is processed through JavaScript which might stand as something like this

**(T + x) = (T+ y) which will be a complete mismatch.**

Where, T+ x is the desired value while T+ y is the one which we might be getting.

So in order to compensate for this, our final formula will be as follows:

**T+ x = T+ y – y + x**

Now coming back to our first test case, we have **T=13:00, x= -7:00 and y= -7:00**

hence, **T+ x= 13:00 + (-7:00) – (-7:00) + (-7:00)= 6:00 am which is the desired time.**

*2.Now if the appointment created above is viewed on 1 December, i.e, after Daylight Time Saving, the clinic should be able to see it at 6:00 am itself.*

Going by the above-mentioned formula this can be achieved as follows:

Here **y= -5:00 **because we are viewing the appointment on 1 December which is **after DTS.**

**x= -7:00 **because appointment was created on April 1 which is** during DTS**

**T + x = T + y – y +x
= 13:00 + (-5:00) – (-5:00) + (-7:00)= 6:00 am**

*3.Suppose you have created an appointment on April 1 (during DTS) for December 1 (after DTS) at 6:00 am. What will be the time of appointment that you should see when you view the calendar on April 2? Let’s find it out as follows:*

Here **T=** **13:00** am because the time when we are creating the appointment is **during DTS**.

**x= -7:00 **because appointment was created on April 1** (****during DTS)
**y=

**-7:00**because appointment is viewed on April 2

**(**

**during DTS)**

So,

**T + x = T + y – y +x
= 13:00 + (-7:00) – (-7:00) + (-7:00) = 6:00 am.
This gives you the result which is exactly at parlance with what the clinic in Atlanta would like to see when they log in on April 2.**

*4.Let us again consider that the appointment created for test case 3 is to be viewed on December 2 which falls in the DTS cycle different from the one in which the appointment was created.*

Here **T=** **13:00** am because the time when we are creating the appointment is during DTS.

**x= -7:00 **because appointment was created on April 1**(during DTS).
**y=

**-5:00**because appointment is viewed on December 2

**(after DTS).**

So,

**T + x = T + y – y +x
= 13:00 + (-5:00) – (-5:00) + (-7:00) = 6:00 am.
This gives you the result which is exactly at parlance with what the clinic in Atlanta would like to see when they log in on December 2.**

Till now, all the test cases we have analysed, for all of them, **Appointment Creation Time was during DTS**. Now let us implement the same logic by creating appointments after **DTS.**

*5.Imagine that you have created an appointment on 1 December for a future date of 2 April at 6:00 am. When this appointment is viewed on 2 December, how should it look?*

Here **T=** **11:00** am because the time for which we are creating the appointment is after DTS. Hence **UTC-5.**

**x= -5:00 because appointment was created on December 1.
**y=

**-5:00 because appointment is viewed on December 2.**

So,

**T + x = T + y – y +x
= 11:00 + (-5:00) – (-5:00) + (-5:00) = 6:00 am.
**This gives you the result which is exactly at parlance with what the clinic in Atlanta would like to see when they log in on December 2.

*6.Now, the appointment you created for test case 5 is to be viewed just a day before the appointment date which will be 1 April. It should again show at 6:00 am.*

Here **T=** **11:00** am because the time for which we are creating the appointment is after DTS. Hence **UTC-5.**

**x= -5:00 because appointment was created on December 2
**y=

**-7:00 because appointment is viewed on April 1.**

So,

**T + x = T + y – y +x
= 11:00 + (-7:00) – (-7:00) + (-5:00) = 6:00 am.
**This gives you the result which is exactly at parlance with what the clinic in Atlanta would like to see when they log in on April 1.

*7.Imagine you had created an appointment on 1 December for the same day and trying to view it on a later day December 2 which falls in the same DST cycle. *

Here **T=** **11:00** am because the time for which we are creating the appointment is after DTS. Hence **UTC-5.**

**x= -5:00 because the appointment was created on December 1.
**y=

**-5:00 because the appointment is viewed on December 2.**

So,

**T + x = T + y – y +x
= 11:00 + (-5:00) – (-5:00) + (-5:00) = 6:00 am.
**This gives you the result which is exactly at parlance with what the clinic in Atlanta would like to see when they log in on December 2.

*8.Imagine you had created an appointment on 1 December for the same day and trying to view it on a later date April 2 which falls in the different DST cycle. *

Here **T=** **11:00** am because the time for which we are creating the appointment is after DTS. Hence **UTC-5.**

**x= -5:00 because the appointment was created on December 1.
**y=

**-7:00 because the appointment is viewed on April 2.**

So,

**T + x = T + y – y +x
= 11:00 + (-7:00) – (-7:00) + (-5:00) = 6:00 am.
**This gives you the result which is exactly at parlance with what the clinic in Atlanta would like to see when they log in on April 2.

—————————————————————————————————————————————-