Groovy Groundhogs

So the groundhog saw his shadow today, implying six more weeks of Winter.  Let’s settle this nonsense once and for all.

[sourcecode language=”java”]
def cal = Calendar.instance
def ghday = cal.time
def spring = cal.time
def days = (ghday..spring).size()
println “Between Feb 2 and Mar 21, there are $days days”
The output is
[sourcecode language=”java”]
Between Feb 2 and Mar 21, there are 48 days
In other words, there are six weeks and six days between Groundhog Day and the first day of Spring.  So we’re already going to have an early Spring. 🙂

5 responses to “Groovy Groundhogs”

  1. nice tips.

    btw, you should try joda-time. it is very nice to play with date.

  2. Yes, I’m familiar with joda time, but for something this simple it was easy enough to use the regular Calendar class.

  3. lol! And I learned something about date ranges, too. Thanks!

  4. i am interested with this date range
    [code] def days = (ghday..spring).size() [/code]

    can you tell me what kind of object that has “range” features .. I tought it was only applied to Integer but now you showed us that it can be applied to java.util.Date object. that’s amazing.

  5. I live in the southern hemisphere, so it’s summer here, but I liked how you played with calendars anyway…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.