1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2010-01-15 23:38:12 +00:00
|
|
|
* Copyright (C) 1996-2010, International Business Machines
|
1999-11-23 01:30:04 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/ucal.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/calendar.h"
|
|
|
|
#include "unicode/timezone.h"
|
2006-06-27 23:06:25 +00:00
|
|
|
#include "unicode/gregocal.h"
|
2003-03-05 18:36:48 +00:00
|
|
|
#include "unicode/simpletz.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ustring.h"
|
2002-11-12 23:52:27 +00:00
|
|
|
#include "unicode/strenum.h"
|
2002-07-16 17:50:42 +00:00
|
|
|
#include "cmemory.h"
|
2008-11-07 04:50:24 +00:00
|
|
|
#include "cstring.h"
|
2002-11-12 23:52:27 +00:00
|
|
|
#include "ustrenum.h"
|
2009-03-09 20:39:13 +00:00
|
|
|
#include "uenumimp.h"
|
|
|
|
#include "ulist.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2003-03-05 18:36:48 +00:00
|
|
|
static TimeZone*
|
|
|
|
_createTimeZone(const UChar* zoneID, int32_t len, UErrorCode* ec) {
|
|
|
|
TimeZone* zone = NULL;
|
|
|
|
if (ec!=NULL && U_SUCCESS(*ec)) {
|
|
|
|
// Note that if zoneID is invalid, we get back GMT. This odd
|
|
|
|
// behavior is by design and goes back to the JDK. The only
|
|
|
|
// failure we will see is a memory allocation failure.
|
|
|
|
int32_t l = (len<0 ? u_strlen(zoneID) : len);
|
2004-08-31 20:31:12 +00:00
|
|
|
UnicodeString zoneStrID;
|
|
|
|
zoneStrID.setTo((UBool)(len < 0), zoneID, l); /* temporary read-only alias */
|
|
|
|
zone = TimeZone::createTimeZone(zoneStrID);
|
2003-03-05 18:36:48 +00:00
|
|
|
if (zone == NULL) {
|
|
|
|
*ec = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UEnumeration* U_EXPORT2
|
|
|
|
ucal_openTimeZones(UErrorCode* ec) {
|
2009-03-18 20:23:40 +00:00
|
|
|
return uenum_openFromStringEnumeration(TimeZone::createEnumeration(), ec);
|
2003-03-05 18:36:48 +00:00
|
|
|
}
|
|
|
|
|
2002-11-12 23:52:27 +00:00
|
|
|
U_CAPI UEnumeration* U_EXPORT2
|
2003-03-05 18:36:48 +00:00
|
|
|
ucal_openCountryTimeZones(const char* country, UErrorCode* ec) {
|
2009-03-18 20:23:40 +00:00
|
|
|
return uenum_openFromStringEnumeration(TimeZone::createEnumeration(country), ec);
|
2003-03-05 18:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucal_getDefaultTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec) {
|
|
|
|
int32_t len = 0;
|
|
|
|
if (ec!=NULL && U_SUCCESS(*ec)) {
|
|
|
|
TimeZone* zone = TimeZone::createDefault();
|
|
|
|
if (zone == NULL) {
|
|
|
|
*ec = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
} else {
|
|
|
|
UnicodeString id;
|
|
|
|
zone->getID(id);
|
|
|
|
delete zone;
|
|
|
|
len = id.extract(result, resultCapacity, *ec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucal_setDefaultTimeZone(const UChar* zoneID, UErrorCode* ec) {
|
|
|
|
TimeZone* zone = _createTimeZone(zoneID, -1, ec);
|
|
|
|
if (zone != NULL) {
|
|
|
|
TimeZone::adoptDefault(zone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec) {
|
|
|
|
int32_t result = 0;
|
|
|
|
TimeZone* zone = _createTimeZone(zoneID, -1, ec);
|
2003-08-15 21:05:51 +00:00
|
|
|
if (U_SUCCESS(*ec)) {
|
|
|
|
if (zone->getDynamicClassID() == SimpleTimeZone::getStaticClassID()) {
|
|
|
|
result = ((SimpleTimeZone*) zone)->getDSTSavings();
|
|
|
|
} else {
|
|
|
|
// Since there is no getDSTSavings on TimeZone, we use a
|
|
|
|
// heuristic: Starting with the current time, march
|
|
|
|
// forwards for one year, looking for DST savings.
|
|
|
|
// Stepping by weeks is sufficient.
|
|
|
|
UDate d = Calendar::getNow();
|
|
|
|
for (int32_t i=0; i<53; ++i, d+=U_MILLIS_PER_DAY*7.0) {
|
|
|
|
int32_t raw, dst;
|
|
|
|
zone->getOffset(d, FALSE, raw, dst, *ec);
|
|
|
|
if (U_FAILURE(*ec)) {
|
|
|
|
break;
|
|
|
|
} else if (dst != 0) {
|
|
|
|
result = dst;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-05 18:36:48 +00:00
|
|
|
}
|
|
|
|
delete zone;
|
|
|
|
return result;
|
2002-11-12 23:52:27 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDate U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getNow()
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return Calendar::getNow();
|
|
|
|
}
|
|
|
|
|
2008-11-07 04:50:24 +00:00
|
|
|
#define ULOC_LOCALE_IDENTIFIER_CAPACITY (ULOC_FULLNAME_CAPACITY + 1 + ULOC_KEYWORD_AND_VALUES_CAPACITY)
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UCalendar* U_EXPORT2
|
2008-11-07 04:50:24 +00:00
|
|
|
ucal_open( const UChar* zoneID,
|
|
|
|
int32_t len,
|
|
|
|
const char* locale,
|
|
|
|
UCalendarType caltype,
|
|
|
|
UErrorCode* status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-03-05 18:36:48 +00:00
|
|
|
TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault()
|
|
|
|
: _createTimeZone(zoneID, len, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-03-05 18:36:48 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2008-11-07 04:50:24 +00:00
|
|
|
|
|
|
|
if ( caltype == UCAL_GREGORIAN ) {
|
|
|
|
char localeBuf[ULOC_LOCALE_IDENTIFIER_CAPACITY];
|
2010-01-26 07:21:21 +00:00
|
|
|
if ( locale == NULL ) {
|
|
|
|
locale = uloc_getDefault();
|
|
|
|
}
|
2008-11-07 04:50:24 +00:00
|
|
|
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);
|
|
|
|
}
|
2000-04-15 21:23:28 +00:00
|
|
|
return (UCalendar*)Calendar::createInstance(zone, Locale(locale), *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_close(UCalendar *cal)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
delete (Calendar*) cal;
|
|
|
|
}
|
|
|
|
|
2008-05-28 04:53:32 +00:00
|
|
|
U_CAPI UCalendar* U_EXPORT2
|
|
|
|
ucal_clone(const UCalendar* cal,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status)) return 0;
|
|
|
|
|
|
|
|
Calendar* res = ((Calendar*)cal)->clone();
|
|
|
|
|
|
|
|
if(res == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UCalendar*) res;
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setTimeZone( UCalendar* cal,
|
|
|
|
const UChar* zoneID,
|
|
|
|
int32_t len,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2000-11-29 02:14:29 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-03-05 18:36:48 +00:00
|
|
|
TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault()
|
|
|
|
: _createTimeZone(zoneID, len, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-03-05 18:36:48 +00:00
|
|
|
if (zone != NULL) {
|
|
|
|
((Calendar*)cal)->adoptTimeZone(zone);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2000-11-29 02:14:29 +00:00
|
|
|
ucal_getTimeZoneDisplayName(const UCalendar* cal,
|
1999-08-16 21:50:52 +00:00
|
|
|
UCalendarDisplayNameType type,
|
2000-11-29 02:14:29 +00:00
|
|
|
const char *locale,
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
const TimeZone& tz = ((Calendar*)cal)->getTimeZone();
|
|
|
|
UnicodeString id;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
id.setTo(result, 0, resultLength);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
switch(type) {
|
1999-08-16 21:50:52 +00:00
|
|
|
case UCAL_STANDARD:
|
2007-08-19 08:59:28 +00:00
|
|
|
tz.getDisplayName(FALSE, TimeZone::LONG, Locale(locale), id);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case UCAL_SHORT_STANDARD:
|
2007-08-19 08:59:28 +00:00
|
|
|
tz.getDisplayName(FALSE, TimeZone::SHORT, Locale(locale), id);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case UCAL_DST:
|
2007-08-19 08:59:28 +00:00
|
|
|
tz.getDisplayName(TRUE, TimeZone::LONG, Locale(locale), id);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case UCAL_SHORT_DST:
|
2007-08-19 08:59:28 +00:00
|
|
|
tz.getDisplayName(TRUE, TimeZone::SHORT, Locale(locale), id);
|
|
|
|
break;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
return id.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_inDaylightTime( const UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UErrorCode* status )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*status)) return (UBool) -1;
|
|
|
|
return ((Calendar*)cal)->inDaylightTime(*status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2006-06-27 23:06:25 +00:00
|
|
|
ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode) {
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Calendar *cpp_cal = (Calendar *)cal;
|
|
|
|
if(cpp_cal->getDynamicClassID() != GregorianCalendar::getStaticClassID()) {
|
|
|
|
*pErrorCode = U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
((GregorianCalendar *)cpp_cal)->setGregorianChange(date, *pErrorCode);
|
2006-06-27 23:06:25 +00:00
|
|
|
}
|
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
U_CAPI UDate U_EXPORT2
|
2006-06-27 23:06:25 +00:00
|
|
|
ucal_getGregorianChange(const UCalendar *cal, UErrorCode *pErrorCode) {
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return (UDate)0;
|
|
|
|
}
|
|
|
|
Calendar *cpp_cal = (Calendar *)cal;
|
|
|
|
if(cpp_cal->getDynamicClassID() != GregorianCalendar::getStaticClassID()) {
|
|
|
|
*pErrorCode = U_UNSUPPORTED_ERROR;
|
|
|
|
return (UDate)0;
|
|
|
|
}
|
|
|
|
return ((GregorianCalendar *)cpp_cal)->getGregorianChange();
|
2006-06-27 23:06:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getAttribute( const UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UCalendarAttribute attr)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
switch(attr) {
|
1999-08-16 21:50:52 +00:00
|
|
|
case UCAL_LENIENT:
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->isLenient();
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UCAL_FIRST_DAY_OF_WEEK:
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->getFirstDayOfWeek();
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UCAL_MINIMAL_DAYS_IN_FIRST_WEEK:
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->getMinimalDaysInFirstWeek();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
default:
|
2007-08-19 08:59:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setAttribute( UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UCalendarAttribute attr,
|
|
|
|
int32_t newValue)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
switch(attr) {
|
1999-08-16 21:50:52 +00:00
|
|
|
case UCAL_LENIENT:
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->setLenient((UBool)newValue);
|
|
|
|
break;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UCAL_FIRST_DAY_OF_WEEK:
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->setFirstDayOfWeek((UCalendarDaysOfWeek)newValue);
|
|
|
|
break;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UCAL_MINIMAL_DAYS_IN_FIRST_WEEK:
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->setMinimalDaysInFirstWeek((uint8_t)newValue);
|
|
|
|
break;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getAvailable(int32_t index)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
return uloc_getAvailable(index);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_countAvailable()
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
return uloc_countAvailable();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDate U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getMillis( const UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UErrorCode* status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*status)) return (UDate) 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->getTime(*status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setMillis( UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UDate dateTime,
|
|
|
|
UErrorCode* status )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->setTime(dateTime, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TBD: why does this take an UErrorCode?
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setDate( UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
int32_t year,
|
|
|
|
int32_t month,
|
|
|
|
int32_t date,
|
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->set(year, month, date);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TBD: why does this take an UErrorCode?
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setDateTime( UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
int32_t year,
|
|
|
|
int32_t month,
|
|
|
|
int32_t date,
|
|
|
|
int32_t hour,
|
|
|
|
int32_t minute,
|
|
|
|
int32_t second,
|
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->set(year, month, date, hour, minute, second);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_equivalentTo( const UCalendar* cal1,
|
2007-08-19 08:59:28 +00:00
|
|
|
const UCalendar* cal2)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal1)->isEquivalentTo(*((Calendar*)cal2));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_add( UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UCalendarDateFields field,
|
|
|
|
int32_t amount,
|
|
|
|
UErrorCode* status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->add(field, amount, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_roll( UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UCalendarDateFields field,
|
|
|
|
int32_t amount,
|
|
|
|
UErrorCode* status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->roll(field, amount, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_get( const UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UCalendarDateFields field,
|
|
|
|
UErrorCode* status )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->get(field, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_set( UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UCalendarDateFields field,
|
|
|
|
int32_t value)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->set(field, value);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_isSet( const UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UCalendarDateFields field)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->isSet(field);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_clearField( UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UCalendarDateFields field)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)cal)->clear(field);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_clear(UCalendar* calendar)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
((Calendar*)calendar)->clear();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getLimit( const UCalendar* cal,
|
2007-08-19 08:59:28 +00:00
|
|
|
UCalendarDateFields field,
|
|
|
|
UCalendarLimitType type,
|
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
if(status==0 || U_FAILURE(*status)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(type) {
|
1999-08-16 21:50:52 +00:00
|
|
|
case UCAL_MINIMUM:
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->getMinimum(field);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case UCAL_MAXIMUM:
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->getMaximum(field);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case UCAL_GREATEST_MINIMUM:
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->getGreatestMinimum(field);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case UCAL_LEAST_MAXIMUM:
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->getLeastMaximum(field);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case UCAL_ACTUAL_MINIMUM:
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->getActualMinimum(field,
|
|
|
|
*status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case UCAL_ACTUAL_MAXIMUM:
|
2007-08-19 08:59:28 +00:00
|
|
|
return ((Calendar*)cal)->getActualMaximum(field,
|
|
|
|
*status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
default:
|
2007-08-19 08:59:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-09-20 01:54:48 +00:00
|
|
|
|
2003-11-14 21:08:16 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
|
|
|
ucal_getLocaleByType(const UCalendar *cal, ULocDataLocaleType type, UErrorCode* status)
|
|
|
|
{
|
2004-01-20 23:06:38 +00:00
|
|
|
if (cal == NULL) {
|
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ((Calendar*)cal)->getLocaleID(type, *status);
|
2003-11-14 21:08:16 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 22:29:51 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
|
|
|
ucal_getTZDataVersion(UErrorCode* status)
|
|
|
|
{
|
|
|
|
return TimeZone::getTZDataVersion(*status);
|
|
|
|
}
|
|
|
|
|
2008-01-23 23:47:13 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucal_getCanonicalTimeZoneID(const UChar* id, int32_t len,
|
2008-02-05 19:14:43 +00:00
|
|
|
UChar* result, int32_t resultCapacity, UBool *isSystemID, UErrorCode* status) {
|
2008-01-23 23:47:13 +00:00
|
|
|
if(status == 0 || U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-05 19:14:43 +00:00
|
|
|
if (isSystemID) {
|
|
|
|
*isSystemID = FALSE;
|
|
|
|
}
|
2008-01-23 23:47:13 +00:00
|
|
|
if (id == 0 || len == 0 || result == 0 || resultCapacity <= 0) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int32_t reslen = 0;
|
|
|
|
UnicodeString canonical;
|
2008-02-05 19:14:43 +00:00
|
|
|
UBool systemID = FALSE;
|
|
|
|
TimeZone::getCanonicalID(UnicodeString(id, len), canonical, systemID, *status);
|
2008-01-23 23:47:13 +00:00
|
|
|
if (U_SUCCESS(*status)) {
|
2008-02-05 19:14:43 +00:00
|
|
|
if (isSystemID) {
|
|
|
|
*isSystemID = systemID;
|
|
|
|
}
|
2008-01-23 23:47:13 +00:00
|
|
|
reslen = canonical.extract(result, resultCapacity, *status);
|
|
|
|
}
|
|
|
|
return reslen;
|
|
|
|
}
|
|
|
|
|
2008-11-06 06:49:30 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
2008-12-02 22:56:31 +00:00
|
|
|
ucal_getType(const UCalendar *cal, UErrorCode* status)
|
2008-11-06 06:49:30 +00:00
|
|
|
{
|
2008-12-02 22:56:31 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-07 04:50:24 +00:00
|
|
|
return ((Calendar*)cal)->getType();
|
2008-11-06 06:49:30 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 23:38:12 +00:00
|
|
|
U_CAPI UCalendarWeekdayType U_EXPORT2
|
|
|
|
ucal_getDayOfWeekType(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode* status)
|
|
|
|
{
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return UCAL_WEEKDAY;
|
|
|
|
}
|
|
|
|
return ((Calendar*)cal)->getDayOfWeekType(dayOfWeek, *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucal_getWeekendTransition(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode *status)
|
|
|
|
{
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ((Calendar*)cal)->getWeekendTransition(dayOfWeek, *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
ucal_isWeekend(const UCalendar *cal, UDate date, UErrorCode *status)
|
|
|
|
{
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return ((Calendar*)cal)->isWeekend(date, *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-09 20:39:13 +00:00
|
|
|
static const UEnumeration defaultKeywordValues = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
ulist_close_keyword_values_iterator,
|
|
|
|
ulist_count_keyword_values,
|
|
|
|
uenum_unextDefault,
|
|
|
|
ulist_next_keyword_value,
|
|
|
|
ulist_reset_keyword_values_iterator
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const CAL_TYPES[] = {
|
|
|
|
"gregorian",
|
|
|
|
"japanese",
|
|
|
|
"buddhist",
|
|
|
|
"roc",
|
|
|
|
"persian",
|
|
|
|
"islamic-civil",
|
|
|
|
"islamic",
|
|
|
|
"hebrew",
|
|
|
|
"chinese",
|
|
|
|
"indian",
|
|
|
|
"coptic",
|
|
|
|
"ethiopic",
|
|
|
|
"ethiopic-amete-alem",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-02-14 02:32:41 +00:00
|
|
|
U_CAPI UEnumeration* U_EXPORT2
|
2009-04-15 01:57:02 +00:00
|
|
|
ucal_getKeywordValuesForLocale(const char * /* key */, const char* locale, UBool commonlyUsed, UErrorCode *status) {
|
2009-03-09 20:39:13 +00:00
|
|
|
// Resolve region
|
2009-03-30 18:51:03 +00:00
|
|
|
char prefRegion[ULOC_FULLNAME_CAPACITY] = "";
|
2009-03-09 20:39:13 +00:00
|
|
|
int32_t prefRegionLength = 0;
|
2009-03-30 18:51:03 +00:00
|
|
|
prefRegionLength = uloc_getCountry(locale, prefRegion, sizeof(prefRegion), status);
|
2009-03-09 20:39:13 +00:00
|
|
|
if (prefRegionLength == 0) {
|
2009-03-30 18:51:03 +00:00
|
|
|
char loc[ULOC_FULLNAME_CAPACITY] = "";
|
2009-03-09 20:39:13 +00:00
|
|
|
int32_t locLength = 0;
|
2009-03-30 18:51:03 +00:00
|
|
|
locLength = uloc_addLikelySubtags(locale, loc, sizeof(loc), status);
|
2009-03-09 20:39:13 +00:00
|
|
|
|
2009-03-30 18:51:03 +00:00
|
|
|
prefRegionLength = uloc_getCountry(loc, prefRegion, sizeof(prefRegion), status);
|
2009-03-09 20:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read preferred calendar values from supplementalData calendarPreference
|
2009-03-25 17:59:48 +00:00
|
|
|
UResourceBundle *rb = ures_openDirect(NULL, "supplementalData", status);
|
|
|
|
ures_getByKey(rb, "calendarPreferenceData", rb, status);
|
|
|
|
UResourceBundle *order = ures_getByKey(rb, prefRegion, NULL, status);
|
|
|
|
if (*status == U_MISSING_RESOURCE_ERROR && rb != NULL) {
|
|
|
|
*status = U_ZERO_ERROR;
|
|
|
|
order = ures_getByKey(rb, "001", NULL, status);
|
2009-03-09 20:39:13 +00:00
|
|
|
}
|
2009-03-25 17:59:48 +00:00
|
|
|
|
|
|
|
// Create a list of calendar type strings
|
|
|
|
UList *values = NULL;
|
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
values = ulist_createEmptyList(status);
|
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
for (int i = 0; i < ures_getSize(order); i++) {
|
|
|
|
int32_t len;
|
|
|
|
const UChar *type = ures_getStringByIndex(order, i, &len, status);
|
|
|
|
char *caltype = (char*)uprv_malloc(len + 1);
|
|
|
|
if (caltype == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
u_UCharsToChars(type, caltype, len);
|
|
|
|
*(caltype + len) = 0;
|
|
|
|
|
|
|
|
ulist_addItemEndList(values, caltype, TRUE, status);
|
2009-03-09 20:39:13 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-03-25 17:59:48 +00:00
|
|
|
|
|
|
|
if (U_SUCCESS(*status) && !commonlyUsed) {
|
|
|
|
// If not commonlyUsed, add other available values
|
|
|
|
for (int32_t i = 0; CAL_TYPES[i] != NULL; i++) {
|
2009-11-11 15:47:22 +00:00
|
|
|
if (!ulist_containsString(values, CAL_TYPES[i], (int32_t)uprv_strlen(CAL_TYPES[i]))) {
|
2009-03-25 17:59:48 +00:00
|
|
|
ulist_addItemEndList(values, CAL_TYPES[i], FALSE, status);
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
ulist_deleteList(values);
|
|
|
|
values = NULL;
|
|
|
|
}
|
2009-03-09 20:39:13 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-25 17:59:48 +00:00
|
|
|
|
|
|
|
ures_close(order);
|
|
|
|
ures_close(rb);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status) || values == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create string enumeration
|
|
|
|
UEnumeration *en = (UEnumeration*)uprv_malloc(sizeof(UEnumeration));
|
|
|
|
if (en == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
ulist_deleteList(values);
|
2009-03-09 20:39:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ulist_resetList(values);
|
2009-03-25 17:59:48 +00:00
|
|
|
memcpy(en, &defaultKeywordValues, sizeof(UEnumeration));
|
|
|
|
en->context = values;
|
2009-03-09 20:39:13 +00:00
|
|
|
return en;
|
2009-02-14 02:32:41 +00:00
|
|
|
}
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|