0

Bit of a newbie with JavaScript and I have spent ages trying to work this one out: I am allowing a visitor to book a future meeting date & time (at the visitor's local time)

I am in UK time and whilst not wanting to constrict the available meeting time, would like to show the visitor what the UK time would be for their requested Date/Time.

So I get the future date from the visitor, get their local timezoneoffset, so now I need to find whether (for the meeting date) either the visitor's local time and / or the UK time is subject to DST and make the necessary adjustments.

I have seen functions that ascertain whether DST is in effect for the current date but I can't see a function that will do the same for a future date, or a different timezone. Are there such functions or do I need to find the visitor's TZ and run the future date against a list of Timezones Start Date / End Dates?

Regards, Nick

Huangism
  • 16,278
  • 7
  • 48
  • 74
Nick
  • 27
  • 6
  • Doesn't answer the question directly, but assuming you've got some sort of backend code in use, what is it? For example, the .Net date objects will handle this for you quite easily - it may be easier to perform an ajax request to deal with this? – James Thorpe Sep 02 '14 at 10:41
  • looks like similar functionality is available in [setTimeZone](http://php.net/manual/en/datetime.settimezone.php) - according to [this post](http://stackoverflow.com/questions/9736789/php-datetime-dst) it should handle DST automatically for you also – James Thorpe Sep 02 '14 at 10:51
  • Thanks for the links and info, I was looking at a js solution for instant display but if js can't handle it easily it looks like php can. Again, thanks for assistance – Nick Sep 02 '14 at 11:05

1 Answers1

0

As James suggested in the question comments, this is best done in your back-end code. You said you were using PHP, so you should look to DateTimeZone::getTransitions, or perhaps to IntlCalendar::inDaylightTime.

However, there are solutions for working with time zones in JavaScript. You'll need one of the libraries listed here. In particular, you may want to look at moment-timezone, which you can do something like this:

moment.tz('2015-07-01','Europe/London').isDST()
Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575