Question

Hi all,

So I'm scratching my head here... British Summer Time runs from the last Sunday of March til the last Sunday of October. My JS-skills are not uber-fantastic.

I don't suppose any of you have a pre-written function (or feel like having a go at writing a function) to get the user's current date, check if it's between the 2 above dates, and return 0 or 1?

I'm struggling here, and it'd be a huge help if someone could point me to a relevant link or an even bigger help if somebody feels like writing a quick function for me!

Thanks guys! :)

8 answers to this question

Recommended Posts

  • 0

You can use the getTimezoneOffset() function in Javascript to determine what you need. The first line below gets the user's current date, the second line gets how offset they are to the current GMT :)

var d = new Date();

var offset = d.getTimezoneOffset();

  • 0

Thanks for that, but that's not what I asked for ;)

The user could be 8 hours behind, 6 hours ahead, on GMT, I don't really care... I just need to know whether BST is in effect.

I'm almost done writing a Wordpress plugin, so I guess I'll have to have another go at writing this function myself when it's the last thing left to do...

  • 0
  On 07/10/2011 at 12:24, TheLegendOfMart said:

Yes it is till Oct 30th 2am where the clocks will go back an hour.

LOL ... he read the title and not the question ;)

Try this:-

function dateWithin(beginDate,endDate,checkDate) {

var b,e,c;

b = Date.parse(beginDate);

e = Date.parse(endDate);

c = Date.parse(checkDate);

if((c <= e && c >= b)) {

return true;

}

return false;

}

You just need to hard code the start & end dates for BST.

  • 0
  Quote
You just need to hard code the start & end dates for BST.

Exactly, that's where I got stuck last time! :p There is no 'hard coded date' for when BST starts or ends. It's the last Sunday of March til the last Sunday of October :p

Thanks though, I appreciate the effort!

Edit: I think this is going to help me (merged with the above code), having a little go of it now: http://www.irt.org/articles/js050/

Edit 2: Actually, that isn't all of the code. The author's referencing numerous other bits of code, and some of it doesn't exist... i.e. that link doesn't give a complete working function.... I'm on the right lines though now at least!

  • 0

Well in the end, I just sent the finished plugin to my client using GMT times. It's what he requested after all! No doubt he'll come back to me complaining that he needs support for BST added, and sadly, the bit of code it affects must be written in JS, and I don't like JS :p

Oh well, cheers for the help though guys! If anyone has a working solution though, feel free to post it up... and if my client comes back and moans, then I'll post the working solution here for everyone too! :)

  • 0

This any help ?

http://www.michaelapproved.com/articles/daylight-saving-time-dst-detect/

To be honest, I'd do it server side, but then I have the luxury of having my own server and BST is automatically set and the server clock is set to GMT or BST accordingly, I assume you can't do this using PHP/ASP etc?

  • 0

Well as expected, my client eventually came back and asked for BST support to be added. So I went ahead and wrote the function. Feel free to scavenge, rip apart etc :)



<script>

/*
A function that determines whether BST is currently in effect in London,
based on the date on the user's PC, but regardless of whether the user
is in London, or somewhere else. BST runs between the last Sunday of
March, and the last Sunday of October, with a varying date each year.
*/
function isBSTinEffect()
{
var d = new Date();

// Loop over the 31 days of March for the current year
for(var i=31; i>0; i--)
{
var tmp = new Date(d.getFullYear(), 2, i);

// If it's Sunday
if(tmp.getDay() == 0)
{
// last Sunday of March
lSoM = tmp;

// And stop the loop
break;
}
}

// Loop over the 31 days of October for the current year
for(var i=31; i>0; i--)
{
var tmp = new Date(d.getFullYear(), 9, i);

// If it's Sunday
if(tmp.getDay() == 0)
{
// last Sunday of October
lSoO = tmp;

// And stop the loop
break;
}
}

// 0 = DST off (GMT)
// 1 = DST on (BST)
if(d < lSoM || d > lSoO) return 0;
else return 1;
}

alert(isBSTinEffect());
</script>
[/CODE]

