Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_STABLE UCalendar* U_EXPORT2 ucal_open ( const UChar zoneID,
int32_t  len,
const char *  locale,
UCalendarType  type,
UErrorCode status 

Open a UCalendar. A UCalendar may be used to convert a millisecond value to a year, month, and day.

Note: When unknown TimeZone ID is specified, the UCalendar returned by the function is initialized with GMT ("Etc/GMT") without any errors/warnings. If you want to check if a TimeZone ID is valid, use ucal_getCanonicalTimeZoneID prior to this function.

zoneIDThe desired TimeZone ID. If 0, use the default time zone.
lenThe length of zoneID, or -1 if null-terminated.
localeThe desired locale
typeThe type of UCalendar to open. This can be UCAL_GREGORIAN to open the Gregorian calendar for the locale, or UCAL_DEFAULT to open the default calendar for the locale (the default calendar may also be Gregorian). To open a specific non-Gregorian calendar for the locale, use uloc_setKeywordValue to set the value of the calendar keyword for the locale and then pass the locale to ucal_open with UCAL_DEFAULT as the type.
statusA pointer to an UErrorCode to receive any errors
A pointer to a UCalendar, or 0 if an error occurred. ICU 2.0

Definition at line 120 of file ucal.cpp.

References TimeZone::createDefault(), Calendar::createInstance(), NULL, U_FAILURE, and UCAL_GREGORIAN.


  if(U_FAILURE(*status)) return 0;
  TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault()
      : _createTimeZone(zoneID, len, status);

  if (U_FAILURE(*status)) {
      return NULL;

  if ( caltype == UCAL_GREGORIAN ) {
      uprv_strncpy(localeBuf, locale, ULOC_LOCALE_IDENTIFIER_CAPACITY);
      uloc_setKeywordValue("calendar", "gregorian", localeBuf, ULOC_LOCALE_IDENTIFIER_CAPACITY, status);
      if (U_FAILURE(*status)) {
          return NULL;
      return (UCalendar*)Calendar::createInstance(zone, Locale(localeBuf), *status);
  return (UCalendar*)Calendar::createInstance(zone, Locale(locale), *status);

Here is the call graph for this function:

Generated by  Doxygen 1.6.0   Back to index