My goal is to create a time zone converter that will compare two different date field inputs from a pdf form to decide which array to send to my function that populates the drop down lists. One array has UTC offsets for DST and the other has UTC offsets disregarding DST. I first tried to write a conditional statement that checked the date against a static date but this would have to be amended every year. Is there a way to take advantage of javascript to make this an easier process? Ideally I’d like a self adjusting code but 1 adjustment every year is not the end of the world. The original idea consisted of this general idea (psuedocode):
if(11 Mar 2012 < date < 04 Nov 2012){
CountryCode = CountryCodeDST}
else{
CountryCode = CountryCode}
Here are the arrays with the function. Any ideas? Guidance? This is my first exposure to javascript and hopefully this question makes sense and can help others along with myself.
var CountryCode = new Array(
"CST",
"EST",
"MST",
"MST-Arizona");
var UTCoffset = new Array(
"GMT+0600",
"GMT+0500",
"GMT+0700",
"GMT+0700");
var CountryCodeDST = new Array(
"CST",
"EST",
"MST",
"MST-Arizona");
var UTCoffsetDST = new Array(
"GMT+0500",
"GMT+0400",
"GMT+0600",
"GMT+0700");
function TZ_Populate(dropdownField)
{
for (var i=0; i < CountryCode.length; i++)
dropdownField.addItem(CountryCode[i]);
}
function TZ_ReadOut(TZ_Alias, UTC_Alias)
{
for (var i = 0; i < CountryCode.length; i++)
{
if (CountryCode[i] == TZ_Alias)
{
UTC_Alias.rawValue = UTCoffset[i];
break;
}
}
}
This is actually really easy in Javascript, because behind the scenes Javascript represents dates as integers (specifically the number of milliseconds since the epoch point). As a result, you can write almost literally the same code you had, and have it actually work: