Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar's day of week gets inconsistent case!?

 
Maverick Lasa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,
I happen to encounter this when I was coding for date type conversions.
I really don't have the hint why the day of the week is different as
well as the long value. But the value will be the same when the MARKED
LINE is commented out or setting the DEFAULT_YEAR's value to a value that
is greater than 0. Someone has any idea?

Regards,
Mavedrive
[ October 18, 2003: Message edited by: Maverick Lasa ]
[ October 18, 2003: Message edited by: Maverick Lasa ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GregorianCalendar does not have a year 0, nor any negative year for that matter. The correct representation of years prior to 1 AD is to set the ERA to BC. "Year 0" is 1 BC, while "year -1" would be 2 BC. Yes, this is pretty silly, but it's how the standard Gregorian calendar in the outside world was designed; GregorianCalendar merely reflects this. The GregorianCalendar class works correctly as long as you use legal values for the YEAR field; if you use 0 or negative values, it gives inconsistent results, as you've observed. The documentation for GregorianCalendar and Calendar is rather poor in this regard; they really should point out what the allowed values for year consist of. Further they really should throw IllegalArgumentExcecption when illegal arguments are used, rather than return inconsistent results. Of course, htis is just part of a long list of objections to the way Calendar is set up in Java. Oh well...
[ October 18, 2003: Message edited by: Jim Yingst ]
 
Maverick Lasa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jim,
I do agree that the javadoc is quite poor; not describing the range of valid values for the fields. Anyway, let's just hope it will be fixed in
the incoming versions...
Mavedrive
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic