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 683083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:40:05+00:00 2026-05-14T01:40:05+00:00

FYI, There is some overlap in the initial description of this question with a

  • 0

FYI, There is some overlap in the initial description of this question with a question I asked yesterday, but the question is different.

My app has users who have seasonal products. When a user selects a product, we allow him to also select the product’s season. We accomplish this by letting him select a start date and an end date for each product.

We’re using date_select to generate two sets of drop-downs: one for the start date and one for the end date.

Including years doesn’t make sense for our model. So we’re using the option: discard_year => true

When you use discard_year => true, Rails sets a year in the database, it just doesn’t appear in the views. Rails sets all the years to either 0001 or 0002 in our app. Yes, we could make it 2009 and 2010 or any other pair. But the point is that we want the months and days to function independent of a particular year. If we used 2009 and 2010, then those dates would be wrong next year because we don’t expect these records to be updated every year.

My problem is that we need to dynamically evaluate the availability of products based on their relationship to the current month. For example, assume it’s March 15. Regardless of the year, I need a method that can tell me that a product available from October to January is not available right now.

If we were using actual years, this would be pretty easy.

For example, in the products model, I can do this:

def is_available?
  (season_start.past? && season_end.future?)
end

I can also evaluate a start_date and an end_date against current_date

However, in setup I’ve described above where we have arbitrary years that only make sense relative to each other, these methods don’t work. For example, is_available? would return false for all my products because their end date is in the year 0001 or 0002.

What I need is a method just like the ones I used as examples above, except that they evaluate against current_month instead of current_date, and past? and future months instead of years.

I have no idea how to do this or whether Rails has any built in functionality that could help. I’ve gone through all the date and time methods/helpers in the API docs, but I’m not seeing anything equivalent to what I’m describing.

Thanks.

  • 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-14T01:40:05+00:00Added an answer on May 14, 2026 at 1:40 am

    Set the year of the current date to 1000 and perform a range compare with the start and end dates.

    def is_available?
      t = Date.today
      d = Date.new(1000, t.month, t.day)
      (season_start..season_end).include?(d) or 
         (season_start..season_end).include?(d+1.year) 
    end
    

    Second comparison above is to address the following scenario:

    Lets say today Jan 15 and the season is from Oct – Feb. In our logic, we set the date to Jan 15 1000. This date will not be within Oct 1 1000 – Mar 1 1001. Hence we do the second comparison where we advance the date by a year to Jan 15 1001, which is within the range.

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

Sidebar

Related Questions

Requirement:- File1 has contents like - ABCD00000001,\some\some1\ABCD00000001,Y,,5 (this indicates there are 5 file in
FYI: This is a follow up to another question: Position element absolutely, but to
This is probably the MOST basic question and for some reason but I'm a
Someone else has already asked a somewhat similar question: Validate an Xml file against
Need some help from Oracle app developers out there: I have an C#.NET 4.0
All, I know that there is this question already out there: jquery file upload
FYI I'm programming in objective-C but anyone might be able to help. I've been
I have written a user control that captures some user input and has a
My layout file defines a WebView, underneath which there are some fixed height buttons.
I currently have some code that pulls down a list of users in a

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.