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

  • Home
  • SEARCH
  • 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 7929227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:00:33+00:00 2026-06-03T20:00:33+00:00

Same arguments passed on the same method for the same object. It usually will

  • 0

Same arguments passed on the same method for the same object. It usually will display true, which is what I expect. But… sometimes it displays false. About 2-3 out of 100 times. What is wrong with this method that would be causing this behavior?

year, month, and day are instance variables containing “2012”, “4”, “1” respectively.

public boolean isInDateRange(String startDate, String endDate)
{
    if(startDate == null || endDate == null){
        return false;
    }
    Calendar today = Calendar.getInstance();
    today.set(Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day));

    Calendar start = Calendar.getInstance();
    //subtract 1 from the month parameter because java.util.Calendar's months
    //go from 0 to 11 instead of 1 to 12.
    start.set(Integer.valueOf(startDate.substring(0, 4)), Integer.valueOf(startDate.substring(5, 7)) - 1, Integer.valueOf(startDate.substring(8, 10)));

    Calendar end = Calendar.getInstance();
    end.set(Integer.valueOf(endDate.substring(0, 4)), (Integer.valueOf(endDate.substring(5, 7))) -1 , Integer.valueOf(endDate.substring(8, 10)));

    return today.compareTo(start) >= 0 && today.compareTo(end) <= 0;
}

And here is what I am passing to it

calendarDetails.getTuesday().isInDateRange("2012-05-01 00:00:00", "2012-05-01 00:00:00")
  • 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-06-03T20:00:35+00:00Added an answer on June 3, 2026 at 8:00 pm

    You’re ignoring the time in your calculations. On the few occasions that the millisecond ticks over between Calendar today = ... and Calendar start = ..., you end up with today, start, and end having the same value for the date, but the time of both start and end is ahead of today. Specifically, they’re 1 ms ahead since you’re using Calendar.getInstance(), which returns the current time, to build all three of them. So when that tick happens, today isn’t between start and end. You should zero out the time if you don’t care about it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is said that in Java method arguments are passed by value which is
When trying to compare two objects passed as arguments: first as object, second as
Is there anyway to create a dynamically retrievable method which somehow monitors an object's
Parameter arrays allow a variable number of arguments to be passed into a method:
I'm building a site which will provide product information in two languages: English and
My starting point is the following: - I have a method, transform, which I
I'm struggling with the code below. I have a method Find, which for me
I have this method, #upload, that basically takes in, amongst other arguments, a file
Here's a barebones Python app that simply prints the command-line arguments passed in: import
Possible Duplicate: Idiomatic object creation in ruby Sometimes it's useful to assign numerous of

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.