Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 411427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:59:09+00:00 2026-05-12T17:59:09+00:00

Here’s a timely question. The rules in North America* for time change are: the

  • 0

Here’s a timely question. The rules in North America* for time change are:

  • the first Sunday in November, offset changes to Standard (-1 hour)
  • the second Sunday in March, offset changes to Daylight (your normal offset from GMT)

Consider a function in JavaScript that takes in a Date parameter, and should determine whether the argument is Standard or Daylight Saving.

The root of the question is:

  • how would you construct the date of the next time change?

The algorithm/pseudocode currently looks like this:

if argDate == "March" 
{

    var firstOfMonth = new Date();
    firstOfMonth.setFullYear(year,3,1);

    //the day of week (0=Sunday, 6 = Saturday)
    var firstOfMonthDayOfWeek = firstOfMonth.getDay();

    var firstSunday;

    if (firstOfMonthDayOfWeek != 0) //Sunday!
    {
        //need to find a way to determine which date is the second Sunday
    }

}

The constraint here is to use the standard JavaScript function, and not scrape any JavaScript engine’s parsing of the Date object. This code won’t be running in a browser, so those nice solutions wouldn’t apply.

**not all places/regions in North America change times.*

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:59:09+00:00Added an answer on May 12, 2026 at 5:59 pm
    if argDate == "March" 
    {
    
        var firstOfMonth = new Date();
        firstOfMonth.setFullYear(year,3,1);
    
        //the day of week (0=Sunday, 6 = Saturday)
        var firstOfMonthDayOfWeek = firstOfMonth.getDay();
    
        var daysUntilFirstSunday =  (7-firstOfMonthDayOfWeek) % 7;
    
        var firstSunday = firstOfMonth.getDate() + daysUntilFirstSunday;
    
        // first Sunday now holds the desired day of the month
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a quick question. When you use format specifiers in the string you want
Here's the SQL query Select sum(f.Acres*m.credit1), sum(f.Acres*m.credit2), sum(f.Acres*m.credit3) from first f join model m
Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
Here I am trying to change the value of the following check box while
Here are some facts about my app followed by a question My app has
Here's the code I have. It works. The only problem is that the first
Here is the scenario: I'm writing an app that will watch for any changes
Here a simple question : What do you think of code which use try
Here is a jsFiddle of my question: http://jsfiddle.net/4wyvv/1/ Basically: //constructor function function Maker(){ var
Here is the site in question http://kryptodesigns.com/dev/forum.php?styleid=3 In FF, Chrome everything looks fine, pay

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.