- Mark as New
- Follow
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
I don't believe that there is timezone info available in FormCalc, so I worked this out in javascript.
Javascript is able to get the local system time and timezone of the machine that the script is running on. There is no way to obtain the timezone for NY from a random system, so it needs to be set as a constant in the script. This will change from GMT-4 to GMT-5 depending on whether daylight savings time is in force, but you might want to ignore the hour difference.
Here's the script to do the calculation. You will just need to change the NY_TARGET_DATE constant to whatever date you want.
// The following two constants must be set for your current situation
// NY_TIME_ZONE_DATE_OFFSET = timezone difference between GMT and NY
// NY_TARGET_DATE = the deadline date
var NY_TIME_ZONE_OFFSET = -4;
var NY_TARGET_DATE = "4/8/2010";
var ONE_HOUR_IN_MS = 1000*60*60;
var ONE_DAY_IN_MS = ONE_HOUR_IN_MS * 24;
var nyTimeZoneOffsetMs = NY_TIME_ZONE_OFFSET * ONE_HOUR_IN_MS;
// Obtain target NY date/time as milliseconds
var targetNYDate = new Date(NY_TARGET_DATE);
var targetNYTimeMs = targetNYDate.getTime();
// Get current local date/time from the system as milliseconds
var currentLocalDate = new Date();
var currentLocalTimeMs = currentLocalDate.getTime();
// Get offset of local system timezone from UTC. This
// will be in minutes; convert to milliseconds by multiplying
// by 60000 (60 sec/minute, 1000ms/second)
var localTzOffset = currentLocalDate.getTimezoneOffset() * 60000;
// Add local timezone offset to current local time to convert our local time to UTC
var utcDate = new Date(currentLocalTimeMs += localTzOffset);
// Calculate current NY time by adding NY offset to UTC
var currentNYTimeMs = utcDate.getTime()+ nyTimeZoneOffsetMs;
// Get difference between the target NY date/time
// and current NY date/time in milliseconds
var timeDifferenceMs = targetNYTimeMs - currentNYTimeMs
// Divide by number of milliseconds in a day to get number of days.
// Math.ceil will round up. Will return a positive number of days until
// target date; zero if same day as target date, and
// negative number if past the target date.
var numDays = Math.ceil(timeDifferenceMs / ONE_DAY_IN_MS);
this.rawValue = numDays;
Views
Replies
Total Likes