• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calendar's day of week gets inconsistent case!?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic