1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-11-23 01:30:04 +00:00
|
|
|
* Copyright (C) 1996-1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ucal.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/calendar.h"
|
|
|
|
#include "unicode/timezone.h"
|
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cpputils.h"
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const UChar*
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getAvailableTZIDs( int32_t rawOffset,
|
|
|
|
int32_t index,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t count = 0;
|
|
|
|
const UChar *retVal = 0;
|
|
|
|
|
|
|
|
const UnicodeString** const tzs = TimeZone::createAvailableIDs(rawOffset,
|
|
|
|
count);
|
|
|
|
|
|
|
|
if(tzs == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(index < count)
|
|
|
|
retVal = tzs[index]->getUChars();
|
|
|
|
else
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_INDEX_OUTOFBOUNDS_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete [] tzs;
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_countAvailableTZIDs(int32_t rawOffset)
|
|
|
|
{
|
|
|
|
int32_t count = 0;
|
|
|
|
|
|
|
|
const UnicodeString** const tzs = TimeZone::createAvailableIDs(rawOffset,
|
|
|
|
count);
|
|
|
|
|
|
|
|
if(tzs == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
// TBD: U_MEMORY_ALLOCATION_ERROR
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] tzs;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UDate
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getNow()
|
|
|
|
{
|
|
|
|
return Calendar::getNow();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore type until we add more subclasses
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UCalendar*
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_open( const UChar* zoneID,
|
|
|
|
int32_t len,
|
|
|
|
const char* locale,
|
2000-08-15 18:25:20 +00:00
|
|
|
UCalendarType /*type*/,
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
TimeZone *zone = 0;
|
|
|
|
if(zoneID == 0) {
|
|
|
|
zone = TimeZone::createDefault();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int32_t length = (len == -1 ? u_strlen(zoneID) : len);
|
|
|
|
|
2000-08-15 19:29:56 +00:00
|
|
|
zone = TimeZone::createTimeZone(UnicodeString(zoneID, length));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
if(zone == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-15 21:23:28 +00:00
|
|
|
return (UCalendar*)Calendar::createInstance(zone, Locale(locale), *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_close(UCalendar *cal)
|
|
|
|
{
|
|
|
|
delete (Calendar*) cal;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setTimeZone( UCalendar* cal,
|
|
|
|
const UChar* zoneID,
|
|
|
|
int32_t len,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
TimeZone *zone = 0;
|
|
|
|
if(zone == 0) {
|
|
|
|
zone = TimeZone::createDefault();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int32_t length = (len == -1 ? u_strlen(zoneID) : len);
|
|
|
|
zone = TimeZone::createTimeZone(UnicodeString((UChar*)zoneID,
|
|
|
|
length, length));
|
|
|
|
}
|
|
|
|
if(zone == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
((Calendar*)cal)->adoptTimeZone(zone);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getTimeZoneDisplayName( const UCalendar* cal,
|
|
|
|
UCalendarDisplayNameType type,
|
|
|
|
const char *locale,
|
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t actLen;
|
|
|
|
|
|
|
|
const TimeZone& tz = ((Calendar*)cal)->getTimeZone();
|
|
|
|
UnicodeString id(result, 0, resultLength);
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case UCAL_STANDARD:
|
2000-04-15 21:23:28 +00:00
|
|
|
tz.getDisplayName(FALSE, TimeZone::LONG, Locale(locale), id);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UCAL_SHORT_STANDARD:
|
2000-04-15 21:23:28 +00:00
|
|
|
tz.getDisplayName(FALSE, TimeZone::SHORT, Locale(locale), id);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UCAL_DST:
|
2000-04-15 21:23:28 +00:00
|
|
|
tz.getDisplayName(TRUE, TimeZone::LONG, Locale(locale), id);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UCAL_SHORT_DST:
|
2000-04-15 21:23:28 +00:00
|
|
|
tz.getDisplayName(TRUE, TimeZone::SHORT, Locale(locale), id);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
T_fillOutputParams(&id, result, resultLength, &actLen, status);
|
|
|
|
return actLen;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_inDaylightTime( const UCalendar* cal,
|
|
|
|
UErrorCode* status )
|
|
|
|
{
|
2000-05-18 22:08:39 +00:00
|
|
|
if(U_FAILURE(*status)) return (UBool) -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((Calendar*)cal)->inDaylightTime(*status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getAttribute( const UCalendar* cal,
|
|
|
|
UCalendarAttribute attr)
|
|
|
|
{
|
|
|
|
switch(attr) {
|
|
|
|
case UCAL_LENIENT:
|
|
|
|
return ((Calendar*)cal)->isLenient();
|
|
|
|
|
|
|
|
case UCAL_FIRST_DAY_OF_WEEK:
|
|
|
|
return ((Calendar*)cal)->getFirstDayOfWeek();
|
|
|
|
|
|
|
|
case UCAL_MINIMAL_DAYS_IN_FIRST_WEEK:
|
|
|
|
return ((Calendar*)cal)->getMinimalDaysInFirstWeek();
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-10-22 00:43:39 +00:00
|
|
|
return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setAttribute( UCalendar* cal,
|
|
|
|
UCalendarAttribute attr,
|
|
|
|
int32_t newValue)
|
|
|
|
{
|
|
|
|
switch(attr) {
|
|
|
|
case UCAL_LENIENT:
|
2000-05-18 22:08:39 +00:00
|
|
|
((Calendar*)cal)->setLenient((UBool)newValue);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UCAL_FIRST_DAY_OF_WEEK:
|
|
|
|
((Calendar*)cal)->setFirstDayOfWeek((Calendar::EDaysOfWeek)newValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UCAL_MINIMAL_DAYS_IN_FIRST_WEEK:
|
|
|
|
((Calendar*)cal)->setMinimalDaysInFirstWeek((uint8_t)newValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const char*
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getAvailable(int32_t index)
|
|
|
|
{
|
|
|
|
return uloc_getAvailable(index);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_countAvailable()
|
|
|
|
{
|
|
|
|
return uloc_countAvailable();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UDate
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getMillis( const UCalendar* cal,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return (UDate) 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return ((Calendar*)cal)->getTime(*status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setMillis( UCalendar* cal,
|
|
|
|
UDate dateTime,
|
|
|
|
UErrorCode* status )
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
((Calendar*)cal)->setTime(dateTime, *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TBD: why does this take an UErrorCode?
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setDate( UCalendar* cal,
|
|
|
|
int32_t year,
|
|
|
|
int32_t month,
|
|
|
|
int32_t date,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
((Calendar*)cal)->set(year, month, date);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TBD: why does this take an UErrorCode?
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_setDateTime( UCalendar* cal,
|
|
|
|
int32_t year,
|
|
|
|
int32_t month,
|
|
|
|
int32_t date,
|
|
|
|
int32_t hour,
|
|
|
|
int32_t minute,
|
|
|
|
int32_t second,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
((Calendar*)cal)->set(year, month, date, hour, minute, second);
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_equivalentTo( const UCalendar* cal1,
|
|
|
|
const UCalendar* cal2)
|
|
|
|
{
|
|
|
|
return ((Calendar*)cal1)->equivalentTo(*((Calendar*)cal2));
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_add( UCalendar* cal,
|
|
|
|
UCalendarDateFields field,
|
|
|
|
int32_t amount,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
((Calendar*)cal)->add((Calendar::EDateFields)field, amount, *status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_roll( UCalendar* cal,
|
|
|
|
UCalendarDateFields field,
|
|
|
|
int32_t amount,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
((Calendar*)cal)->roll((Calendar::EDateFields)field, amount, *status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_get( const UCalendar* cal,
|
|
|
|
UCalendarDateFields field,
|
|
|
|
UErrorCode* status )
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return ((Calendar*)cal)->get((Calendar::EDateFields)field, *status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_set( UCalendar* cal,
|
|
|
|
UCalendarDateFields field,
|
|
|
|
int32_t value)
|
|
|
|
{
|
|
|
|
((Calendar*)cal)->set((Calendar::EDateFields)field, value);
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_isSet( const UCalendar* cal,
|
|
|
|
UCalendarDateFields field)
|
|
|
|
{
|
|
|
|
return ((Calendar*)cal)->isSet((Calendar::EDateFields)field);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_clearField( UCalendar* cal,
|
|
|
|
UCalendarDateFields field)
|
|
|
|
{
|
|
|
|
((Calendar*)cal)->clear((Calendar::EDateFields)field);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_clear(UCalendar* calendar)
|
|
|
|
{
|
|
|
|
((Calendar*)calendar)->clear();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucal_getLimit( const UCalendar* cal,
|
|
|
|
UCalendarDateFields field,
|
|
|
|
UCalendarLimitType type,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-22 00:43:39 +00:00
|
|
|
if(status==0 || U_FAILURE(*status)) {
|
|
|
|
return -1;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case UCAL_MINIMUM:
|
|
|
|
return ((Calendar*)cal)->getMinimum((Calendar::EDateFields)field);
|
|
|
|
|
|
|
|
case UCAL_MAXIMUM:
|
|
|
|
return ((Calendar*)cal)->getMaximum((Calendar::EDateFields)field);
|
|
|
|
|
|
|
|
case UCAL_GREATEST_MINIMUM:
|
|
|
|
return ((Calendar*)cal)->getGreatestMinimum((Calendar::EDateFields)field);
|
|
|
|
|
|
|
|
case UCAL_LEAST_MAXIMUM:
|
|
|
|
return ((Calendar*)cal)->getLeastMaximum((Calendar::EDateFields)field);
|
|
|
|
|
|
|
|
case UCAL_ACTUAL_MINIMUM:
|
|
|
|
return ((Calendar*)cal)->getActualMinimum((Calendar::EDateFields)field,
|
|
|
|
*status);
|
|
|
|
|
|
|
|
case UCAL_ACTUAL_MAXIMUM:
|
|
|
|
return ((Calendar*)cal)->getActualMaximum((Calendar::EDateFields)field,
|
|
|
|
*status);
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-10-22 00:43:39 +00:00
|
|
|
return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|