2004-11-01 18:56:24 +00:00
/************************************************************************
2000-01-15 02:00:06 +00:00
* COPYRIGHT :
2009-03-13 03:21:29 +00:00
* Copyright ( c ) 1997 - 2009 , International Business Machines Corporation
2004-11-01 18:56:24 +00:00
* and others . All Rights Reserved .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-08-16 21:50:52 +00:00
2002-09-21 00:43:14 +00:00
# include "unicode/utypes.h"
# if !UCONFIG_NO_FORMATTING
1999-08-16 21:50:52 +00:00
# include "caltest.h"
2007-02-23 04:35:31 +00:00
# include "unicode/dtfmtsym.h"
1999-12-28 23:57:50 +00:00
# include "unicode/gregocal.h"
# include "unicode/smpdtfmt.h"
# include "unicode/simpletz.h"
2007-07-12 21:53:20 +00:00
# include "unicode/dbgutil.h"
2009-03-24 04:43:23 +00:00
# include "unicode/udat.h"
# include "unicode/ustring.h"
# define mkcstr(U) u_austrcpy(calloc(8, u_strlen(U) + 1), U)
2003-05-16 21:58:37 +00:00
1999-08-16 21:50:52 +00:00
// *****************************************************************************
// class CalendarTest
// *****************************************************************************
2003-10-26 10:20:40 +00:00
UnicodeString CalendarTest : : calToStr ( const Calendar & cal )
2003-05-16 21:58:37 +00:00
{
UnicodeString out ;
2003-06-12 20:24:07 +00:00
UErrorCode status = U_ZERO_ERROR ;
2003-05-16 21:58:37 +00:00
int i ;
2003-10-26 10:20:40 +00:00
UDate d ;
2003-05-16 21:58:37 +00:00
for ( i = 0 ; i < UCAL_FIELD_COUNT ; i + + ) {
2003-10-26 10:20:40 +00:00
out + = ( UnicodeString ( " " ) + fieldName ( ( UCalendarDateFields ) i ) + " = " + cal . get ( ( UCalendarDateFields ) i , status ) + UnicodeString ( " " ) ) ;
2003-05-16 21:58:37 +00:00
}
2003-10-26 10:20:40 +00:00
out + = " [ " + UnicodeString ( cal . getType ( ) ) + " ] " ;
if ( cal . inDaylightTime ( status ) ) {
out + = UnicodeString ( " (in DST), zone= " ) ;
}
else {
out + = UnicodeString ( " , zone= " ) ;
}
UnicodeString str2 ;
out + = cal . getTimeZone ( ) . getDisplayName ( str2 ) ;
d = cal . getTime ( status ) ;
out + = UnicodeString ( " : " , " " ) + d ;
2003-05-16 21:58:37 +00:00
return out ;
}
2000-08-15 18:25:20 +00:00
void CalendarTest : : runIndexedTest ( int32_t index , UBool exec , const char * & name , char * /*par*/ )
1999-08-16 21:50:52 +00:00
{
if ( exec ) logln ( " TestSuite TestCalendar " ) ;
switch ( index ) {
case 0 :
name = " TestDOW943 " ;
if ( exec ) {
logln ( " TestDOW943--- " ) ; logln ( " " ) ;
TestDOW943 ( ) ;
}
break ;
case 1 :
name = " TestClonesUnique908 " ;
if ( exec ) {
logln ( " TestClonesUnique908--- " ) ; logln ( " " ) ;
TestClonesUnique908 ( ) ;
}
break ;
case 2 :
name = " TestGregorianChange768 " ;
if ( exec ) {
logln ( " TestGregorianChange768--- " ) ; logln ( " " ) ;
TestGregorianChange768 ( ) ;
}
break ;
case 3 :
name = " TestDisambiguation765 " ;
if ( exec ) {
logln ( " TestDisambiguation765--- " ) ; logln ( " " ) ;
TestDisambiguation765 ( ) ;
}
break ;
case 4 :
name = " TestGMTvsLocal4064654 " ;
if ( exec ) {
logln ( " TestGMTvsLocal4064654--- " ) ; logln ( " " ) ;
TestGMTvsLocal4064654 ( ) ;
}
break ;
case 5 :
name = " TestAddSetOrder621 " ;
if ( exec ) {
logln ( " TestAddSetOrder621--- " ) ; logln ( " " ) ;
TestAddSetOrder621 ( ) ;
}
break ;
case 6 :
name = " TestAdd520 " ;
if ( exec ) {
logln ( " TestAdd520--- " ) ; logln ( " " ) ;
TestAdd520 ( ) ;
}
break ;
case 7 :
name = " TestFieldSet4781 " ;
if ( exec ) {
logln ( " TestFieldSet4781--- " ) ; logln ( " " ) ;
TestFieldSet4781 ( ) ;
}
break ;
case 8 :
name = " TestSerialize337 " ;
if ( exec ) {
logln ( " TestSerialize337--- " ) ; logln ( " " ) ;
// TestSerialize337();
}
break ;
case 9 :
name = " TestSecondsZero121 " ;
if ( exec ) {
logln ( " TestSecondsZero121--- " ) ; logln ( " " ) ;
TestSecondsZero121 ( ) ;
}
break ;
case 10 :
name = " TestAddSetGet0610 " ;
if ( exec ) {
logln ( " TestAddSetGet0610--- " ) ; logln ( " " ) ;
TestAddSetGet0610 ( ) ;
}
break ;
case 11 :
name = " TestFields060 " ;
if ( exec ) {
logln ( " TestFields060--- " ) ; logln ( " " ) ;
TestFields060 ( ) ;
}
break ;
case 12 :
name = " TestEpochStartFields " ;
if ( exec ) {
logln ( " TestEpochStartFields--- " ) ; logln ( " " ) ;
TestEpochStartFields ( ) ;
}
break ;
case 13 :
name = " TestDOWProgression " ;
if ( exec ) {
logln ( " TestDOWProgression--- " ) ; logln ( " " ) ;
TestDOWProgression ( ) ;
}
break ;
case 14 :
name = " TestGenericAPI " ;
if ( exec ) {
logln ( " TestGenericAPI--- " ) ; logln ( " " ) ;
TestGenericAPI ( ) ;
}
break ;
case 15 :
name = " TestAddRollExtensive " ;
if ( exec ) {
logln ( " TestAddRollExtensive--- " ) ; logln ( " " ) ;
TestAddRollExtensive ( ) ;
}
break ;
2000-01-19 04:20:48 +00:00
case 16 :
name = " TestDOW_LOCALandYEAR_WOY " ;
if ( exec ) {
logln ( " TestDOW_LOCALandYEAR_WOY--- " ) ; logln ( " " ) ;
TestDOW_LOCALandYEAR_WOY ( ) ;
}
break ;
2000-01-25 02:29:22 +00:00
case 17 :
name = " TestWOY " ;
if ( exec ) {
logln ( " TestWOY--- " ) ; logln ( " " ) ;
TestWOY ( ) ;
}
break ;
2001-08-16 22:32:08 +00:00
case 18 :
name = " TestRog " ;
if ( exec ) {
logln ( " TestRog--- " ) ; logln ( " " ) ;
TestRog ( ) ;
}
break ;
2003-10-26 10:20:40 +00:00
case 19 :
name = " TestYWOY " ;
if ( exec ) {
logln ( " TestYWOY--- " ) ; logln ( " " ) ;
TestYWOY ( ) ;
}
break ;
2003-11-24 21:36:01 +00:00
case 20 :
name = " TestJD " ;
if ( exec ) {
logln ( " TestJD--- " ) ; logln ( " " ) ;
TestJD ( ) ;
}
break ;
2007-07-12 21:53:20 +00:00
case 21 :
name = " TestDebug " ;
if ( exec ) {
logln ( " TestDebug--- " ) ; logln ( " " ) ;
TestDebug ( ) ;
}
break ;
2009-03-20 19:06:29 +00:00
case 22 :
name = " Test6703 " ;
if ( exec ) {
logln ( " Test6703--- " ) ; logln ( " " ) ;
Test6703 ( ) ;
}
break ;
2009-03-24 04:43:23 +00:00
case 23 :
name = " Test3785 " ;
if ( exec ) {
logln ( " Test3785--- " ) ; logln ( " " ) ;
Test3785 ( ) ;
}
break ;
1999-08-16 21:50:52 +00:00
default : name = " " ; break ;
}
}
// ---------------------------------------------------------------------------------
2003-10-26 10:20:40 +00:00
UnicodeString CalendarTest : : fieldName ( UCalendarDateFields f ) {
2000-12-21 01:35:08 +00:00
switch ( f ) {
2003-10-26 10:20:40 +00:00
# define FIELD_NAME_STR(x) case x: return (#x+5)
FIELD_NAME_STR ( UCAL_ERA ) ;
FIELD_NAME_STR ( UCAL_YEAR ) ;
FIELD_NAME_STR ( UCAL_MONTH ) ;
FIELD_NAME_STR ( UCAL_WEEK_OF_YEAR ) ;
FIELD_NAME_STR ( UCAL_WEEK_OF_MONTH ) ;
FIELD_NAME_STR ( UCAL_DATE ) ;
FIELD_NAME_STR ( UCAL_DAY_OF_YEAR ) ;
FIELD_NAME_STR ( UCAL_DAY_OF_WEEK ) ;
FIELD_NAME_STR ( UCAL_DAY_OF_WEEK_IN_MONTH ) ;
FIELD_NAME_STR ( UCAL_AM_PM ) ;
FIELD_NAME_STR ( UCAL_HOUR ) ;
FIELD_NAME_STR ( UCAL_HOUR_OF_DAY ) ;
FIELD_NAME_STR ( UCAL_MINUTE ) ;
FIELD_NAME_STR ( UCAL_SECOND ) ;
FIELD_NAME_STR ( UCAL_MILLISECOND ) ;
FIELD_NAME_STR ( UCAL_ZONE_OFFSET ) ;
FIELD_NAME_STR ( UCAL_DST_OFFSET ) ;
FIELD_NAME_STR ( UCAL_YEAR_WOY ) ;
FIELD_NAME_STR ( UCAL_DOW_LOCAL ) ;
FIELD_NAME_STR ( UCAL_EXTENDED_YEAR ) ;
FIELD_NAME_STR ( UCAL_JULIAN_DAY ) ;
FIELD_NAME_STR ( UCAL_MILLISECONDS_IN_DAY ) ;
# undef FIELD_NAME_STR
2000-12-21 01:35:08 +00:00
default :
return UnicodeString ( " " ) + ( ( int32_t ) f ) ;
}
}
1999-08-16 21:50:52 +00:00
/**
* Test various API methods for API completeness .
*/
void
CalendarTest : : TestGenericAPI ( )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2003-05-16 21:58:37 +00:00
UDate d ;
1999-08-16 21:50:52 +00:00
UnicodeString str ;
2003-12-03 01:19:27 +00:00
UBool eq = FALSE , b4 = FALSE , af = FALSE ;
1999-08-16 21:50:52 +00:00
2003-02-21 08:32:22 +00:00
UDate when = date ( 90 , UCAL_APRIL , 15 ) ;
1999-08-16 21:50:52 +00:00
UnicodeString tzid ( " TestZone " ) ;
int32_t tzoffset = 123400 ;
SimpleTimeZone * zone = new SimpleTimeZone ( tzoffset , tzid ) ;
Calendar * cal = Calendar : : createInstance ( zone - > clone ( ) , status ) ;
if ( failure ( status , " Calendar::createInstance " ) ) return ;
if ( * zone ! = cal - > getTimeZone ( ) ) errln ( " FAIL: Calendar::getTimeZone failed " ) ;
Calendar * cal2 = Calendar : : createInstance ( cal - > getTimeZone ( ) , status ) ;
if ( failure ( status , " Calendar::createInstance " ) ) return ;
cal - > setTime ( when , status ) ;
cal2 - > setTime ( when , status ) ;
if ( failure ( status , " Calendar::setTime " ) ) return ;
if ( ! ( * cal = = * cal2 ) ) errln ( " FAIL: Calendar::operator== failed " ) ;
if ( ( * cal ! = * cal2 ) ) errln ( " FAIL: Calendar::operator!= failed " ) ;
if ( ! cal - > equals ( * cal2 , status ) | |
cal - > before ( * cal2 , status ) | |
cal - > after ( * cal2 , status ) | |
1999-10-18 22:48:32 +00:00
U_FAILURE ( status ) ) errln ( " FAIL: equals/before/after failed " ) ;
1999-08-16 21:50:52 +00:00
2003-10-26 10:20:40 +00:00
logln ( UnicodeString ( " cal= " ) + cal - > getTime ( status ) + UnicodeString ( calToStr ( * cal ) ) ) ;
logln ( UnicodeString ( " cal2= " ) + cal2 - > getTime ( status ) + UnicodeString ( calToStr ( * cal2 ) ) ) ;
logln ( " cal2->setTime(when+1000) " ) ;
1999-08-16 21:50:52 +00:00
cal2 - > setTime ( when + 1000 , status ) ;
2003-10-26 10:20:40 +00:00
logln ( UnicodeString ( " cal2= " ) + cal2 - > getTime ( status ) + UnicodeString ( calToStr ( * cal2 ) ) ) ;
1999-08-16 21:50:52 +00:00
if ( failure ( status , " Calendar::setTime " ) ) return ;
if ( cal - > equals ( * cal2 , status ) | |
cal2 - > before ( * cal , status ) | |
cal - > after ( * cal2 , status ) | |
2003-10-26 10:20:40 +00:00
U_FAILURE ( status ) ) errln ( " FAIL: equals/before/after failed after setTime(+1000) " ) ;
1999-08-16 21:50:52 +00:00
2009-09-04 17:15:03 +00:00
logln ( " cal->roll(UCAL_SECOND) " ) ;
2003-02-21 08:32:22 +00:00
cal - > roll ( UCAL_SECOND , ( UBool ) TRUE , status ) ;
2003-10-26 10:20:40 +00:00
logln ( UnicodeString ( " cal= " ) + cal - > getTime ( status ) + UnicodeString ( calToStr ( * cal ) ) ) ;
2009-09-04 17:15:03 +00:00
cal - > roll ( UCAL_SECOND , 0 , status ) ;
logln ( UnicodeString ( " cal= " ) + cal - > getTime ( status ) + UnicodeString ( calToStr ( * cal ) ) ) ;
1999-08-16 21:50:52 +00:00
if ( failure ( status , " Calendar::roll " ) ) return ;
2009-09-04 17:15:03 +00:00
2003-10-26 10:20:40 +00:00
if ( ! ( eq = cal - > equals ( * cal2 , status ) ) | |
( b4 = cal - > before ( * cal2 , status ) ) | |
( af = cal - > after ( * cal2 , status ) ) | |
U_FAILURE ( status ) ) {
errln ( " FAIL: equals[%c]/before[%c]/after[%c] failed after roll 1 second [should be T/F/F] " ,
eq ? ' T ' : ' F ' ,
b4 ? ' T ' : ' F ' ,
af ? ' T ' : ' F ' ) ;
logln ( UnicodeString ( " cal= " ) + cal - > getTime ( status ) + UnicodeString ( calToStr ( * cal ) ) ) ;
logln ( UnicodeString ( " cal2= " ) + cal2 - > getTime ( status ) + UnicodeString ( calToStr ( * cal2 ) ) ) ;
}
1999-08-16 21:50:52 +00:00
// Roll back to January
2003-02-21 08:32:22 +00:00
cal - > roll ( UCAL_MONTH , ( int32_t ) ( 1 + UCAL_DECEMBER - cal - > get ( UCAL_MONTH , status ) ) , status ) ;
1999-08-16 21:50:52 +00:00
if ( failure ( status , " Calendar::roll " ) ) return ;
if ( cal - > equals ( * cal2 , status ) | |
cal2 - > before ( * cal , status ) | |
cal - > after ( * cal2 , status ) | |
2003-10-26 10:20:40 +00:00
U_FAILURE ( status ) ) errln ( " FAIL: equals/before/after failed after rollback to January " ) ;
1999-08-16 21:50:52 +00:00
TimeZone * z = cal - > orphanTimeZone ( ) ;
if ( z - > getID ( str ) ! = tzid | |
z - > getRawOffset ( ) ! = tzoffset )
errln ( " FAIL: orphanTimeZone failed " ) ;
int32_t i ;
for ( i = 0 ; i < 2 ; + + i )
{
2000-05-18 22:08:39 +00:00
UBool lenient = ( i > 0 ) ;
1999-08-16 21:50:52 +00:00
cal - > setLenient ( lenient ) ;
if ( lenient ! = cal - > isLenient ( ) ) errln ( " FAIL: setLenient/isLenient failed " ) ;
// Later: Check for lenient behavior
}
2003-02-21 08:32:22 +00:00
for ( i = UCAL_SUNDAY ; i < = UCAL_SATURDAY ; + + i )
1999-08-16 21:50:52 +00:00
{
2003-02-21 08:32:22 +00:00
cal - > setFirstDayOfWeek ( ( UCalendarDaysOfWeek ) i ) ;
1999-08-16 21:50:52 +00:00
if ( cal - > getFirstDayOfWeek ( ) ! = i ) errln ( " FAIL: set/getFirstDayOfWeek failed " ) ;
2003-06-10 03:53:28 +00:00
UErrorCode aStatus = U_ZERO_ERROR ;
if ( cal - > getFirstDayOfWeek ( aStatus ) ! = i | | U_FAILURE ( aStatus ) ) errln ( " FAIL: getFirstDayOfWeek(status) failed " ) ;
1999-08-16 21:50:52 +00:00
}
2003-03-18 18:17:05 +00:00
for ( i = 1 ; i < = 7 ; + + i )
1999-08-16 21:50:52 +00:00
{
cal - > setMinimalDaysInFirstWeek ( ( uint8_t ) i ) ;
if ( cal - > getMinimalDaysInFirstWeek ( ) ! = i ) errln ( " FAIL: set/getFirstDayOfWeek failed " ) ;
}
2003-02-21 08:32:22 +00:00
for ( i = 0 ; i < UCAL_FIELD_COUNT ; + + i )
1999-08-16 21:50:52 +00:00
{
2008-04-09 18:26:42 +00:00
if ( cal - > getMinimum ( ( UCalendarDateFields ) i ) > cal - > getGreatestMinimum ( ( UCalendarDateFields ) i ) )
errln ( " FAIL: getMinimum larger than getGreatestMinimum for field " + i ) ;
2003-02-21 08:32:22 +00:00
if ( cal - > getLeastMaximum ( ( UCalendarDateFields ) i ) > cal - > getMaximum ( ( UCalendarDateFields ) i ) )
1999-08-16 21:50:52 +00:00
errln ( " FAIL: getLeastMaximum larger than getMaximum for field " + i ) ;
2003-02-21 08:32:22 +00:00
if ( cal - > getMinimum ( ( UCalendarDateFields ) i ) > = cal - > getMaximum ( ( UCalendarDateFields ) i ) )
1999-08-16 21:50:52 +00:00
errln ( " FAIL: getMinimum not less than getMaximum for field " + i ) ;
}
cal - > adoptTimeZone ( TimeZone : : createDefault ( ) ) ;
cal - > clear ( ) ;
cal - > set ( 1984 , 5 , 24 ) ;
1999-10-18 22:48:32 +00:00
if ( cal - > getTime ( status ) ! = date ( 84 , 5 , 24 ) | | U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
errln ( " FAIL: Calendar::set(3 args) failed " ) ;
cal - > clear ( ) ;
cal - > set ( 1985 , 3 , 2 , 11 , 49 ) ;
1999-10-18 22:48:32 +00:00
if ( cal - > getTime ( status ) ! = date ( 85 , 3 , 2 , 11 , 49 ) | | U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
errln ( " FAIL: Calendar::set(5 args) failed " ) ;
cal - > clear ( ) ;
cal - > set ( 1995 , 9 , 12 , 1 , 39 , 55 ) ;
1999-10-18 22:48:32 +00:00
if ( cal - > getTime ( status ) ! = date ( 95 , 9 , 12 , 1 , 39 , 55 ) | | U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
errln ( " FAIL: Calendar::set(6 args) failed " ) ;
cal - > getTime ( status ) ;
if ( failure ( status , " Calendar::getTime " ) ) return ;
2003-02-21 08:32:22 +00:00
for ( i = 0 ; i < UCAL_FIELD_COUNT ; + + i )
1999-08-16 21:50:52 +00:00
{
switch ( i ) {
2003-02-21 08:32:22 +00:00
case UCAL_YEAR : case UCAL_MONTH : case UCAL_DATE :
case UCAL_HOUR_OF_DAY : case UCAL_MINUTE : case UCAL_SECOND :
2003-10-26 10:20:40 +00:00
case UCAL_EXTENDED_YEAR :
if ( ! cal - > isSet ( ( UCalendarDateFields ) i ) ) errln ( " FAIL: Calendar::isSet F, should be T " + fieldName ( ( UCalendarDateFields ) i ) ) ;
1999-08-16 21:50:52 +00:00
break ;
default :
2003-10-26 10:20:40 +00:00
if ( cal - > isSet ( ( UCalendarDateFields ) i ) ) errln ( " FAIL: Calendar::isSet = T, should be F " + fieldName ( ( UCalendarDateFields ) i ) ) ;
1999-08-16 21:50:52 +00:00
}
2003-02-21 08:32:22 +00:00
cal - > clear ( ( UCalendarDateFields ) i ) ;
2003-10-26 10:20:40 +00:00
if ( cal - > isSet ( ( UCalendarDateFields ) i ) ) errln ( " FAIL: Calendar::clear/isSet failed " + fieldName ( ( UCalendarDateFields ) i ) ) ;
1999-08-16 21:50:52 +00:00
}
2009-09-04 17:15:03 +00:00
if ( cal - > getActualMinimum ( UCAL_SECOND , status ) ! = 0 ) {
errln ( " Calendar is suppose to return 0 for getActualMinimum " ) ;
}
1999-08-16 21:50:52 +00:00
delete cal ;
delete cal2 ;
int32_t count ;
const Locale * loc = Calendar : : getAvailableLocales ( count ) ;
if ( count < 1 | | loc = = 0 )
{
2009-06-12 19:34:21 +00:00
dataerrln ( " FAIL: getAvailableLocales failed " ) ;
1999-08-16 21:50:52 +00:00
}
else
{
for ( i = 0 ; i < count ; + + i )
{
cal = Calendar : : createInstance ( loc [ i ] , status ) ;
if ( failure ( status , " Calendar::createInstance " ) ) return ;
delete cal ;
}
}
2002-08-21 00:16:30 +00:00
cal = Calendar : : createInstance ( TimeZone : : createDefault ( ) , Locale : : getEnglish ( ) , status ) ;
1999-08-16 21:50:52 +00:00
if ( failure ( status , " Calendar::createInstance " ) ) return ;
delete cal ;
2002-08-21 00:16:30 +00:00
cal = Calendar : : createInstance ( * zone , Locale : : getEnglish ( ) , status ) ;
1999-08-16 21:50:52 +00:00
if ( failure ( status , " Calendar::createInstance " ) ) return ;
delete cal ;
GregorianCalendar * gc = new GregorianCalendar ( * zone , status ) ;
if ( failure ( status , " new GregorianCalendar " ) ) return ;
delete gc ;
2002-08-21 00:16:30 +00:00
gc = new GregorianCalendar ( Locale : : getEnglish ( ) , status ) ;
1999-08-16 21:50:52 +00:00
if ( failure ( status , " new GregorianCalendar " ) ) return ;
delete gc ;
2002-08-21 00:16:30 +00:00
gc = new GregorianCalendar ( Locale : : getEnglish ( ) , status ) ;
1999-08-16 21:50:52 +00:00
delete gc ;
2002-08-21 00:16:30 +00:00
gc = new GregorianCalendar ( * zone , Locale : : getEnglish ( ) , status ) ;
1999-08-16 21:50:52 +00:00
if ( failure ( status , " new GregorianCalendar " ) ) return ;
delete gc ;
gc = new GregorianCalendar ( zone , status ) ;
if ( failure ( status , " new GregorianCalendar " ) ) return ;
delete gc ;
gc = new GregorianCalendar ( 1998 , 10 , 14 , 21 , 43 , status ) ;
2003-05-16 21:58:37 +00:00
if ( gc - > getTime ( status ) ! = ( d = date ( 98 , 10 , 14 , 21 , 43 ) ) | | U_FAILURE ( status ) )
errln ( " FAIL: new GregorianCalendar(ymdhm) failed with " + UnicodeString ( u_errorName ( status ) ) + " , cal= " + gc - > getTime ( status ) + UnicodeString ( calToStr ( * gc ) ) + " , d= " + d ) ;
else
logln ( UnicodeString ( " GOOD: cal= " ) + gc - > getTime ( status ) + UnicodeString ( calToStr ( * gc ) ) + " , d= " + d ) ;
1999-08-16 21:50:52 +00:00
delete gc ;
gc = new GregorianCalendar ( 1998 , 10 , 14 , 21 , 43 , 55 , status ) ;
2003-05-16 21:58:37 +00:00
if ( gc - > getTime ( status ) ! = ( d = date ( 98 , 10 , 14 , 21 , 43 , 55 ) ) | | U_FAILURE ( status ) )
errln ( " FAIL: new GregorianCalendar(ymdhms) failed with " + UnicodeString ( u_errorName ( status ) ) ) ;
1999-08-16 21:50:52 +00:00
2002-08-21 00:16:30 +00:00
GregorianCalendar gc2 ( Locale : : getEnglish ( ) , status ) ;
1999-08-16 21:50:52 +00:00
if ( failure ( status , " new GregorianCalendar " ) ) return ;
gc2 = * gc ;
if ( gc2 ! = * gc | | ! ( gc2 = = * gc ) ) errln ( " FAIL: GregorianCalendar assignment/operator==/operator!= failed " ) ;
delete gc ;
delete z ;
}
// -------------------------------------
/**
* This test confirms the correct behavior of add when incrementing
* through subsequent days .
*/
void
CalendarTest : : TestRog ( )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
GregorianCalendar * gc = new GregorianCalendar ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
2003-02-21 08:32:22 +00:00
int32_t year = 1997 , month = UCAL_APRIL , date = 1 ;
1999-08-16 21:50:52 +00:00
gc - > set ( year , month , date ) ;
2003-02-21 08:32:22 +00:00
gc - > set ( UCAL_HOUR_OF_DAY , 23 ) ;
gc - > set ( UCAL_MINUTE , 0 ) ;
gc - > set ( UCAL_SECOND , 0 ) ;
gc - > set ( UCAL_MILLISECOND , 0 ) ;
for ( int32_t i = 0 ; i < 9 ; i + + , gc - > add ( UCAL_DATE , 1 , status ) ) {
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
2003-02-21 08:32:22 +00:00
if ( gc - > get ( UCAL_YEAR , status ) ! = year | |
gc - > get ( UCAL_MONTH , status ) ! = month | |
gc - > get ( UCAL_DATE , status ) ! = ( date + i ) ) errln ( " FAIL: Date wrong " ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
delete gc ;
}
// -------------------------------------
/**
* Test the handling of the day of the week , checking for correctness and
* for correct minimum and maximum values .
*/
void
CalendarTest : : TestDOW943 ( )
{
dowTest ( FALSE ) ;
dowTest ( TRUE ) ;
}
2000-05-18 22:08:39 +00:00
void CalendarTest : : dowTest ( UBool lenient )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
GregorianCalendar * cal = new GregorianCalendar ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
2003-10-26 10:20:40 +00:00
logln ( " cal - Aug 12, 1997 \n " ) ;
2003-02-21 08:32:22 +00:00
cal - > set ( 1997 , UCAL_AUGUST , 12 ) ;
1999-08-16 21:50:52 +00:00
cal - > getTime ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::getTime failed " ) ; return ; }
2003-10-26 10:20:40 +00:00
logln ( ( lenient ? UnicodeString ( " LENIENT0: " ) : UnicodeString ( " nonlenient0: " ) ) + UnicodeString ( calToStr ( * cal ) ) ) ;
1999-08-16 21:50:52 +00:00
cal - > setLenient ( lenient ) ;
2003-10-26 10:20:40 +00:00
logln ( " cal - Dec 1, 1996 \n " ) ;
2003-02-21 08:32:22 +00:00
cal - > set ( 1996 , UCAL_DECEMBER , 1 ) ;
2003-10-26 10:20:40 +00:00
logln ( ( lenient ? UnicodeString ( " LENIENT: " ) : UnicodeString ( " nonlenient: " ) ) + UnicodeString ( calToStr ( * cal ) ) ) ;
2003-02-21 08:32:22 +00:00
int32_t dow = cal - > get ( UCAL_DAY_OF_WEEK , status ) ;
2003-10-26 10:20:40 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed [%s] " , u_errorName ( status ) ) ; return ; }
2003-02-21 08:32:22 +00:00
int32_t min = cal - > getMinimum ( UCAL_DAY_OF_WEEK ) ;
int32_t max = cal - > getMaximum ( UCAL_DAY_OF_WEEK ) ;
1999-08-16 21:50:52 +00:00
if ( dow < min | |
dow > max ) errln ( UnicodeString ( " FAIL: Day of week " ) + ( int32_t ) dow + " out of range " ) ;
2003-10-26 10:20:40 +00:00
if ( dow ! = UCAL_SUNDAY ) errln ( " FAIL: Day of week should be SUNDAY[%d] not %d " , UCAL_SUNDAY , dow ) ;
2003-02-21 08:32:22 +00:00
if ( min ! = UCAL_SUNDAY | |
max ! = UCAL_SATURDAY ) errln ( " FAIL: Min/max bad " ) ;
1999-08-16 21:50:52 +00:00
delete cal ;
}
// -------------------------------------
/**
* Confirm that cloned Calendar objects do not inadvertently share substructures .
*/
void
CalendarTest : : TestClonesUnique908 ( )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
Calendar * c = Calendar : : createInstance ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::createInstance failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
Calendar * d = ( Calendar * ) c - > clone ( ) ;
2003-02-21 08:32:22 +00:00
c - > set ( UCAL_MILLISECOND , 123 ) ;
d - > set ( UCAL_MILLISECOND , 456 ) ;
if ( c - > get ( UCAL_MILLISECOND , status ) ! = 123 | |
d - > get ( UCAL_MILLISECOND , status ) ! = 456 ) {
1999-08-16 21:50:52 +00:00
errln ( " FAIL: Clones share fields " ) ;
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
delete c ;
delete d ;
}
// -------------------------------------
/**
* Confirm that the Gregorian cutoff value works as advertised .
*/
void
CalendarTest : : TestGregorianChange768 ( )
{
2000-05-18 22:08:39 +00:00
UBool b ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
UnicodeString str ;
GregorianCalendar * c = new GregorianCalendar ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
logln ( UnicodeString ( " With cutoff " ) + dateToString ( c - > getGregorianChange ( ) , str ) ) ;
2000-08-15 18:25:20 +00:00
b = c - > isLeapYear ( 1800 ) ;
logln ( UnicodeString ( " isLeapYear(1800) = " ) + ( b ? " true " : " false " ) ) ;
1999-08-16 21:50:52 +00:00
logln ( UnicodeString ( " (should be FALSE) " ) ) ;
if ( b ) errln ( " FAIL " ) ;
c - > setGregorianChange ( date ( 0 , 0 , 1 ) , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " GregorianCalendar::setGregorianChange failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
logln ( UnicodeString ( " With cutoff " ) + dateToString ( c - > getGregorianChange ( ) , str ) ) ;
2000-08-15 18:25:20 +00:00
b = c - > isLeapYear ( 1800 ) ;
logln ( UnicodeString ( " isLeapYear(1800) = " ) + ( b ? " true " : " false " ) ) ;
1999-08-16 21:50:52 +00:00
logln ( UnicodeString ( " (should be TRUE) " ) ) ;
if ( ! b ) errln ( " FAIL " ) ;
delete c ;
}
// -------------------------------------
/**
* Confirm the functioning of the field disambiguation algorithm .
*/
void
CalendarTest : : TestDisambiguation765 ( )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2006-04-21 01:18:35 +00:00
Calendar * c = Calendar : : createInstance ( " en_US " , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::createInstance failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
c - > setLenient ( FALSE ) ;
c - > clear ( ) ;
2003-02-21 08:32:22 +00:00
c - > set ( UCAL_YEAR , 1997 ) ;
c - > set ( UCAL_MONTH , UCAL_JUNE ) ;
c - > set ( UCAL_DATE , 3 ) ;
verify765 ( " 1997 third day of June = " , c , 1997 , UCAL_JUNE , 3 ) ;
1999-08-16 21:50:52 +00:00
c - > clear ( ) ;
2003-02-21 08:32:22 +00:00
c - > set ( UCAL_YEAR , 1997 ) ;
c - > set ( UCAL_DAY_OF_WEEK , UCAL_TUESDAY ) ;
c - > set ( UCAL_MONTH , UCAL_JUNE ) ;
c - > set ( UCAL_DAY_OF_WEEK_IN_MONTH , 1 ) ;
verify765 ( " 1997 first Tuesday in June = " , c , 1997 , UCAL_JUNE , 3 ) ;
1999-08-16 21:50:52 +00:00
c - > clear ( ) ;
2003-02-21 08:32:22 +00:00
c - > set ( UCAL_YEAR , 1997 ) ;
c - > set ( UCAL_DAY_OF_WEEK , UCAL_TUESDAY ) ;
c - > set ( UCAL_MONTH , UCAL_JUNE ) ;
c - > set ( UCAL_DAY_OF_WEEK_IN_MONTH , - 1 ) ;
verify765 ( " 1997 last Tuesday in June = " , c , 1997 , UCAL_JUNE , 24 ) ;
2008-04-09 18:26:42 +00:00
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
2008-04-09 18:26:42 +00:00
c - > clear ( ) ;
c - > set ( UCAL_YEAR , 1997 ) ;
c - > set ( UCAL_DAY_OF_WEEK , UCAL_TUESDAY ) ;
c - > set ( UCAL_MONTH , UCAL_JUNE ) ;
c - > set ( UCAL_DAY_OF_WEEK_IN_MONTH , 0 ) ;
c - > getTime ( status ) ;
1999-08-16 21:50:52 +00:00
verify765 ( " 1997 zero-th Tuesday in June = " , status ) ;
2008-04-09 18:26:42 +00:00
1999-08-16 21:50:52 +00:00
c - > clear ( ) ;
2003-02-21 08:32:22 +00:00
c - > set ( UCAL_YEAR , 1997 ) ;
c - > set ( UCAL_DAY_OF_WEEK , UCAL_TUESDAY ) ;
c - > set ( UCAL_MONTH , UCAL_JUNE ) ;
c - > set ( UCAL_WEEK_OF_MONTH , 1 ) ;
verify765 ( " 1997 Tuesday in week 1 of June = " , c , 1997 , UCAL_JUNE , 3 ) ;
1999-08-16 21:50:52 +00:00
c - > clear ( ) ;
2003-02-21 08:32:22 +00:00
c - > set ( UCAL_YEAR , 1997 ) ;
c - > set ( UCAL_DAY_OF_WEEK , UCAL_TUESDAY ) ;
c - > set ( UCAL_MONTH , UCAL_JUNE ) ;
c - > set ( UCAL_WEEK_OF_MONTH , 5 ) ;
verify765 ( " 1997 Tuesday in week 5 of June = " , c , 1997 , UCAL_JULY , 1 ) ;
2008-04-09 18:26:42 +00:00
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
2008-04-09 18:26:42 +00:00
c - > clear ( ) ;
c - > set ( UCAL_YEAR , 1997 ) ;
c - > set ( UCAL_DAY_OF_WEEK , UCAL_TUESDAY ) ;
c - > set ( UCAL_MONTH , UCAL_JUNE ) ;
c - > set ( UCAL_WEEK_OF_MONTH , 0 ) ;
2009-03-13 03:21:29 +00:00
c - > setMinimalDaysInFirstWeek ( 1 ) ;
2008-04-09 18:26:42 +00:00
c - > getTime ( status ) ;
verify765 ( " 1997 Tuesday in week 0 of June = " , status ) ;
2000-01-25 02:29:22 +00:00
/* Note: The following test used to expect YEAR 1997, WOY 1 to
* resolve to a date in Dec 1996 ; that is , to behave as if
* YEAR_WOY were 1997. With the addition of a new explicit
* YEAR_WOY field , YEAR_WOY must itself be set if that is what is
* desired . Using YEAR in combination with WOY is ambiguous , and
* results in the first WOY / DOW day of the year satisfying the
* given fields ( there may be up to two such days ) . In this case ,
* it propertly resolves to Tue Dec 30 1997 , which has a WOY value
* of 1 ( for YEAR_WOY 1998 ) and a DOW of Tuesday , and falls in the
* _calendar_ year 1997 , as specified . - aliu */
1999-08-16 21:50:52 +00:00
c - > clear ( ) ;
2003-02-21 08:32:22 +00:00
c - > set ( UCAL_YEAR_WOY , 1997 ) ; // aliu
c - > set ( UCAL_DAY_OF_WEEK , UCAL_TUESDAY ) ;
c - > set ( UCAL_WEEK_OF_YEAR , 1 ) ;
verify765 ( " 1997 Tuesday in week 1 of yearWOY = " , c , 1996 , UCAL_DECEMBER , 31 ) ;
2000-01-25 02:29:22 +00:00
c - > clear ( ) ; // - add test for YEAR
2009-03-13 03:21:29 +00:00
c - > setMinimalDaysInFirstWeek ( 1 ) ;
2003-02-21 08:32:22 +00:00
c - > set ( UCAL_YEAR , 1997 ) ;
c - > set ( UCAL_DAY_OF_WEEK , UCAL_TUESDAY ) ;
c - > set ( UCAL_WEEK_OF_YEAR , 1 ) ;
verify765 ( " 1997 Tuesday in week 1 of year = " , c , 1997 , UCAL_DECEMBER , 30 ) ;
1999-08-16 21:50:52 +00:00
c - > clear ( ) ;
2003-02-21 08:32:22 +00:00
c - > set ( UCAL_YEAR , 1997 ) ;
c - > set ( UCAL_DAY_OF_WEEK , UCAL_TUESDAY ) ;
c - > set ( UCAL_WEEK_OF_YEAR , 10 ) ;
verify765 ( " 1997 Tuesday in week 10 of year = " , c , 1997 , UCAL_MARCH , 4 ) ;
1999-08-16 21:50:52 +00:00
//try {
// {sfb} week 0 is no longer a valid week of year
/*c->clear();
c - > set ( Calendar : : YEAR , 1997 ) ;
c - > set ( Calendar : : DAY_OF_WEEK , Calendar : : TUESDAY ) ;
//c->set(Calendar::WEEK_OF_YEAR, 0);
c - > set ( Calendar : : WEEK_OF_YEAR , 1 ) ;
verify765 ( " 1997 Tuesday in week 0 of year = " , c , 1996 , Calendar : : DECEMBER , 24 ) ; */
//}
//catch(IllegalArgumentException ex) {
// errln("FAIL: Exception seen:");
// ex.printStackTrace(log);
//}
delete c ;
}
// -------------------------------------
void
CalendarTest : : verify765 ( const UnicodeString & msg , Calendar * c , int32_t year , int32_t month , int32_t day )
{
UnicodeString str ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2006-04-21 01:18:35 +00:00
int32_t y = c - > get ( UCAL_YEAR , status ) ;
int32_t m = c - > get ( UCAL_MONTH , status ) ;
int32_t d = c - > get ( UCAL_DATE , status ) ;
if ( y = = year & &
m = = month & &
d = = day ) {
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " FAIL: Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
logln ( " PASS: " + msg + dateToString ( c - > getTime ( status ) , str ) ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::getTime failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
else {
2006-04-21 01:18:35 +00:00
errln ( " FAIL: " + msg + dateToString ( c - > getTime ( status ) , str ) + " ; expected " + ( int32_t ) year + " / " + ( int32_t ) ( month + 1 ) + " / " + ( int32_t ) day +
" ; got " + ( int32_t ) y + " / " + ( int32_t ) ( m + 1 ) + " / " + ( int32_t ) d + " for Locale: " + c - > getLocaleID ( ULOC_ACTUAL_LOCALE , status ) ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::getTime failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
}
// -------------------------------------
void
CalendarTest : : verify765 ( const UnicodeString & msg /*, IllegalArgumentException e*/ , UErrorCode status )
{
1999-10-07 00:07:53 +00:00
if ( status ! = U_ILLEGAL_ARGUMENT_ERROR ) errln ( " FAIL: No IllegalArgumentException for " + msg ) ;
1999-08-16 21:50:52 +00:00
else logln ( " PASS: " + msg + " IllegalArgument as expected " ) ;
}
// -------------------------------------
/**
* Confirm that the offset between local time and GMT behaves as expected .
*/
void
CalendarTest : : TestGMTvsLocal4064654 ( )
{
test4064654 ( 1997 , 1 , 1 , 12 , 0 , 0 ) ;
test4064654 ( 1997 , 4 , 16 , 18 , 30 , 0 ) ;
}
// -------------------------------------
void
CalendarTest : : test4064654 ( int32_t yr , int32_t mo , int32_t dt , int32_t hr , int32_t mn , int32_t sc )
{
UDate date ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
UnicodeString str ;
Calendar * gmtcal = Calendar : : createInstance ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::createInstance failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
gmtcal - > adoptTimeZone ( TimeZone : : createTimeZone ( " Africa/Casablanca " ) ) ;
gmtcal - > set ( yr , mo - 1 , dt , hr , mn , sc ) ;
2003-02-21 08:32:22 +00:00
gmtcal - > set ( UCAL_MILLISECOND , 0 ) ;
1999-08-16 21:50:52 +00:00
date = gmtcal - > getTime ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::getTime failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
logln ( " date = " + dateToString ( date , str ) ) ;
Calendar * cal = Calendar : : createInstance ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::createInstance failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
cal - > setTime ( date , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::setTime failed " ) ; return ; }
2003-02-21 08:32:22 +00:00
int32_t offset = cal - > getTimeZone ( ) . getOffset ( ( uint8_t ) cal - > get ( UCAL_ERA , status ) ,
cal - > get ( UCAL_YEAR , status ) ,
cal - > get ( UCAL_MONTH , status ) ,
cal - > get ( UCAL_DATE , status ) ,
( uint8_t ) cal - > get ( UCAL_DAY_OF_WEEK , status ) ,
cal - > get ( UCAL_MILLISECOND , status ) , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
logln ( " offset for " + dateToString ( date , str ) + " = " + ( offset / 1000 / 60 / 60.0 ) + " hr " ) ;
2003-02-21 08:32:22 +00:00
int32_t utc = ( ( cal - > get ( UCAL_HOUR_OF_DAY , status ) * 60 +
cal - > get ( UCAL_MINUTE , status ) ) * 60 +
cal - > get ( UCAL_SECOND , status ) ) * 1000 +
cal - > get ( UCAL_MILLISECOND , status ) - offset ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
int32_t expected = ( ( hr * 60 + mn ) * 60 + sc ) * 1000 ;
if ( utc ! = expected ) errln ( UnicodeString ( " FAIL: Discrepancy of " ) + ( utc - expected ) +
" millis = " + ( ( utc - expected ) / 1000 / 60 / 60.0 ) + " hr " ) ;
delete gmtcal ;
delete cal ;
}
// -------------------------------------
/**
* The operations of adding and setting should not exhibit pathological
* dependence on the order of operations . This test checks for this .
*/
void
CalendarTest : : TestAddSetOrder621 ( )
{
UDate d = date ( 97 , 4 , 14 , 13 , 23 , 45 ) ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
Calendar * cal = Calendar : : createInstance ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Calendar::createInstance failed " ) ;
delete cal ;
return ;
}
cal - > setTime ( d , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Calendar::setTime failed " ) ;
delete cal ;
return ;
}
2003-02-21 08:32:22 +00:00
cal - > add ( UCAL_DATE , - 5 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Calendar::add failed " ) ;
delete cal ;
return ;
}
2003-02-21 08:32:22 +00:00
cal - > set ( UCAL_HOUR_OF_DAY , 0 ) ;
cal - > set ( UCAL_MINUTE , 0 ) ;
cal - > set ( UCAL_SECOND , 0 ) ;
1999-08-16 21:50:52 +00:00
UnicodeString s ;
dateToString ( cal - > getTime ( status ) , s ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Calendar::getTime failed " ) ;
delete cal ;
return ;
}
delete cal ;
cal = Calendar : : createInstance ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Calendar::createInstance failed " ) ;
delete cal ;
return ;
}
cal - > setTime ( d , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Calendar::setTime failed " ) ;
delete cal ;
return ;
}
2003-02-21 08:32:22 +00:00
cal - > set ( UCAL_HOUR_OF_DAY , 0 ) ;
cal - > set ( UCAL_MINUTE , 0 ) ;
cal - > set ( UCAL_SECOND , 0 ) ;
cal - > add ( UCAL_DATE , - 5 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Calendar::add failed " ) ;
delete cal ;
return ;
}
UnicodeString s2 ;
dateToString ( cal - > getTime ( status ) , s2 ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
errln ( " Calendar::getTime failed " ) ;
delete cal ;
return ;
}
if ( s = = s2 )
logln ( " Pass: " + s + " == " + s2 ) ;
else
errln ( " FAIL: " + s + " != " + s2 ) ;
delete cal ;
}
// -------------------------------------
/**
* Confirm that adding to various fields works .
*/
void
CalendarTest : : TestAdd520 ( )
{
2003-02-21 08:32:22 +00:00
int32_t y = 1997 , m = UCAL_FEBRUARY , d = 1 ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
GregorianCalendar * temp = new GregorianCalendar ( y , m , d , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
check520 ( temp , y , m , d ) ;
2003-02-21 08:32:22 +00:00
temp - > add ( UCAL_YEAR , 1 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
y + + ;
check520 ( temp , y , m , d ) ;
2003-02-21 08:32:22 +00:00
temp - > add ( UCAL_MONTH , 1 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
m + + ;
check520 ( temp , y , m , d ) ;
2003-02-21 08:32:22 +00:00
temp - > add ( UCAL_DATE , 1 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
d + + ;
check520 ( temp , y , m , d ) ;
2003-02-21 08:32:22 +00:00
temp - > add ( UCAL_DATE , 2 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
d + = 2 ;
check520 ( temp , y , m , d ) ;
2003-02-21 08:32:22 +00:00
temp - > add ( UCAL_DATE , 28 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
d = 1 ; + + m ;
check520 ( temp , y , m , d ) ;
delete temp ;
}
// -------------------------------------
/**
* Execute adding and rolling in GregorianCalendar extensively ,
*/
void
CalendarTest : : TestAddRollExtensive ( )
{
int32_t maxlimit = 40 ;
2003-02-21 08:32:22 +00:00
int32_t y = 1997 , m = UCAL_FEBRUARY , d = 1 , hr = 1 , min = 1 , sec = 0 , ms = 0 ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
GregorianCalendar * temp = new GregorianCalendar ( y , m , d , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
2003-02-21 08:32:22 +00:00
temp - > set ( UCAL_HOUR , hr ) ;
temp - > set ( UCAL_MINUTE , min ) ;
temp - > set ( UCAL_SECOND , sec ) ;
temp - > set ( UCAL_MILLISECOND , ms ) ;
2009-03-13 03:21:29 +00:00
temp - > setMinimalDaysInFirstWeek ( 1 ) ;
1999-08-16 21:50:52 +00:00
2003-02-21 08:32:22 +00:00
UCalendarDateFields e ;
1999-08-16 21:50:52 +00:00
logln ( " Testing GregorianCalendar add... " ) ;
2003-02-21 08:32:22 +00:00
e = UCAL_YEAR ;
while ( e < UCAL_FIELD_COUNT ) {
1999-08-16 21:50:52 +00:00
int32_t i ;
int32_t limit = maxlimit ;
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
for ( i = 0 ; i < limit ; i + + ) {
temp - > add ( e , 1 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { limit = i ; status = U_ZERO_ERROR ; }
1999-08-16 21:50:52 +00:00
}
for ( i = 0 ; i < limit ; i + + ) {
temp - > add ( e , - 1 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " GregorianCalendar::add -1 failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
check520 ( temp , y , m , d , hr , min , sec , ms , e ) ;
2003-02-21 08:32:22 +00:00
e = ( UCalendarDateFields ) ( ( int32_t ) e + 1 ) ;
1999-08-16 21:50:52 +00:00
}
logln ( " Testing GregorianCalendar roll... " ) ;
2003-02-21 08:32:22 +00:00
e = UCAL_YEAR ;
while ( e < UCAL_FIELD_COUNT ) {
1999-08-16 21:50:52 +00:00
int32_t i ;
int32_t limit = maxlimit ;
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
for ( i = 0 ; i < limit ; i + + ) {
2003-10-26 10:20:40 +00:00
logln ( calToStr ( * temp ) + UnicodeString ( " " ) + fieldName ( e ) + UnicodeString ( " ++ " ) ) ;
1999-08-16 21:50:52 +00:00
temp - > roll ( e , 1 , status ) ;
2003-10-26 10:20:40 +00:00
if ( U_FAILURE ( status ) ) {
logln ( " caltest.cpp:%d e=%d, i=%d - roll(+) err %s \n " , __LINE__ , ( int ) e , ( int ) i , u_errorName ( status ) ) ;
logln ( calToStr ( * temp ) ) ;
limit = i ; status = U_ZERO_ERROR ;
}
1999-08-16 21:50:52 +00:00
}
for ( i = 0 ; i < limit ; i + + ) {
2003-10-26 10:20:40 +00:00
logln ( " caltest.cpp:%d e=%d, i=%d \n " , __LINE__ , ( int ) e , ( int ) i ) ;
logln ( calToStr ( * temp ) + UnicodeString ( " " ) + fieldName ( e ) + UnicodeString ( " -- " ) ) ;
1999-08-16 21:50:52 +00:00
temp - > roll ( e , - 1 , status ) ;
2003-10-26 10:20:40 +00:00
if ( U_FAILURE ( status ) ) { errln ( UnicodeString ( " GregorianCalendar::roll " ) + CalendarTest : : fieldName ( e ) + " count= " + UnicodeString ( ' @ ' + i ) + " by -1 failed with " + u_errorName ( status ) ) ; return ; }
1999-08-16 21:50:52 +00:00
}
check520 ( temp , y , m , d , hr , min , sec , ms , e ) ;
2003-02-21 08:32:22 +00:00
e = ( UCalendarDateFields ) ( ( int32_t ) e + 1 ) ;
1999-08-16 21:50:52 +00:00
}
delete temp ;
}
// -------------------------------------
void
CalendarTest : : check520 ( Calendar * c ,
int32_t y , int32_t m , int32_t d ,
int32_t hr , int32_t min , int32_t sec ,
2003-02-21 08:32:22 +00:00
int32_t ms , UCalendarDateFields field )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2003-02-21 08:32:22 +00:00
if ( c - > get ( UCAL_YEAR , status ) ! = y | |
c - > get ( UCAL_MONTH , status ) ! = m | |
c - > get ( UCAL_DATE , status ) ! = d | |
c - > get ( UCAL_HOUR , status ) ! = hr | |
c - > get ( UCAL_MINUTE , status ) ! = min | |
c - > get ( UCAL_SECOND , status ) ! = sec | |
c - > get ( UCAL_MILLISECOND , status ) ! = ms ) {
1999-10-18 22:48:32 +00:00
errln ( UnicodeString ( " U_FAILURE for field " ) + ( int32_t ) field +
1999-08-16 21:50:52 +00:00
" : Expected y/m/d h:m:s:ms of " +
y + " / " + ( m + 1 ) + " / " + d + " " +
hr + " : " + min + " : " + sec + " : " + ms +
2003-02-21 08:32:22 +00:00
" ; got " + c - > get ( UCAL_YEAR , status ) +
" / " + ( c - > get ( UCAL_MONTH , status ) + 1 ) +
" / " + c - > get ( UCAL_DATE , status ) +
" " + c - > get ( UCAL_HOUR , status ) + " : " +
c - > get ( UCAL_MINUTE , status ) + " : " +
c - > get ( UCAL_SECOND , status ) + " : " +
c - > get ( UCAL_MILLISECOND , status )
1999-08-16 21:50:52 +00:00
) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
else
logln ( UnicodeString ( " Confirmed: " ) + y + " / " +
( m + 1 ) + " / " + d + " " +
hr + " : " + min + " : " + sec + " : " + ms ) ;
}
// -------------------------------------
void
CalendarTest : : check520 ( Calendar * c ,
int32_t y , int32_t m , int32_t d )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2003-02-21 08:32:22 +00:00
if ( c - > get ( UCAL_YEAR , status ) ! = y | |
c - > get ( UCAL_MONTH , status ) ! = m | |
c - > get ( UCAL_DATE , status ) ! = d ) {
1999-08-16 21:50:52 +00:00
errln ( UnicodeString ( " FAILURE: Expected y/m/d of " ) +
y + " / " + ( m + 1 ) + " / " + d + " " +
2003-02-21 08:32:22 +00:00
" ; got " + c - > get ( UCAL_YEAR , status ) +
" / " + ( c - > get ( UCAL_MONTH , status ) + 1 ) +
" / " + c - > get ( UCAL_DATE , status )
1999-08-16 21:50:52 +00:00
) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
else
logln ( UnicodeString ( " Confirmed: " ) + y + " / " +
( m + 1 ) + " / " + d ) ;
}
// -------------------------------------
/**
* Test that setting of fields works . In particular , make sure that all instances
* of GregorianCalendar don ' t share a static instance of the fields array .
*/
void
CalendarTest : : TestFieldSet4781 ( )
{
// try {
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
GregorianCalendar * g = new GregorianCalendar ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
GregorianCalendar * g2 = new GregorianCalendar ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
2003-02-21 08:32:22 +00:00
g2 - > set ( UCAL_HOUR , 12 , status ) ;
g2 - > set ( UCAL_MINUTE , 0 , status ) ;
g2 - > set ( UCAL_SECOND , 0 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::set failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
if ( * g = = * g2 ) logln ( " Same " ) ;
else logln ( " Different " ) ;
//}
//catch(IllegalArgumentException e) {
//errln("Unexpected exception seen: " + e);
//}
delete g ;
delete g2 ;
}
// -------------------------------------
/* We don't support serialization on C++
void
CalendarTest : : TestSerialize337 ( )
{
Calendar cal = Calendar : : getInstance ( ) ;
2000-05-18 22:08:39 +00:00
UBool ok = FALSE ;
1999-08-16 21:50:52 +00:00
try {
FileOutputStream f = new FileOutputStream ( FILENAME ) ;
ObjectOutput s = new ObjectOutputStream ( f ) ;
s . writeObject ( PREFIX ) ;
s . writeObject ( cal ) ;
s . writeObject ( POSTFIX ) ;
f . close ( ) ;
FileInputStream in = new FileInputStream ( FILENAME ) ;
ObjectInputStream t = new ObjectInputStream ( in ) ;
UnicodeString & pre = ( UnicodeString & ) t . readObject ( ) ;
Calendar c = ( Calendar ) t . readObject ( ) ;
UnicodeString & post = ( UnicodeString & ) t . readObject ( ) ;
in . close ( ) ;
ok = pre . equals ( PREFIX ) & &
post . equals ( POSTFIX ) & &
cal - > equals ( c ) ;
File fl = new File ( FILENAME ) ;
fl . delete ( ) ;
}
catch ( IOException e ) {
errln ( " FAIL: Exception received: " ) ;
e . printStackTrace ( log ) ;
}
catch ( ClassNotFoundException e ) {
errln ( " FAIL: Exception received: " ) ;
e . printStackTrace ( log ) ;
}
if ( ! ok ) errln ( " Serialization of Calendar object failed. " ) ;
}
UnicodeString & CalendarTest : : PREFIX = " abc " ;
UnicodeString & CalendarTest : : POSTFIX = " def " ;
UnicodeString & CalendarTest : : FILENAME = " tmp337.bin " ;
*/
// -------------------------------------
/**
* Verify that the seconds of a Calendar can be zeroed out through the
* expected sequence of operations .
*/
void
CalendarTest : : TestSecondsZero121 ( )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
Calendar * cal = new GregorianCalendar ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
cal - > setTime ( Calendar : : getNow ( ) , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::setTime failed " ) ; return ; }
2003-02-21 08:32:22 +00:00
cal - > set ( UCAL_SECOND , 0 ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::set failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
UDate d = cal - > getTime ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::getTime failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
UnicodeString s ;
dateToString ( d , s ) ;
2009-06-12 19:34:21 +00:00
if ( s . indexOf ( " DATE_FORMAT_FAILURE " ) > = 0 ) {
dataerrln ( " Got: \" DATE_FORMAT_FAILURE \" . " ) ;
} else if ( s . indexOf ( " :00 " ) < 0 ) {
errln ( " Expected to see :00 in " + s ) ;
}
1999-08-16 21:50:52 +00:00
delete cal ;
}
// -------------------------------------
/**
* Verify that a specific sequence of adding and setting works as expected ;
* it should not vary depending on when and whether the get method is
* called .
*/
void
CalendarTest : : TestAddSetGet0610 ( )
{
2001-05-09 23:15:05 +00:00
UnicodeString EXPECTED_0610 ( " 1993/0/5 " , " " ) ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
{
Calendar * calendar = new GregorianCalendar ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
2003-02-21 08:32:22 +00:00
calendar - > set ( 1993 , UCAL_JANUARY , 4 ) ;
1999-08-16 21:50:52 +00:00
logln ( " 1A) " + value ( calendar ) ) ;
2003-02-21 08:32:22 +00:00
calendar - > add ( UCAL_DATE , 1 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
UnicodeString v = value ( calendar ) ;
logln ( " 1B) " + v ) ;
logln ( " --) 1993/0/5 " ) ;
if ( ! ( v = = EXPECTED_0610 ) ) errln ( " Expected " + EXPECTED_0610 + " ; saw " + v ) ;
delete calendar ;
}
{
2003-02-21 08:32:22 +00:00
Calendar * calendar = new GregorianCalendar ( 1993 , UCAL_JANUARY , 4 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
logln ( " 2A) " + value ( calendar ) ) ;
2003-02-21 08:32:22 +00:00
calendar - > add ( UCAL_DATE , 1 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
UnicodeString v = value ( calendar ) ;
logln ( " 2B) " + v ) ;
logln ( " --) 1993/0/5 " ) ;
if ( ! ( v = = EXPECTED_0610 ) ) errln ( " Expected " + EXPECTED_0610 + " ; saw " + v ) ;
delete calendar ;
}
{
2003-02-21 08:32:22 +00:00
Calendar * calendar = new GregorianCalendar ( 1993 , UCAL_JANUARY , 4 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
logln ( " 3A) " + value ( calendar ) ) ;
calendar - > getTime ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::getTime failed " ) ; return ; }
2003-02-21 08:32:22 +00:00
calendar - > add ( UCAL_DATE , 1 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
UnicodeString v = value ( calendar ) ;
logln ( " 3B) " + v ) ;
logln ( " --) 1993/0/5 " ) ;
if ( ! ( v = = EXPECTED_0610 ) ) errln ( " Expected " + EXPECTED_0610 + " ; saw " + v ) ;
delete calendar ;
}
}
// -------------------------------------
UnicodeString
CalendarTest : : value ( Calendar * calendar )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2003-02-21 08:32:22 +00:00
return UnicodeString ( " " ) + ( int32_t ) calendar - > get ( UCAL_YEAR , status ) +
" / " + ( int32_t ) calendar - > get ( UCAL_MONTH , status ) +
" / " + ( int32_t ) calendar - > get ( UCAL_DATE , status ) +
1999-10-18 22:48:32 +00:00
( U_FAILURE ( status ) ? " FAIL: Calendar::get failed " : " " ) ;
1999-08-16 21:50:52 +00:00
}
// -------------------------------------
/**
* Verify that various fields on a known date are set correctly .
*/
void
CalendarTest : : TestFields060 ( )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
int32_t year = 1997 ;
2003-02-21 08:32:22 +00:00
int32_t month = UCAL_OCTOBER ;
1999-08-16 21:50:52 +00:00
int32_t dDate = 22 ;
GregorianCalendar * calendar = 0 ;
calendar = new GregorianCalendar ( year , month , dDate , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
for ( int32_t i = 0 ; i < EXPECTED_FIELDS_length ; ) {
2003-02-21 08:32:22 +00:00
UCalendarDateFields field = ( UCalendarDateFields ) EXPECTED_FIELDS [ i + + ] ;
1999-08-16 21:50:52 +00:00
int32_t expected = EXPECTED_FIELDS [ i + + ] ;
if ( calendar - > get ( field , status ) ! = expected ) {
errln ( UnicodeString ( " Expected field " ) + ( int32_t ) field + " to have value " + ( int32_t ) expected +
" ; received " + ( int32_t ) calendar - > get ( field , status ) + " instead " ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
}
delete calendar ;
}
int32_t CalendarTest : : EXPECTED_FIELDS [ ] = {
2003-02-21 08:32:22 +00:00
UCAL_YEAR , 1997 ,
UCAL_MONTH , UCAL_OCTOBER ,
UCAL_DATE , 22 ,
UCAL_DAY_OF_WEEK , UCAL_WEDNESDAY ,
UCAL_DAY_OF_WEEK_IN_MONTH , 4 ,
UCAL_DAY_OF_YEAR , 295
1999-08-16 21:50:52 +00:00
} ;
2001-05-22 16:54:15 +00:00
const int32_t CalendarTest : : EXPECTED_FIELDS_length = ( int32_t ) ( sizeof ( CalendarTest : : EXPECTED_FIELDS ) /
sizeof ( CalendarTest : : EXPECTED_FIELDS [ 0 ] ) ) ;
1999-08-16 21:50:52 +00:00
// -------------------------------------
/**
* Verify that various fields on a known date are set correctly . In this
* case , the start of the epoch ( January 1 1970 ) .
*/
void
CalendarTest : : TestEpochStartFields ( )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
TimeZone * z = TimeZone : : createDefault ( ) ;
Calendar * c = Calendar : : createInstance ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::createInstance failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
UDate d = - z - > getRawOffset ( ) ;
GregorianCalendar * gc = new GregorianCalendar ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
gc - > setTimeZone ( * z ) ;
gc - > setTime ( d , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::setTime failed " ) ; return ; }
2000-05-18 22:08:39 +00:00
UBool idt = gc - > inDaylightTime ( status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " GregorianCalendar::inDaylightTime failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
if ( idt ) {
UnicodeString str ;
logln ( " Warning: Skipping test because " + dateToString ( d , str ) + " is in DST. " ) ;
}
else {
c - > setTime ( d , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::setTime failed " ) ; return ; }
2003-02-21 08:32:22 +00:00
for ( int32_t i = 0 ; i < UCAL_ZONE_OFFSET ; + + i ) {
if ( c - > get ( ( UCalendarDateFields ) i , status ) ! = EPOCH_FIELDS [ i ] )
1999-08-16 21:50:52 +00:00
errln ( UnicodeString ( " Expected field " ) + i + " to have value " + EPOCH_FIELDS [ i ] +
2003-02-21 08:32:22 +00:00
" ; saw " + c - > get ( ( UCalendarDateFields ) i , status ) + " instead " ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
2003-02-21 08:32:22 +00:00
if ( c - > get ( UCAL_ZONE_OFFSET , status ) ! = z - > getRawOffset ( ) )
1999-08-16 21:50:52 +00:00
{
errln ( UnicodeString ( " Expected field ZONE_OFFSET to have value " ) + z - > getRawOffset ( ) +
2003-02-21 08:32:22 +00:00
" ; saw " + c - > get ( UCAL_ZONE_OFFSET , status ) + " instead " ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
2003-02-21 08:32:22 +00:00
if ( c - > get ( UCAL_DST_OFFSET , status ) ! = 0 )
1999-08-16 21:50:52 +00:00
{
errln ( UnicodeString ( " Expected field DST_OFFSET to have value 0 " ) +
2003-02-21 08:32:22 +00:00
" ; saw " + c - > get ( UCAL_DST_OFFSET , status ) + " instead " ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
}
}
delete c ;
delete z ;
delete gc ;
}
int32_t CalendarTest : : EPOCH_FIELDS [ ] = {
1 , 1970 , 0 , 1 , 1 , 1 , 1 , 5 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , - 28800000 , 0
} ;
// -------------------------------------
/**
* Test that the days of the week progress properly when add is called repeatedly
* for increments of 24 days .
*/
void
CalendarTest : : TestDOWProgression ( )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2003-02-21 08:32:22 +00:00
Calendar * cal = new GregorianCalendar ( 1972 , UCAL_OCTOBER , 26 , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
1999-08-16 21:50:52 +00:00
marchByDelta ( cal , 24 ) ;
delete cal ;
}
// -------------------------------------
2000-01-19 04:20:48 +00:00
void
CalendarTest : : TestDOW_LOCALandYEAR_WOY ( )
{
2000-01-25 02:29:22 +00:00
/* Note: I've commented out the loop_addroll tests for YEAR and
* YEAR_WOY below because these two fields should NOT behave
* identically when adding . YEAR should keep the month / dom
* invariant . YEAR_WOY should keep the woy / dow invariant . I ' ve
* added a new test that checks for this in place of the old call
* to loop_addroll . - aliu */
2000-01-19 04:20:48 +00:00
UErrorCode status = U_ZERO_ERROR ;
int32_t times = 20 ;
2002-03-26 23:18:57 +00:00
Calendar * cal = Calendar : : createInstance ( Locale : : getGermany ( ) , status ) ;
2000-01-19 04:20:48 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't create GregorianCalendar " ) ; return ; }
2002-03-26 23:18:57 +00:00
SimpleDateFormat * sdf = new SimpleDateFormat ( UnicodeString ( " YYYY'-W'ww-ee " ) , Locale : : getGermany ( ) , status ) ;
2009-06-12 19:34:21 +00:00
if ( U_FAILURE ( status ) ) { errcheckln ( status , " Couldn't create SimpleDateFormat - %s " , u_errorName ( status ) ) ; return ; }
2007-02-23 04:35:31 +00:00
// ICU no longer use localized date-time pattern characters by default.
// So we set pattern chars using 'J' instead of 'Y'.
DateFormatSymbols * dfs = new DateFormatSymbols ( Locale : : getGermany ( ) , status ) ;
dfs - > setLocalPatternChars ( UnicodeString ( " GyMdkHmsSEDFwWahKzJeugAZvcLQq " ) ) ;
sdf - > adoptDateFormatSymbols ( dfs ) ;
2000-01-25 17:49:13 +00:00
sdf - > applyLocalizedPattern ( UnicodeString ( " JJJJ'-W'ww-ee " ) , status ) ;
2000-01-19 04:20:48 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Couldn't apply localized pattern " ) ; return ; }
2007-02-23 04:35:31 +00:00
cal - > clear ( ) ;
2003-02-21 08:32:22 +00:00
cal - > set ( 1997 , UCAL_DECEMBER , 25 ) ;
2000-08-14 21:42:36 +00:00
doYEAR_WOYLoop ( cal , sdf , times , status ) ;
2003-02-21 08:32:22 +00:00
//loop_addroll(cal, /*sdf,*/ times, UCAL_YEAR_WOY, UCAL_YEAR, status);
2000-01-25 02:29:22 +00:00
yearAddTest ( * cal , status ) ; // aliu
2003-02-21 08:32:22 +00:00
loop_addroll ( cal , /*sdf,*/ times , UCAL_DOW_LOCAL , UCAL_DAY_OF_WEEK , status ) ;
2000-01-19 04:20:48 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Error in parse/calculate test for 1997 " ) ; return ; }
2003-10-26 10:20:40 +00:00
2000-01-20 04:42:04 +00:00
cal - > clear ( ) ;
2003-02-21 08:32:22 +00:00
cal - > set ( 1998 , UCAL_DECEMBER , 25 ) ;
2000-08-14 21:42:36 +00:00
doYEAR_WOYLoop ( cal , sdf , times , status ) ;
2003-02-21 08:32:22 +00:00
//loop_addroll(cal, /*sdf,*/ times, UCAL_YEAR_WOY, UCAL_YEAR, status);
2000-01-25 02:29:22 +00:00
yearAddTest ( * cal , status ) ; // aliu
2003-02-21 08:32:22 +00:00
loop_addroll ( cal , /*sdf,*/ times , UCAL_DOW_LOCAL , UCAL_DAY_OF_WEEK , status ) ;
2000-01-19 04:20:48 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Error in parse/calculate test for 1998 " ) ; return ; }
2003-10-26 10:20:40 +00:00
2000-01-20 04:42:04 +00:00
cal - > clear ( ) ;
2003-02-21 08:32:22 +00:00
cal - > set ( 1582 , UCAL_OCTOBER , 1 ) ;
2000-08-14 21:42:36 +00:00
doYEAR_WOYLoop ( cal , sdf , times , status ) ;
2000-08-15 18:25:20 +00:00
//loop_addroll(cal, /*sdf,*/ times, Calendar::YEAR_WOY, Calendar::YEAR, status);
2000-01-25 02:29:22 +00:00
yearAddTest ( * cal , status ) ; // aliu
2003-02-21 08:32:22 +00:00
loop_addroll ( cal , /*sdf,*/ times , UCAL_DOW_LOCAL , UCAL_DAY_OF_WEEK , status ) ;
2000-01-19 04:20:48 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Error in parse/calculate test for 1582 " ) ; return ; }
2000-06-29 19:42:17 +00:00
delete sdf ;
delete cal ;
2000-01-19 04:20:48 +00:00
return ;
}
2000-01-25 02:29:22 +00:00
/**
* Confirm that adding a YEAR and adding a YEAR_WOY work properly for
* the given Calendar at its current setting .
*/
void CalendarTest : : yearAddTest ( Calendar & cal , UErrorCode & status ) {
/**
* When adding the YEAR , the month and day should remain constant .
* When adding the YEAR_WOY , the WOY and DOW should remain constant . - aliu
* Examples :
* Wed Jan 14 1998 / 1998 - W03 - 03 Add ( YEAR_WOY , 1 ) - > Wed Jan 20 1999 / 1999 - W03 - 03
* Add ( YEAR , 1 ) - > Thu Jan 14 1999 / 1999 - W02 - 04
* Thu Jan 14 1999 / 1999 - W02 - 04 Add ( YEAR_WOY , 1 ) - > Thu Jan 13 2000 / 2000 - W02 - 04
* Add ( YEAR , 1 ) - > Fri Jan 14 2000 / 2000 - W02 - 05
* Sun Oct 31 1582 / 1582 - W42 - 07 Add ( YEAR_WOY , 1 ) - > Sun Oct 23 1583 / 1583 - W42 - 07
* Add ( YEAR , 1 ) - > Mon Oct 31 1583 / 1583 - W44 - 01
*/
2003-02-21 08:32:22 +00:00
int32_t y = cal . get ( UCAL_YEAR , status ) ;
int32_t mon = cal . get ( UCAL_MONTH , status ) ;
int32_t day = cal . get ( UCAL_DATE , status ) ;
int32_t ywy = cal . get ( UCAL_YEAR_WOY , status ) ;
int32_t woy = cal . get ( UCAL_WEEK_OF_YEAR , status ) ;
int32_t dow = cal . get ( UCAL_DOW_LOCAL , status ) ;
2000-01-25 02:29:22 +00:00
UDate t = cal . getTime ( status ) ;
2005-05-19 20:28:20 +00:00
if ( U_FAILURE ( status ) ) {
errln ( UnicodeString ( " Failed to create Calendar for locale. Error: " ) + UnicodeString ( u_errorName ( status ) ) ) ;
return ;
}
2000-01-25 02:29:22 +00:00
UnicodeString str , str2 ;
2000-04-15 21:28:17 +00:00
SimpleDateFormat fmt ( UnicodeString ( " EEE MMM dd yyyy / YYYY'-W'ww-ee " ) , status ) ;
2000-01-25 02:29:22 +00:00
fmt . setCalendar ( cal ) ;
fmt . format ( t , str . remove ( ) ) ;
str + = " .add(YEAR, 1) => " ;
2003-02-21 08:32:22 +00:00
cal . add ( UCAL_YEAR , 1 , status ) ;
int32_t y2 = cal . get ( UCAL_YEAR , status ) ;
int32_t mon2 = cal . get ( UCAL_MONTH , status ) ;
int32_t day2 = cal . get ( UCAL_DATE , status ) ;
2000-01-25 02:29:22 +00:00
fmt . format ( cal . getTime ( status ) , str ) ;
if ( y2 ! = ( y + 1 ) | | mon2 ! = mon | | day2 ! = day ) {
str + = ( UnicodeString ) " , expected year " +
( y + 1 ) + " , month " + ( mon + 1 ) + " , day " + day ;
errln ( ( UnicodeString ) " FAIL: " + str ) ;
2003-10-26 10:20:40 +00:00
logln ( UnicodeString ( " -> " ) + CalendarTest : : calToStr ( cal ) ) ;
2000-01-25 02:29:22 +00:00
} else {
logln ( str ) ;
}
fmt . format ( t , str . remove ( ) ) ;
str + = " .add(YEAR_WOY, 1)=> " ;
cal . setTime ( t , status ) ;
2003-10-26 10:20:40 +00:00
logln ( UnicodeString ( " <- " ) + CalendarTest : : calToStr ( cal ) ) ;
2003-02-21 08:32:22 +00:00
cal . add ( UCAL_YEAR_WOY , 1 , status ) ;
int32_t ywy2 = cal . get ( UCAL_YEAR_WOY , status ) ;
int32_t woy2 = cal . get ( UCAL_WEEK_OF_YEAR , status ) ;
int32_t dow2 = cal . get ( UCAL_DOW_LOCAL , status ) ;
2000-01-25 02:29:22 +00:00
fmt . format ( cal . getTime ( status ) , str ) ;
if ( ywy2 ! = ( ywy + 1 ) | | woy2 ! = woy | | dow2 ! = dow ) {
str + = ( UnicodeString ) " , expected yearWOY " +
( ywy + 1 ) + " , woy " + woy + " , dowLocal " + dow ;
errln ( ( UnicodeString ) " FAIL: " + str ) ;
2003-10-26 10:20:40 +00:00
logln ( UnicodeString ( " -> " ) + CalendarTest : : calToStr ( cal ) ) ;
2000-01-25 02:29:22 +00:00
} else {
logln ( str ) ;
}
}
2000-01-19 04:20:48 +00:00
// -------------------------------------
2003-02-21 08:32:22 +00:00
void CalendarTest : : loop_addroll ( Calendar * cal , /*SimpleDateFormat *sdf,*/ int times , UCalendarDateFields field , UCalendarDateFields field2 , UErrorCode & errorCode ) {
2000-01-19 04:20:48 +00:00
Calendar * calclone ;
2000-04-15 21:28:17 +00:00
SimpleDateFormat fmt ( UnicodeString ( " EEE MMM dd yyyy / YYYY'-W'ww-ee " ) , errorCode ) ;
2000-01-25 02:29:22 +00:00
fmt . setCalendar ( * cal ) ;
2000-01-20 21:58:07 +00:00
int i ;
for ( i = 0 ; i < times ; i + + ) {
2000-01-19 04:20:48 +00:00
calclone = cal - > clone ( ) ;
2000-01-25 02:29:22 +00:00
UDate start = cal - > getTime ( errorCode ) ;
2000-01-19 04:20:48 +00:00
cal - > add ( field , 1 , errorCode ) ;
if ( U_FAILURE ( errorCode ) ) { errln ( " Error in add " ) ; delete calclone ; return ; }
calclone - > add ( field2 , 1 , errorCode ) ;
if ( U_FAILURE ( errorCode ) ) { errln ( " Error in add " ) ; delete calclone ; return ; }
if ( cal - > getTime ( errorCode ) ! = calclone - > getTime ( errorCode ) ) {
2000-01-25 02:29:22 +00:00
UnicodeString str ( " FAIL: Results of add differ. " ) , str2 ;
str + = fmt . format ( start , str2 ) + " " ;
str + = UnicodeString ( " Add( " ) + fieldName ( field ) + " , 1) -> " +
fmt . format ( cal - > getTime ( errorCode ) , str2 . remove ( ) ) + " ; " ;
str + = UnicodeString ( " Add( " ) + fieldName ( field2 ) + " , 1) -> " +
fmt . format ( calclone - > getTime ( errorCode ) , str2 . remove ( ) ) ;
errln ( str ) ;
2000-01-19 04:20:48 +00:00
delete calclone ;
return ;
}
delete calclone ;
}
for ( i = 0 ; i < times ; i + + ) {
calclone = cal - > clone ( ) ;
cal - > roll ( field , ( int32_t ) 1 , errorCode ) ;
if ( U_FAILURE ( errorCode ) ) { errln ( " Error in roll " ) ; delete calclone ; return ; }
calclone - > roll ( field2 , ( int32_t ) 1 , errorCode ) ;
if ( U_FAILURE ( errorCode ) ) { errln ( " Error in roll " ) ; delete calclone ; return ; }
if ( cal - > getTime ( errorCode ) ! = calclone - > getTime ( errorCode ) ) {
delete calclone ;
2000-01-20 04:42:04 +00:00
errln ( " Results of roll differ! " ) ;
2000-01-19 04:20:48 +00:00
return ;
}
delete calclone ;
}
}
// -------------------------------------
void
CalendarTest : : doYEAR_WOYLoop ( Calendar * cal , SimpleDateFormat * sdf ,
int32_t times , UErrorCode & errorCode ) {
UnicodeString us ;
UDate tst , original ;
2002-03-26 23:18:57 +00:00
Calendar * tstres = new GregorianCalendar ( Locale : : getGermany ( ) , errorCode ) ;
2000-01-19 04:20:48 +00:00
for ( int i = 0 ; i < times ; + + i ) {
2000-01-20 21:58:07 +00:00
sdf - > format ( Formattable ( cal - > getTime ( errorCode ) , Formattable : : kIsDate ) , us , errorCode ) ;
2000-01-19 04:20:48 +00:00
//logln("expected: "+us);
if ( U_FAILURE ( errorCode ) ) { errln ( " Format error " ) ; return ; }
tst = sdf - > parse ( us , errorCode ) ;
if ( U_FAILURE ( errorCode ) ) { errln ( " Parse error " ) ; return ; }
tstres - > clear ( ) ;
tstres - > setTime ( tst , errorCode ) ;
2003-02-21 08:32:22 +00:00
//logln((UnicodeString)"Parsed week of year is "+tstres->get(UCAL_WEEK_OF_YEAR, errorCode));
2000-01-19 04:20:48 +00:00
if ( U_FAILURE ( errorCode ) ) { errln ( " Set time error " ) ; return ; }
original = cal - > getTime ( errorCode ) ;
us . remove ( ) ;
2000-01-20 21:58:07 +00:00
sdf - > format ( Formattable ( tst , Formattable : : kIsDate ) , us , errorCode ) ;
2000-01-19 04:20:48 +00:00
//logln("got: "+us);
if ( U_FAILURE ( errorCode ) ) { errln ( " Get time error " ) ; return ; }
2000-01-20 04:42:04 +00:00
if ( original ! = tst ) {
2000-01-19 04:20:48 +00:00
us . remove ( ) ;
2000-01-20 21:58:07 +00:00
sdf - > format ( Formattable ( original , Formattable : : kIsDate ) , us , errorCode ) ;
2003-11-03 23:21:03 +00:00
errln ( " FAIL: Parsed time doesn't match with regular " ) ;
logln ( " expected " + us + " " + calToStr ( * cal ) ) ;
2000-01-19 04:20:48 +00:00
us . remove ( ) ;
2000-01-20 21:58:07 +00:00
sdf - > format ( Formattable ( tst , Formattable : : kIsDate ) , us , errorCode ) ;
2003-11-03 23:21:03 +00:00
logln ( " got " + us + " " + calToStr ( * tstres ) ) ;
2000-01-19 04:20:48 +00:00
}
tstres - > clear ( ) ;
2003-02-21 08:32:22 +00:00
tstres - > set ( UCAL_YEAR_WOY , cal - > get ( UCAL_YEAR_WOY , errorCode ) ) ;
tstres - > set ( UCAL_WEEK_OF_YEAR , cal - > get ( UCAL_WEEK_OF_YEAR , errorCode ) ) ;
tstres - > set ( UCAL_DOW_LOCAL , cal - > get ( UCAL_DOW_LOCAL , errorCode ) ) ;
if ( cal - > get ( UCAL_YEAR , errorCode ) ! = tstres - > get ( UCAL_YEAR , errorCode ) ) {
2003-11-03 23:21:03 +00:00
errln ( " FAIL: Different Year! " ) ;
2003-02-21 08:32:22 +00:00
logln ( ( UnicodeString ) " Expected " + cal - > get ( UCAL_YEAR , errorCode ) ) ;
logln ( ( UnicodeString ) " Got " + tstres - > get ( UCAL_YEAR , errorCode ) ) ;
2000-01-19 04:20:48 +00:00
return ;
}
2003-02-21 08:32:22 +00:00
if ( cal - > get ( UCAL_DAY_OF_YEAR , errorCode ) ! = tstres - > get ( UCAL_DAY_OF_YEAR , errorCode ) ) {
2003-11-03 23:21:03 +00:00
errln ( " FAIL: Different Day Of Year! " ) ;
2003-02-21 08:32:22 +00:00
logln ( ( UnicodeString ) " Expected " + cal - > get ( UCAL_DAY_OF_YEAR , errorCode ) ) ;
logln ( ( UnicodeString ) " Got " + tstres - > get ( UCAL_DAY_OF_YEAR , errorCode ) ) ;
2000-01-19 04:20:48 +00:00
return ;
}
2003-11-03 23:21:03 +00:00
//logln(calToStr(*cal));
2003-02-21 08:32:22 +00:00
cal - > add ( UCAL_DATE , 1 , errorCode ) ;
2000-01-19 04:20:48 +00:00
if ( U_FAILURE ( errorCode ) ) { errln ( " Add error " ) ; return ; }
us . remove ( ) ;
}
delete ( tstres ) ;
}
// -------------------------------------
1999-08-16 21:50:52 +00:00
void
CalendarTest : : marchByDelta ( Calendar * cal , int32_t delta )
{
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
Calendar * cur = ( Calendar * ) cal - > clone ( ) ;
2003-02-21 08:32:22 +00:00
int32_t initialDOW = cur - > get ( UCAL_DAY_OF_WEEK , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
int32_t DOW , newDOW = initialDOW ;
do {
UnicodeString str ;
DOW = newDOW ;
logln ( UnicodeString ( " DOW = " ) + DOW + " " + dateToString ( cur - > getTime ( status ) , str ) ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::getTime failed " ) ; return ; }
2003-02-21 08:32:22 +00:00
cur - > add ( UCAL_DAY_OF_WEEK , delta , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::add failed " ) ; return ; }
2003-02-21 08:32:22 +00:00
newDOW = cur - > get ( UCAL_DAY_OF_WEEK , status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::get failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
int32_t expectedDOW = 1 + ( DOW + delta - 1 ) % 7 ;
if ( newDOW ! = expectedDOW ) {
errln ( UnicodeString ( " Day of week should be " ) + expectedDOW + " instead of " + newDOW +
" on " + dateToString ( cur - > getTime ( status ) , str ) ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) { errln ( " Calendar::getTime failed " ) ; return ; }
1999-08-16 21:50:52 +00:00
return ;
}
}
while ( newDOW ! = initialDOW ) ;
delete cur ;
}
2000-01-25 02:29:22 +00:00
# define CHECK(status, msg) \
if ( U_FAILURE ( status ) ) { \
2009-06-12 19:34:21 +00:00
errcheckln ( status , msg ) ; \
2000-01-25 02:29:22 +00:00
return ; \
}
void CalendarTest : : TestWOY ( void ) {
/*
FDW = Mon , MDFW = 4 :
Sun Dec 26 1999 , WOY 51
Mon Dec 27 1999 , WOY 52
Tue Dec 28 1999 , WOY 52
Wed Dec 29 1999 , WOY 52
Thu Dec 30 1999 , WOY 52
Fri Dec 31 1999 , WOY 52
Sat Jan 01 2000 , WOY 52 * * *
Sun Jan 02 2000 , WOY 52 * * *
Mon Jan 03 2000 , WOY 1
Tue Jan 04 2000 , WOY 1
Wed Jan 05 2000 , WOY 1
Thu Jan 06 2000 , WOY 1
Fri Jan 07 2000 , WOY 1
Sat Jan 08 2000 , WOY 1
Sun Jan 09 2000 , WOY 1
Mon Jan 10 2000 , WOY 2
FDW = Mon , MDFW = 2 :
Sun Dec 26 1999 , WOY 52
Mon Dec 27 1999 , WOY 1 * * *
Tue Dec 28 1999 , WOY 1 * * *
Wed Dec 29 1999 , WOY 1 * * *
Thu Dec 30 1999 , WOY 1 * * *
Fri Dec 31 1999 , WOY 1 * * *
Sat Jan 01 2000 , WOY 1
Sun Jan 02 2000 , WOY 1
Mon Jan 03 2000 , WOY 2
Tue Jan 04 2000 , WOY 2
Wed Jan 05 2000 , WOY 2
Thu Jan 06 2000 , WOY 2
Fri Jan 07 2000 , WOY 2
Sat Jan 08 2000 , WOY 2
Sun Jan 09 2000 , WOY 2
Mon Jan 10 2000 , WOY 3
*/
2003-10-26 10:20:40 +00:00
2000-01-25 02:29:22 +00:00
UnicodeString str ;
UErrorCode status = U_ZERO_ERROR ;
int32_t i ;
GregorianCalendar cal ( status ) ;
2000-04-15 21:28:17 +00:00
SimpleDateFormat fmt ( UnicodeString ( " EEE MMM dd yyyy', WOY' w " ) , status ) ;
2000-01-25 02:29:22 +00:00
CHECK ( status , " Fail: Cannot construct calendar/format " ) ;
2003-02-21 08:32:22 +00:00
UCalendarDaysOfWeek fdw = ( UCalendarDaysOfWeek ) 0 ;
2000-01-25 02:29:22 +00:00
2003-10-26 10:20:40 +00:00
//for (int8_t pass=2; pass<=2; ++pass) {
2000-01-25 02:29:22 +00:00
for ( int8_t pass = 1 ; pass < = 2 ; + + pass ) {
switch ( pass ) {
case 1 :
2003-02-21 08:32:22 +00:00
fdw = UCAL_MONDAY ;
2000-01-25 02:29:22 +00:00
cal . setFirstDayOfWeek ( fdw ) ;
cal . setMinimalDaysInFirstWeek ( 4 ) ;
2003-10-26 10:20:40 +00:00
fmt . adoptCalendar ( cal . clone ( ) ) ;
2000-01-25 02:29:22 +00:00
break ;
case 2 :
2003-02-21 08:32:22 +00:00
fdw = UCAL_MONDAY ;
2000-01-25 02:29:22 +00:00
cal . setFirstDayOfWeek ( fdw ) ;
cal . setMinimalDaysInFirstWeek ( 2 ) ;
2003-10-26 10:20:40 +00:00
fmt . adoptCalendar ( cal . clone ( ) ) ;
2000-01-25 02:29:22 +00:00
break ;
}
2003-10-26 10:20:40 +00:00
//for (i=2; i<=6; ++i) {
for ( i = 0 ; i < 16 ; + + i ) {
2000-01-25 02:29:22 +00:00
UDate t , t2 ;
int32_t t_y , t_woy , t_dow ;
cal . clear ( ) ;
2003-02-21 08:32:22 +00:00
cal . set ( 1999 , UCAL_DECEMBER , 26 + i ) ;
2000-01-25 02:29:22 +00:00
fmt . format ( t = cal . getTime ( status ) , str . remove ( ) ) ;
CHECK ( status , " Fail: getTime failed " ) ;
2003-10-26 10:20:40 +00:00
logln ( UnicodeString ( " * " ) + str ) ;
2003-02-21 08:32:22 +00:00
int32_t dow = cal . get ( UCAL_DAY_OF_WEEK , status ) ;
int32_t woy = cal . get ( UCAL_WEEK_OF_YEAR , status ) ;
int32_t year = cal . get ( UCAL_YEAR , status ) ;
int32_t mon = cal . get ( UCAL_MONTH , status ) ;
2003-10-26 10:20:40 +00:00
logln ( calToStr ( cal ) ) ;
2000-01-25 02:29:22 +00:00
CHECK ( status , " Fail: get failed " ) ;
int32_t dowLocal = dow - fdw ;
if ( dowLocal < 0 ) dowLocal + = 7 ;
dowLocal + + ;
int32_t yearWoy = year ;
2003-02-21 08:32:22 +00:00
if ( mon = = UCAL_JANUARY ) {
2000-01-25 02:29:22 +00:00
if ( woy > = 52 ) - - yearWoy ;
} else {
if ( woy = = 1 ) + + yearWoy ;
}
// Basic fields->time check y/woy/dow
// Since Y/WOY is ambiguous, we do a check of the fields,
// not of the specific time.
cal . clear ( ) ;
2003-02-21 08:32:22 +00:00
cal . set ( UCAL_YEAR , year ) ;
cal . set ( UCAL_WEEK_OF_YEAR , woy ) ;
cal . set ( UCAL_DAY_OF_WEEK , dow ) ;
t_y = cal . get ( UCAL_YEAR , status ) ;
t_woy = cal . get ( UCAL_WEEK_OF_YEAR , status ) ;
t_dow = cal . get ( UCAL_DAY_OF_WEEK , status ) ;
2000-01-25 02:29:22 +00:00
CHECK ( status , " Fail: get failed " ) ;
if ( t_y ! = year | | t_woy ! = woy | | t_dow ! = dow ) {
str = " Fail: y/woy/dow fields->time => " ;
fmt . format ( cal . getTime ( status ) , str ) ;
errln ( str ) ;
2003-10-26 10:20:40 +00:00
logln ( calToStr ( cal ) ) ;
logln ( " [get!=set] Y%d!=%d || woy%d!=%d || dow%d!=%d \n " ,
t_y , year , t_woy , woy , t_dow , dow ) ;
} else {
logln ( " y/woy/dow fields->time OK " ) ;
2000-01-25 02:29:22 +00:00
}
// Basic fields->time check y/woy/dow_local
// Since Y/WOY is ambiguous, we do a check of the fields,
// not of the specific time.
cal . clear ( ) ;
2003-02-21 08:32:22 +00:00
cal . set ( UCAL_YEAR , year ) ;
cal . set ( UCAL_WEEK_OF_YEAR , woy ) ;
cal . set ( UCAL_DOW_LOCAL , dowLocal ) ;
t_y = cal . get ( UCAL_YEAR , status ) ;
t_woy = cal . get ( UCAL_WEEK_OF_YEAR , status ) ;
t_dow = cal . get ( UCAL_DOW_LOCAL , status ) ;
2000-01-25 02:29:22 +00:00
CHECK ( status , " Fail: get failed " ) ;
if ( t_y ! = year | | t_woy ! = woy | | t_dow ! = dowLocal ) {
str = " Fail: y/woy/dow_local fields->time => " ;
fmt . format ( cal . getTime ( status ) , str ) ;
errln ( str ) ;
}
// Basic fields->time check y_woy/woy/dow
cal . clear ( ) ;
2003-02-21 08:32:22 +00:00
cal . set ( UCAL_YEAR_WOY , yearWoy ) ;
cal . set ( UCAL_WEEK_OF_YEAR , woy ) ;
cal . set ( UCAL_DAY_OF_WEEK , dow ) ;
2000-01-25 02:29:22 +00:00
t2 = cal . getTime ( status ) ;
CHECK ( status , " Fail: getTime failed " ) ;
if ( t ! = t2 ) {
str = " Fail: y_woy/woy/dow fields->time => " ;
fmt . format ( t2 , str ) ;
errln ( str ) ;
2003-10-26 10:20:40 +00:00
logln ( calToStr ( cal ) ) ;
logln ( " %.f != %.f \n " , t , t2 ) ;
} else {
logln ( " y_woy/woy/dow OK " ) ;
2000-01-25 02:29:22 +00:00
}
// Basic fields->time check y_woy/woy/dow_local
cal . clear ( ) ;
2003-02-21 08:32:22 +00:00
cal . set ( UCAL_YEAR_WOY , yearWoy ) ;
cal . set ( UCAL_WEEK_OF_YEAR , woy ) ;
cal . set ( UCAL_DOW_LOCAL , dowLocal ) ;
2000-01-25 02:29:22 +00:00
t2 = cal . getTime ( status ) ;
CHECK ( status , " Fail: getTime failed " ) ;
if ( t ! = t2 ) {
str = " Fail: y_woy/woy/dow_local fields->time => " ;
fmt . format ( t2 , str ) ;
errln ( str ) ;
}
2003-10-26 10:20:40 +00:00
logln ( " Testing DOW_LOCAL.. dow%d \n " , dow ) ;
2000-01-25 02:29:22 +00:00
// Make sure DOW_LOCAL disambiguates over DOW
int32_t wrongDow = dow - 3 ;
if ( wrongDow < 1 ) wrongDow + = 7 ;
cal . setTime ( t , status ) ;
2003-02-21 08:32:22 +00:00
cal . set ( UCAL_DAY_OF_WEEK , wrongDow ) ;
cal . set ( UCAL_DOW_LOCAL , dowLocal ) ;
2000-01-25 02:29:22 +00:00
t2 = cal . getTime ( status ) ;
CHECK ( status , " Fail: set/getTime failed " ) ;
if ( t ! = t2 ) {
str = " Fail: DOW_LOCAL fields->time => " ;
fmt . format ( t2 , str ) ;
errln ( str ) ;
2003-10-26 10:20:40 +00:00
logln ( calToStr ( cal ) ) ;
logln ( " %.f : DOW%d, DOW_LOCAL%d -> %.f \n " ,
t , wrongDow , dowLocal , t2 ) ;
2000-01-25 02:29:22 +00:00
}
// Make sure DOW disambiguates over DOW_LOCAL
int32_t wrongDowLocal = dowLocal - 3 ;
if ( wrongDowLocal < 1 ) wrongDowLocal + = 7 ;
cal . setTime ( t , status ) ;
2003-02-21 08:32:22 +00:00
cal . set ( UCAL_DOW_LOCAL , wrongDowLocal ) ;
cal . set ( UCAL_DAY_OF_WEEK , dow ) ;
2000-01-25 02:29:22 +00:00
t2 = cal . getTime ( status ) ;
CHECK ( status , " Fail: set/getTime failed " ) ;
if ( t ! = t2 ) {
str = " Fail: DOW fields->time => " ;
fmt . format ( t2 , str ) ;
errln ( str ) ;
}
// Make sure YEAR_WOY disambiguates over YEAR
cal . setTime ( t , status ) ;
2003-02-21 08:32:22 +00:00
cal . set ( UCAL_YEAR , year - 2 ) ;
cal . set ( UCAL_YEAR_WOY , yearWoy ) ;
2000-01-25 02:29:22 +00:00
t2 = cal . getTime ( status ) ;
CHECK ( status , " Fail: set/getTime failed " ) ;
if ( t ! = t2 ) {
str = " Fail: YEAR_WOY fields->time => " ;
fmt . format ( t2 , str ) ;
errln ( str ) ;
}
// Make sure YEAR disambiguates over YEAR_WOY
cal . setTime ( t , status ) ;
2003-02-21 08:32:22 +00:00
cal . set ( UCAL_YEAR_WOY , yearWoy - 2 ) ;
cal . set ( UCAL_YEAR , year ) ;
2000-01-25 02:29:22 +00:00
t2 = cal . getTime ( status ) ;
CHECK ( status , " Fail: set/getTime failed " ) ;
if ( t ! = t2 ) {
str = " Fail: YEAR fields->time => " ;
fmt . format ( t2 , str ) ;
errln ( str ) ;
}
}
}
/*
FDW = Mon , MDFW = 4 :
Sun Dec 26 1999 , WOY 51
Mon Dec 27 1999 , WOY 52
Tue Dec 28 1999 , WOY 52
Wed Dec 29 1999 , WOY 52
Thu Dec 30 1999 , WOY 52
Fri Dec 31 1999 , WOY 52
Sat Jan 01 2000 , WOY 52
Sun Jan 02 2000 , WOY 52
*/
// Roll the DOW_LOCAL within week 52
for ( i = 27 ; i < = 33 ; + + i ) {
int32_t amount ;
for ( amount = - 7 ; amount < = 7 ; + + amount ) {
str = " roll( " ;
2003-02-21 08:32:22 +00:00
cal . set ( 1999 , UCAL_DECEMBER , i ) ;
2000-01-25 02:29:22 +00:00
UDate t , t2 ;
fmt . format ( cal . getTime ( status ) , str ) ;
CHECK ( status , " Fail: getTime failed " ) ;
str + = UnicodeString ( " , " ) + amount + " ) = " ;
2003-02-21 08:32:22 +00:00
cal . roll ( UCAL_DOW_LOCAL , amount , status ) ;
2000-01-25 02:29:22 +00:00
CHECK ( status , " Fail: roll failed " ) ;
t = cal . getTime ( status ) ;
int32_t newDom = i + amount ;
while ( newDom < 27 ) newDom + = 7 ;
while ( newDom > 33 ) newDom - = 7 ;
2003-02-21 08:32:22 +00:00
cal . set ( 1999 , UCAL_DECEMBER , newDom ) ;
2000-01-25 02:29:22 +00:00
t2 = cal . getTime ( status ) ;
CHECK ( status , " Fail: getTime failed " ) ;
fmt . format ( t , str ) ;
if ( t ! = t2 ) {
str . append ( " , exp " ) ;
fmt . format ( t2 , str ) ;
errln ( str ) ;
} else {
logln ( str ) ;
}
}
}
}
2003-10-26 10:20:40 +00:00
void CalendarTest : : TestYWOY ( )
{
UnicodeString str ;
UErrorCode status = U_ZERO_ERROR ;
GregorianCalendar cal ( status ) ;
CHECK ( status , " Fail: Cannot construct calendar/format " ) ;
cal . setFirstDayOfWeek ( UCAL_SUNDAY ) ;
cal . setMinimalDaysInFirstWeek ( 1 ) ;
logln ( " Setting: ywoy=2004, woy=1, dow=MONDAY " ) ;
cal . clear ( ) ;
cal . set ( UCAL_YEAR_WOY , 2004 ) ;
cal . set ( UCAL_WEEK_OF_YEAR , 1 ) ;
cal . set ( UCAL_DAY_OF_WEEK , UCAL_MONDAY ) ;
logln ( calToStr ( cal ) ) ;
if ( cal . get ( UCAL_YEAR , status ) ! = 2003 ) {
errln ( " year not 2003 " ) ;
}
logln ( " + setting DOW to THURSDAY " ) ;
cal . clear ( ) ;
cal . set ( UCAL_YEAR_WOY , 2004 ) ;
cal . set ( UCAL_WEEK_OF_YEAR , 1 ) ;
cal . set ( UCAL_DAY_OF_WEEK , UCAL_THURSDAY ) ;
logln ( calToStr ( cal ) ) ;
if ( cal . get ( UCAL_YEAR , status ) ! = 2004 ) {
errln ( " year not 2004 " ) ;
}
logln ( " + setting DOW_LOCAL to 1 " ) ;
cal . clear ( ) ;
cal . set ( UCAL_YEAR_WOY , 2004 ) ;
cal . set ( UCAL_WEEK_OF_YEAR , 1 ) ;
cal . set ( UCAL_DAY_OF_WEEK , UCAL_THURSDAY ) ;
cal . set ( UCAL_DOW_LOCAL , 1 ) ;
logln ( calToStr ( cal ) ) ;
if ( cal . get ( UCAL_YEAR , status ) ! = 2003 ) {
errln ( " year not 2003 " ) ;
}
cal . setFirstDayOfWeek ( UCAL_MONDAY ) ;
cal . setMinimalDaysInFirstWeek ( 4 ) ;
UDate t = 946713600000. ;
cal . setTime ( t , status ) ;
cal . set ( UCAL_DAY_OF_WEEK , 4 ) ;
cal . set ( UCAL_DOW_LOCAL , 6 ) ;
if ( cal . getTime ( status ) ! = t ) {
logln ( calToStr ( cal ) ) ;
errln ( " FAIL: DOW_LOCAL did not take precedence " ) ;
}
}
2003-11-24 21:36:01 +00:00
void CalendarTest : : TestJD ( )
{
int32_t jd ;
static const int32_t kEpochStartAsJulianDay = 2440588 ;
UErrorCode status = U_ZERO_ERROR ;
GregorianCalendar cal ( status ) ;
cal . setTimeZone ( * TimeZone : : getGMT ( ) ) ;
cal . clear ( ) ;
jd = cal . get ( UCAL_JULIAN_DAY , status ) ;
if ( jd ! = kEpochStartAsJulianDay ) {
errln ( " Wanted JD of %d at time=0, [epoch 1970] but got %d \n " , kEpochStartAsJulianDay , jd ) ;
} else {
logln ( " Wanted JD of %d at time=0, [epoch 1970], got %d \n " , kEpochStartAsJulianDay , jd ) ;
}
cal . setTime ( Calendar : : getNow ( ) , status ) ;
cal . clear ( ) ;
cal . set ( UCAL_JULIAN_DAY , kEpochStartAsJulianDay ) ;
UDate epochTime = cal . getTime ( status ) ;
if ( epochTime ! = 0 ) {
errln ( " Wanted time of 0 at jd=%d, got %.1lf \n " , kEpochStartAsJulianDay , epochTime ) ;
} else {
logln ( " Wanted time of 0 at jd=%d, got %.1lf \n " , kEpochStartAsJulianDay , epochTime ) ;
}
}
2007-07-12 21:53:20 +00:00
// make sure the ctestfw utilities are in sync with the Calendar
void CalendarTest : : TestDebug ( )
{
for ( int32_t t = 0 ; t < = UDBG_ENUM_COUNT ; t + + ) {
int32_t count = udbg_enumCount ( ( UDebugEnumType ) t ) ;
if ( count = = - 1 ) {
logln ( " enumCount(%d) returned -1 " , count ) ;
continue ;
}
for ( int32_t i = 0 ; i < = count ; i + + ) {
2009-04-15 01:57:02 +00:00
if ( t < = UDBG_HIGHEST_CONTIGUOUS_ENUM & & i < count ) {
2007-07-12 21:53:20 +00:00
if ( i ! = udbg_enumArrayValue ( ( UDebugEnumType ) t , i ) ) {
errln ( " FAIL: udbg_enumArrayValue(%d,%d) returned %d, expected %d " , t , i , udbg_enumArrayValue ( ( UDebugEnumType ) t , i ) , i ) ;
}
} else {
logln ( " Testing count+1: " ) ;
}
2007-07-13 17:34:22 +00:00
const char * name = udbg_enumName ( ( UDebugEnumType ) t , i ) ;
if ( name = = NULL ) {
2009-04-15 01:57:02 +00:00
if ( i = = count | | t > UDBG_HIGHEST_CONTIGUOUS_ENUM ) {
2007-07-13 17:34:22 +00:00
logln ( " null name - expected. \n " ) ;
} else {
errln ( " FAIL: udbg_enumName(%d,%d) returned NULL " , t , i ) ;
}
name = " (null) " ;
}
2007-07-12 21:53:20 +00:00
logln ( " udbg_enumArrayValue(%d,%d) = %s, returned %d " , t , i ,
2007-07-13 17:34:22 +00:00
name , udbg_enumArrayValue ( ( UDebugEnumType ) t , i ) ) ;
2007-07-12 21:53:20 +00:00
logln ( " udbg_enumString = " + udbg_enumString ( ( UDebugEnumType ) t , i ) ) ;
}
2009-04-15 01:57:02 +00:00
if ( udbg_enumExpectedCount ( ( UDebugEnumType ) t ) ! = count & & t < = UDBG_HIGHEST_CONTIGUOUS_ENUM ) {
2007-07-12 21:53:20 +00:00
errln ( " FAIL: udbg_enumExpectedCount(%d): %d, != UCAL_FIELD_COUNT=%d " , t , udbg_enumExpectedCount ( ( UDebugEnumType ) t ) , count ) ;
} else {
logln ( " udbg_ucal_fieldCount: %d, UCAL_FIELD_COUNT=udbg_enumCount %d " , udbg_enumExpectedCount ( ( UDebugEnumType ) t ) , count ) ;
}
}
}
2000-01-25 02:29:22 +00:00
# undef CHECK
2003-12-04 23:16:57 +00:00
// List of interesting locales
const char * CalendarTest : : testLocaleID ( int32_t i )
{
switch ( i ) {
2003-12-09 20:52:52 +00:00
case 0 : return " he_IL@calendar=hebrew " ;
case 1 : return " en_US@calendar=hebrew " ;
case 2 : return " fr_FR@calendar=hebrew " ;
case 3 : return " fi_FI@calendar=hebrew " ;
case 4 : return " nl_NL@calendar=hebrew " ;
case 5 : return " hu_HU@calendar=hebrew " ;
case 6 : return " nl_BE@currency=MTL;calendar=islamic " ;
case 7 : return " th_TH_TRADITIONAL@calendar=gregorian " ;
case 8 : return " ar_JO@calendar=islamic-civil " ;
case 9 : return " fi_FI@calendar=islamic " ;
case 10 : return " fr_CH@calendar=islamic-civil " ;
case 11 : return " he_IL@calendar=islamic-civil " ;
case 12 : return " hu_HU@calendar=buddhist " ;
case 13 : return " hu_HU@calendar=islamic " ;
case 14 : return " en_US@calendar=japanese " ;
2003-12-04 23:16:57 +00:00
default : return NULL ;
}
}
int32_t CalendarTest : : testLocaleCount ( )
{
static int32_t gLocaleCount = - 1 ;
if ( gLocaleCount < 0 ) {
int32_t i ;
for ( i = 0 ; testLocaleID ( i ) ! = NULL ; i + + ) {
;
}
gLocaleCount = i ;
}
return gLocaleCount ;
}
static UDate doMinDateOfCalendar ( Calendar * adopt , UBool & isGregorian , UErrorCode & status ) {
if ( U_FAILURE ( status ) ) return 0.0 ;
adopt - > clear ( ) ;
adopt - > set ( UCAL_EXTENDED_YEAR , adopt - > getActualMinimum ( UCAL_EXTENDED_YEAR , status ) ) ;
UDate ret = adopt - > getTime ( status ) ;
isGregorian = ( adopt - > getDynamicClassID ( ) = = GregorianCalendar : : getStaticClassID ( ) ) ;
delete adopt ;
return ret ;
}
UDate CalendarTest : : minDateOfCalendar ( const Locale & locale , UBool & isGregorian , UErrorCode & status ) {
if ( U_FAILURE ( status ) ) return 0.0 ;
return doMinDateOfCalendar ( Calendar : : createInstance ( locale , status ) , isGregorian , status ) ;
}
UDate CalendarTest : : minDateOfCalendar ( const Calendar & cal , UBool & isGregorian , UErrorCode & status ) {
if ( U_FAILURE ( status ) ) return 0.0 ;
return doMinDateOfCalendar ( cal . clone ( ) , isGregorian , status ) ;
}
2009-03-20 19:06:29 +00:00
void CalendarTest : : Test6703 ( )
{
UErrorCode status = U_ZERO_ERROR ;
Calendar * cal ;
Locale loc1 ( " en@calendar=fubar " ) ;
cal = Calendar : : createInstance ( loc1 , status ) ;
if ( failure ( status , " Calendar::createInstance " ) ) return ;
delete cal ;
status = U_ZERO_ERROR ;
Locale loc2 ( " en " ) ;
cal = Calendar : : createInstance ( loc2 , status ) ;
if ( failure ( status , " Calendar::createInstance " ) ) return ;
delete cal ;
status = U_ZERO_ERROR ;
Locale loc3 ( " en@calendar=roc " ) ;
cal = Calendar : : createInstance ( loc3 , status ) ;
if ( failure ( status , " Calendar::createInstance " ) ) return ;
delete cal ;
2003-12-04 23:16:57 +00:00
2009-03-20 19:06:29 +00:00
return ;
}
2003-12-04 23:16:57 +00:00
2009-03-24 04:43:23 +00:00
void CalendarTest : : Test3785 ( )
{
UErrorCode status = U_ZERO_ERROR ;
UChar uzone [ ] = { ' E ' , ' u ' , ' r ' , ' o ' , ' p ' , ' e ' , ' / ' , ' P ' , ' a ' , ' r ' , ' i ' , ' s ' , 0 } ;
UDateFormat * df = udat_open ( UDAT_NONE , UDAT_NONE , " en@calendar=islamic " , uzone ,
u_strlen ( uzone ) , NULL , 0 , & status ) ;
if ( NULL = = df | | U_FAILURE ( status ) ) return ;
UChar upattern [ 64 ] ;
u_uastrcpy ( upattern , " EEE d MMMM y G, HH:mm:ss " ) ;
udat_applyPattern ( df , FALSE , upattern , u_strlen ( upattern ) ) ;
UChar ubuffer [ 1024 ] ;
UDate ud0 = 1337557623000.0 ;
status = U_ZERO_ERROR ;
udat_format ( df , ud0 , ubuffer , 1024 , NULL , & status ) ;
if ( U_FAILURE ( status ) ) return ;
//printf("formatted: '%s'\n", mkcstr(ubuffer));
ud0 + = 1000.0 ; // add one second
status = U_ZERO_ERROR ;
udat_format ( df , ud0 , ubuffer , 1024 , NULL , & status ) ;
if ( U_FAILURE ( status ) ) return ;
//printf("formatted: '%s'\n", mkcstr(ubuffer));
2009-04-02 20:29:06 +00:00
udat_close ( df ) ;
2009-03-24 04:43:23 +00:00
return ;
}
2007-07-12 21:53:20 +00:00
2002-09-21 00:43:14 +00:00
# endif /* #if !UCONFIG_NO_FORMATTING */
1999-08-16 21:50:52 +00:00
//eof