1
/********************************************************************
3
* Copyright (c) 1997-2001, International Business Machines Corporation and
4
* others. All Rights Reserved.
5
********************************************************************/
8
#include "unicode/calendar.h"
9
#include "unicode/gregocal.h"
10
#include "unicode/datefmt.h"
11
#include "unicode/smpdtfmt.h"
14
void CalendarLimitTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
16
if (exec) logln("TestSuite TestCalendarLimit");
18
// Re-enable this later
20
name = "TestCalendarLimit";
22
logln("TestCalendarLimit---"); logln("");
26
default: name = ""; break;
31
// *****************************************************************************
32
// class CalendarLimitTest
33
// *****************************************************************************
35
// -------------------------------------
37
CalendarLimitTest::test(UDate millis, U_NAMESPACE_QUALIFIER Calendar* cal, U_NAMESPACE_QUALIFIER DateFormat* fmt)
39
UErrorCode exception = U_ZERO_ERROR;
40
UnicodeString theDate;
41
UErrorCode status = U_ZERO_ERROR;
42
cal->setTime(millis, exception);
43
if (U_SUCCESS(exception)) {
44
fmt->format(millis, theDate);
45
UDate dt = fmt->parse(theDate, status);
46
// allow a small amount of error (drift)
47
if(! withinErr(dt, millis, 1e-10))
48
errln(UnicodeString("FAIL:round trip for large milli, got: ") + dt + " wanted: " + millis);
50
logln(UnicodeString("OK: got ") + dt + ", wanted " + millis);
51
logln(UnicodeString(" ") + theDate);
56
// -------------------------------------
58
// bug 986c: deprecate nextDouble/previousDouble
60
//|CalendarLimitTest::nextDouble(double a)
62
//| return uprv_nextDouble(a, TRUE);
66
//|CalendarLimitTest::previousDouble(double a)
68
//| return uprv_nextDouble(a, FALSE);
72
CalendarLimitTest::withinErr(double a, double b, double err)
74
return ( uprv_fabs(a - b) < uprv_fabs(a * err) );
78
CalendarLimitTest::TestCalendarLimit()
80
UErrorCode status = U_ZERO_ERROR;
81
Calendar *cal = Calendar::createInstance(status);
82
if (failure(status, "Calendar::createInstance")) return;
83
cal->adoptTimeZone(TimeZone::createTimeZone("GMT"));
84
DateFormat *fmt = DateFormat::createDateTimeInstance();
85
fmt->adoptCalendar(cal);
86
((SimpleDateFormat*) fmt)->applyPattern("HH:mm:ss.SSS zzz, EEEE, MMMM d, yyyy G");
88
// This test used to test the algorithmic limits of the dates that
89
// GregorianCalendar could handle. However, the algorithm has
90
// been rewritten completely since then and the prior limits no
91
// longer apply. Instead, we now do basic round-trip testing of
92
// some extreme (but still manageable) dates.
94
for ( m = 1e17; m < 1e18; m *= 1.1) {
97
for ( m = -1e14; m > -1e15; m *= 1.1) {
101
// This is 2^52 - 1, the largest allowable mantissa with a 0
102
// exponent in a 64-bit double
103
UDate VERY_EARLY_MILLIS = - 4503599627370495.0;
104
UDate VERY_LATE_MILLIS = 4503599627370495.0;
106
// I am removing the previousDouble and nextDouble calls below for
107
// two reasons: 1. As part of jitterbug 986, I am deprecating
108
// these methods and removing calls to them. 2. This test is a
109
// non-critical boundary behavior test.
110
test(VERY_EARLY_MILLIS, cal, fmt);
111
//test(previousDouble(VERY_EARLY_MILLIS), cal, fmt);
112
test(VERY_LATE_MILLIS, cal, fmt);
113
//test(nextDouble(VERY_LATE_MILLIS), cal, fmt);
117
// -------------------------------------