I guess the key thing to bear in mind is:

https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/Calendar.html
"""
The calendar field values can be set by calling the set methods. Any field 
values set in a Calendar will not be interpreted until it needs to calculate 
its time value (milliseconds from the Epoch) or values of the calendar fields. 
Calling the get, getTimeInMillis, getTime, add and roll involves such 
calculation.
"""

Calendar doesn't provide a way to differentiate, in other words.

See default values for fields at 
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/GregorianCalendar.html

Calendar is often used as a ' bucket' for timey-wimey things: you stuff things 
into fields that contextually make sense and ignore those that don't. Not very 
nice OO or helpful as an API.

It MAY be (speaking off the top of my head here) that you don't need/want 
Calendar...the newer java.time package has many "finer-grained" classes for 
things like Instance, Period, Duration, etc. that might be a better fit for a 
specific use-case: https://www.baeldung.com/java-8-date-time-intro

BOB
________________________________
From: James McMahon <jsmcmah...@gmail.com>
Sent: Tuesday, 20 June 2023 8:53 AM
To: users@groovy.apache.org <users@groovy.apache.org>
Subject: Working with Calendar object in Groovy

If I have a Calendar object created for 1999-01-01, a get() of calendar.MONTH 
will return 0. From references I’ve found through Google, we have to add 1 to 
MONTH to get the 1 for January. The calendar object has 0 for MONTH.

Now let’s take the case where we set our calendar object from “1999”,. When we 
get MONTH it is also 0 - but not because our month was January, but because it 
was not present.

How does the calendar instance differentiate between those two cases? Is there 
another calendar object element that tells me “hey, I could set no day or month 
from a date like 1999”?

Reply via email to