This topic is now closed to further replies.
  • Posts

    • Media Player Classic - Home Cinema 2.5.0 by Razvan Serea Media Player Classic - Home Cinema (MPC-HC) is a free and open-source video and audio player for Windows. MPC-HC is based on the original Guliverkli project (which is no longer maintained) and contains many additional features and bug fixes. As the continuation of the original Media Player Classic, MPC-HC isn’t flashy but it works with nearly any media format. MPC-HC uses DXVA technology to pass decoding operations to your modern video card, enhancing your viewing experience. And MPC-HC supports both physical and software DVDs with menus, chapter navigation, and subtitles. Overview of features A lot of people seem to be unaware of some of the awesome features that have been added to MPC-HC in the past years. Here is a list of useful options and features that everyone should know about: Dark interface Menu > View > Dark Theme When using dark theme it is also possible to change the height of the seekbar and size of the toolbar buttons. Options > Advanced Video preview on the seekbar Options > Tweaks > Show preview on seek bar Adjust playback speed Menu > Play > Playback rate The buttons in the player that control playback rate take a 2x step by default. This can be customized to smaller values (like 10%): Options > Playback > Speed step Adjusting playback speed works best with the internal audio renderer. This also has automatic pitch correction. Options > Playback > Output > Audio Renderer MPC-HC can remember playback position, so you can resume from that point later Options > Player > History You can quickly seek through a video with Ctrl + Mouse Scrollwheel. You can jump to next/previous file in a folder by pressing PageUp/PageDown. You can perform automatic actions at end of file. For example to go to next file or close player. Options > Playback > After Playback (permanent setting) Menu > Play > After Playback (for current file only) A-B repeat - You can loop a segment of a video. Press [ and ] to set start and stop markers. You can rotate/flip/mirror/stretch/zoom the video Menu > View > Pan&Scan This is also easily done with hotkeys (see below). There are lots of keyboard hotkeys and mouse actions to control the player. They can be customized as well. Options > Player > Keys Tip: there is a search box above the table. You can stream videos directly from Youtube and many other video websites You can stream videos directly from Youtube and many other video websites Put yt-dlp.exe or youtube-dl.exe in the MPC-HC installation folder. Then you can open website URLs in the player: Menu > File > Open File/URL You can even download those videos: Menu > File > Save a copy Tip: to be able to download in best quality with yt-dlp/youtube-dl, it is recommended to also put ffmpeg.exe in the MPC-HC folder. Several YDL configuration options are found here: Options > Advanced This includes an option to specify the location of the .exe in case you don't want to put it in MPC-HC folder. Play HDR video This requires using madVR or MPC Video Renderer. After installation these renderers can be selected here: Options > Playback > Output Ability to search for and download subtitles, either automatically or manually (press D): Options > Subtitles > Misc Besides all these (new) features, there have also been many bugfixes and internal improvements in the player in the past years that give better performance and stability. It also has updated internal codecs. Support was added for CUE sheets, WebVTT subtitles, etc. Media Player Classic - Home Cinema 2.5.0 changelog: Updated LAV Filters to version 0.80-1-gb9116 Updated MPC Video Renderer to version 0.9.9.2400 Several small fixes and improvements. Graphics Designers Wanted for New Toolbar Buttons A new toolbar is planned for implementation in the player, featuring optional extra buttons and fully customizable layouts. As a result, existing custom toolbar designs will no longer be supported in the future. New button designs are needed, and contributions from graphics designers are welcome. Those interested in helping create the new toolbar are encouraged to read the dedicated information page. Download: MPC-HC 2.5.0 (x64) | Standalone | ~20.0 MB (Open Source) Download: MPC-HC 2.5.0 (x86) | Standalone Links: MPC-HC Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Then don't put it on an IoT VLAN but put it on your main, trusted, VLAN. If you put it on a different VLAN you lose printer discovery.
    • For me it isn't usable because I'm a power user. I need Wayland but I also need remote desktop. VNC isn't a thing with Wayland and freeRDP isn't nearly ready enough yet either. If I was less demanding (didn't need remote desktop or ran Xorg) I would probably be fine.
    • From Microsoft to RedHat, escape an American company for an American company, that would be funny
    • Running Postgres on a server in a datacenter is a little bit different than a bug in a desktop application don't you think?
  • Recent Achievements

    • Week One Done
      emptyother earned a badge
      Week One Done
    • Week One Done
      DarkWun earned a badge
      Week One Done
    • Very Popular
      valkyr09 earned a badge
      Very Popular
    • Week One Done
      suprememobiles earned a badge
      Week One Done
    • Week One Done
      Marites earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      571
    2. 2
      ATLien_0
      182
    3. 3
      +FloatingFatMan
      171
    4. 4
      Xenon
      125
    5. 5
      Michael Scrip
      118
  • Tell a friend

    Love Neowin? Tell a friend!