GrailsInAction / graina2

Source code for the 2nd edition of Grails in Action
90 stars 92 forks source link

Issue #44 : Use Calendar constants and use `date` as key name for month #47

Closed marcpa00 closed 11 years ago

marcpa00 commented 11 years ago

dayOfMonth is not a valid key for the Map passed to Date.updated() : use date, could also use Calendar.DAY_OF_MONTH.

pledbrook commented 11 years ago

That's great, thanks! Particular thanks for updating the other chapters too. Shame that dayOfMonth isn't supported. date is horribly misnamed.

marcpa00 commented 11 years ago

Agreed. Worse, is the fact that :

import static java.util.Calendar.*
d = new Date()
assert d != d.updated(YEAR:2000)

fails!

YEAR have to be forced to its value:

import static java.util.Calendar.*
d = new Date()
assert d != d.updated( (YEAR) : 2000)

which is ugly and would probably raise more unnecessary questions in the context of your book.

As you said, the current mapping of String values to Calendar constants (cf. http://groovy.codehaus.org/groovy-jdk/java/util/Calendar.html#set(java.util.Map)) is ill-choosed : dayOfMonth should have been used instead of date. I guess the backward compatible way to fix this would be to map every static int of JDK's Calendar into a camel-case String key name in groovy-jdk ? Do you think this warrants a suggestion on groovy-user mailing list ?

pledbrook commented 10 years ago

It's probably better to post such a suggestion on groovy-dev