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

    • Free Download Manager 6.28.1.6321 by Razvan Serea Free Download Manager is a powerful, easy-to-use and absolutely free download accelerator and manager. FDM accelerates downloads by splitting files into sections and then downloading them simultaneously. As a result download speed increases up to 600%, or even more! FDM can also resume broken downloads so you needn`t start downloading from the beginning after casual interruption. FDM lets you download files and whole web sites from any remote server via HTTP, HTTPS and FTP. You can also download files using BitTorrent protocol. In addition, Free Download Manager allows you to: adjust traffic usage; to organize and schedule downloads; download video from video sites; download whole web sites with HTML Spider; operate the program remotely, via the internet, and more! Free Download Manager is compatible with the most popular browsers Google Chrome, Firefox, Microsoft Edge, Internet Explorer and Safari. Free Download Manager 6.28.1.6321 changelog: Improved add-ons support. Improved M3U support. Fixed: crash bug in BitTorrent module. Fixed: minor bugs. Windows: a bit improved installer. Windows: Firefox bug workaround. Android: Qt updated to 6.9.1. Download: Free Download Manager (64-bit) | 45.8 MB (Freeware) Links: Home Page | Linux, Mac, Android | MS Store | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Tariffs have nothing to do with this pricing. It was always intended to be slightly more expensive then the S25+
    • Hello, The static link still downloads 10.3.2040.0 from May 22, 2025. The 10.3.2412.0 version can be downloaded directly from emclient.com/dist/v10.3.2412/setup.msi. Regards, Aryeh Goretsky
    • Hello, Yes, and yes. More specifically, there are lots of features in Windows that I do not use--I cannot recall the last time I needed to run EUDCEDIT.EXE or ODBCAD32.EXE on a computer I own, but I'm sure that for some people they are useful, and for a smaller set of people they might even be indispensable. I don't begrudge Microsoft for including them as part of the standard Windows installation nor the people who need such tools; sometimes it is convenient to have some little utility or feature readily available. One thing I do begrudge is Microsoft's over-reliance on its own telemetry, and perhaps surpisingly on the flip side, customers who disable it. Collecting telemetry is generally a good thing, if it is done for good reasons and does not include any customer PII. However, how you interpret that telemetry is even more important, as that can lead to all sorts of disastrous decisions. On the customer side of things, telemetry is your "vote:" it's how you tell companies what features you use in the program, and lets them prioritize things appropriately. One glaring example is Windows 8, which shipped with the full-screen Start Screen because Microsoft's telemetry told them the average Windows user pressed the Windows key to bring up the Start Menu less than once a day. I have often wondered how many "power users" of previous versions of Windows (XP, Vista, and 7) that relied on the Start Menu disabled the telemetry that would have told Microsoft a difference story about its usage. More recently, I came across a young lady who had a problem with a third-party sync program on her computer running Windows 7. An update for the utility removed Windows 7 compatibility, and broke her backup process. Now, support for Windows 7 ended over 5 years ago in 2020, but there are ISVs who still support their software on it, but decisions about stuff like that are made, in part, by knowing what percentage of your customer base is on what operating system version. When I asked about that, she mentioned she had specifically disabled the telemetry from the sync program to its developers, which was optional to begin with. What made things even worse was that this was an open source utility, and its authors had a very clear, well-designed and scoped policy on the telemetry they collected, the pains they went through to avoid collecting any PII, and even other ancillary risks involving information disclosure (like just using of the software) because of the network connection made for the checks. Yet, she took herself out of telling the project maintainers "Hey, I use your software and I'm running Windows 7" by disabling the telemetry checks, which could have let them know they needed to continue supporting it. In a sense, sending telemetry is just like voting: Individually, you may not think it matters much, but it is often the basis for very important decisions. Regards, Aryeh Goretsky
    • Hello, My thoughts on this are mixed. Microsoft has hosted malicious code in the Microsoft Update Catalog where third party device drivers are stored; I wrote about one such incident about fifteen years ago, so if there are any other old malicious drivers floating around in the catalog, this will be a good step towards preventing any infestations from reoccurring. Another thing, which surprisingly is not mentioned in Microsoft's announcement, is that this helps protect against BYOVD (Bring Your Own Vulnerable Driver) attacks, where malware either comes with or downloads an older device drivers with vulnerabilities in it that can be exploited to gain access to kernel memory. Removing all those old device drivers from the Windows Update Catalog, potentially with all sorts of undisclosed vulnerabilities in them, means an attacker can no longer leisurely count on being able to download them from Microsoft's servers--something that may go unnoticed or ignored by security analysts. This makes the adversary attack a little more noisy, since they have to either include the device driver with the rest of their initial payload or download it from a third-party site at some point prior to beginning their BYOVD attack. On the other hand, it means that people who are looking for a specific version of an older device driver for whatever legitimate reasons, like compatibility, performance or stability, may end up going to dodgy third-party sites in search of older drivers, which increases the risk of exposure to everything from nuisance advertisements and unwanted software to actual malicious code. As for me, I have keeping copies of all the device drivers, firmware updates, etc. I have downloaded over the years, some dating back to DOS and Windows 3.x era, not just for hardware I won, but popular things like unified chipset and video card drivers, just in case I ever needed it. It might seem silly to collect such a thing, but the hardware drivers, firmware updates, and documentation are just about 2 TB in size. From my perspective, it is an inexpensive form of insurance, especially given that disk space is always getting cheaper over time. Regards, Aryeh Goretsky
  • Recent Achievements

    • Contributor
      GravityDead went up a rank
      Contributor
    • Week One Done
      BlakeBringer earned a badge
      Week One Done
    • Week One Done
      Helen Shafer earned a badge
      Week One Done
    • First Post
      emptyother earned a badge
      First Post
    • Week One Done
      Crunchy6 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      660
    2. 2
      ATLien_0
      266
    3. 3
      Michael Scrip
      235
    4. 4
      Steven P.
      164
    5. 5
      +FloatingFatMan
      149
  • Tell a friend

    Love Neowin? Tell a friend!