Internationalization and localization tools


Locale-Sensitive Java Method

java.util.GregorianCalendar

public GregorianCalendar()

public GregorianCalendar(TimeZone zone)

public GregorianCalendar(Locale aLocale)

public GregorianCalendar(TimeZone zone,
   Locale aLocale)

public GregorianCalendar(int year,
   int month,
   int dayOfMonth)

public GregorianCalendar(int year,
   int month,
   int dayOfMonth,
   int hourOfDay,
   int minute)

public GregorianCalendar(int year,
   int month,
   int dayOfMonth,
   int hourOfDay,
   int minute,
   int second)

Internationalization (I18n) Method Overview

GregorianCalendar is a concrete subclass of Calendar and provides the standard calendar system used by most of the world. GregorianCalendar is a hybrid calendar that supports both the Julian and Gregorian calendar systems with the support of a single discontinuity, which corresponds by default to the Gregorian date when the Gregorian calendar was instituted (October 15, 1582 in some countries, later in others). This information has been copied from Sun's online Javadocs. Visit the doc for more information.

Some of the various public constructors accept a TimeZone and/or Locale argument. Constructors that don't accept one or both of these rely on the default system TimeZone and/or Locale

I18n Issues

The default machine locale and time zone is not always the correct locale and/or time zone for every user. Hence, it is recommended I18n practice to use the constructor that accepts both a TimeZone and Locale argument, allowing the code to format the resulting date/time strings independently of the machine's default locale.

Globalyzer will detect these constructors and report them as I18n issues regardless of the signature used and regardless of whether it is being used correctly. If Locale and TimeZone are already being passed as arguments, Globalyzer will detect it to force developers to double check that the correct values are being passed. If you have determined that the call is being handled correctly, you can use Globalyzer's Ignore Comment functionality to ensure that it isn't picked up in a subsequent scan.

Suggested Replacement

public GregorianCalendar(TimeZone zone,
   Locale aLocale)

Instead of:

Calendar calendar = new GregorianCalendar();

Use:

//retrieve the run-time user's locale
Locale locale = getUserLocale();

//instantiate a TimeZone object by passing in the user's
//time zone identification string such as "PST"
TimeZone zone = TimeZone.getTimeZone(getUserZone());

//pass the user's locale and time zone as arguments
Calendar aCalendar =
   new GregorianCalendar(zone, locale);

Please see Times and Dates for more information.

Locale-Sensitive Java Methods

 

Lingoport internationalization and localization services and software