2

I would like to know if a particular date belongs to:

Spring
Summer
Fall
Winter

This is how I am initializing the DateTime

DateTimeZone timeZone = DateTimeZone.forID("America/Los_Angeles");
timestamp = new DateTime(unixtimestamp, timeZone);

Is it possible using JodaTime?

I found a similar post which is useful but it doesn't take the Hemisphere in to acccount:

Identifying the season from the Date using Java

Community
  • 1
  • 1
Kenci
  • 4,794
  • 15
  • 64
  • 108
  • 1
    How do you define a 'season' - specific date ranges? Do you expect them to change based on location, or just hemispehere? – Nick Dec 03 '14 at 22:01
  • Short: Impossible with Joda-Time, but I have now [posted another solution](https://stackoverflow.com/a/53662468/2491410) related to astronomical seasons and how to take into account the hemisphere aspect. – Meno Hochschild Dec 07 '18 at 03:24

1 Answers1

0

No, joda time does not provide this functionality. It provides you info about time which has to do with how much the earth is rotated on its axis. Seasons have to do with the earth's rotation relative to the sun. So even though "Los Angeles" is in the northern hemisphere, Joda time doesn't know that. It only knows that its time zone is UTC-08:00 which exists in both hemispheres.

Luckily the earth spins (reasonably) predictably and cyclically around the sun. So at any time you can determine the season for a given time and Hemisphere. In the referenced stack overflow they basically fixed the hemisphere so that the only two variables where time and season.

If you want to take into consideration the hemisphere you can use the existing solution and at the end write a function that will invert the season if your location is in the southern hemisphere instead of the northern hemisphere.

Solution left to the reader as an exercise

Carlos Bribiescas
  • 4,197
  • 9
  • 35
  • 66
  • 1
    the axial tilt is `predictable` only for short periods of time, it changes noticeably over thousands of years : http://en.wikipedia.org/wiki/Axial_tilt#mediaviewer/File:Obliquity_of_the_ecliptic_laskar.PNG, in fact exact predictions are impossible : http://en.wikipedia.org/wiki/Axial_tilt#mediaviewer/File:Obliquity_berger_-5000000_to_0.png – specializt Dec 03 '14 at 22:37
  • Technically you're correct. However all practical things considered, I wouldn't worry about the case where winter occurs in June. K.I.S.S. – Carlos Bribiescas Dec 03 '14 at 23:11
  • Hah, I mean in the Northern hemisphere*** – Carlos Bribiescas Dec 03 '14 at 23:33
  • What would your definition of seasons be for a country close to the equator? The standard seasons have little meaning, as such countries are closest to the sun twice a year - in spring and fall. Also Fall is called Autumn in our part of the planet. – kiwiron Dec 04 '14 at 00:34