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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:45:53+00:00 2026-05-11T08:45:53+00:00

I need to model some information about seasons, and need to track them based

  • 0

I need to model some information about seasons, and need to track them based on start / end date in a year-agnostic way. I.e. I need to allow users to define summer as being between, say, May 15th and September 10th, and do that for all years.

I’ll need to do a lot of checking of the type isThisDateInSeason). All the date manipulation functions (i.e. Date, Calendar) seem to only work with valid dates, i.e. including year information.

Are there any best practices around how to do this? I can think of a bunch of hacky ways of doing it (i.e. store month and day of the month or to store dates and just bring them to a baseline year so I can can compare), but it seems like there might be a better way.

I am writing this in Java or Groovy.

Would the Joda-Time library help here? I don’t have experience with it, but it looks to have much more flexibility.

I found this question about how to identify a season from date, but that focuses on months, and I need more flexibility to include dates.

  • 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. 2026-05-11T08:45:54+00:00Added an answer on May 11, 2026 at 8:45 am

    If each user owns their own data (i.e. they specify their seasons and then they enter their own information) then you could just store the data with the season as part of it, however I have a feeling the scenario you are after is for shared data across numerous users who define seasons differently.

    You would have to be very careful to ‘normalize’ dates as the leap year may cause unexpected problems, i.e. trying to set Feb 29 on a non leap year will cause problems / exceptions.

    I have put the below together, unforutnatly its c# but the concept will be the same. I havnt actually tested the code, but as a even as psudo code it may help.

    public class SeasonChecker {     public enum Season {Summer, Autumn, Winter, Spring};     private List<SeasonRange> _seasons = new List<SeasonRange>();      public void DefineSeason(Season season, DateTime starting, DateTime ending)     {         starting = starting.Date;         ending = ending.Date;          if(ending.Month < starting.Month)         {             // split into 2             DateTime tmp_ending = new DateTime(ending.Year, 12, 31);             DateTime tmp_starting = new DateTime(starting.Year, 1, 1);              SeasonRange r1 = new SeasonRange() { Season = season, Starting= tmp_starting, Ending = ending };             SeasonRange r2 = new SeasonRange() { Season = season, Starting= starting, Ending = tmp_ending };              this._seasons.Add(r1);             this._seasons.Add(r2);         }         else         {             SeasonRange r1 = new SeasonRange() { Season = season, Starting= starting, Ending = ending };             this._seasons.Add(r1);         }     }      public Season GetSeason(DateTime check)     {         foreach(SeasonRange range in _seasons)         {             if(range.InRange(check))                 return range.Season;         }          throw new ArgumentOutOfRangeException('Does not fall into any season');     }       private class SeasonRange     {         public DateTime Starting;         public DateTime Ending;         public Season Season;          public bool InRange(DateTime test)         {             if(test.Month == Starting.Month)             {                 if(test.Day >= Starting.Day)                 {                     return true;                 }             }             else if(test.Month == Ending.Month)             {                 if(test.Day <= Ending.Day)                 {                     return true;                 }             }             else if(test.Month > Starting.Month && test.Month < Ending.Month)             {                 return true;             }              return false;         }      } } 

    Note the above code makes the assumption that the season will not start and end on the same month – a fairly safe one I think!

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

Sidebar

Related Questions

I need to store some data in a Django model. These data are not
I need a modal dialog to gather some user input. I then need the
i have very simple problem. I need to create model, that represent element of
I need to create a 3D model of a cube with a circular hole
In my app i need to save changed values (old and new) when model
For example, if I have a user model and I need to validate login
I have a few models that need to have custom find conditions placed on
I need to replace our Ajax Modal Popup controls with a JavaScript equivalent. We
I need to set the fetch mode on my hibernate mappings to be eager
I need to keep a couple of Jena Models (OntModels, specifically) synchronized across 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.