本文整理汇总了Java中java.util.GregorianCalendar.setGregorianChange方法的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar.setGregorianChange方法的具体用法?Java GregorianCalendar.setGregorianChange怎么用?Java GregorianCalendar.setGregorianChange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.setGregorianChange方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static void main(String[] args) {
for (int l = 0; l < locales.length; l++) {
Locale loc = locales[l];
for (int i = 0; i < offsets.length; i++) {
test(loc, offsets[i][0], offsets[i][1]);
}
}
// The test case in the bug report.
GregorianCalendar cal = new GregorianCalendar();
cal.setLenient(false);
cal.setGregorianChange(new Date(Long.MIN_VALUE));
cal.clear();
cal.set(ZONE_OFFSET, 0);
cal.set(DST_OFFSET, 0);
cal.set(ERA, AD);
cal.set(2004, FEBRUARY, 3, 0, 0, 0);
cal.set(MILLISECOND, 0);
// The following line should not throw an IllegalArgumentException.
cal.getTime();
}
示例2: TestGregorianChange768
import java.util.GregorianCalendar; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public void TestGregorianChange768() {
boolean b;
GregorianCalendar c = new GregorianCalendar();
logln("With cutoff " + c.getGregorianChange());
logln(" isLeapYear(1800) = " + (b = c.isLeapYear(1800)));
logln(" (should be FALSE)");
if (b != false) {
errln("FAIL");
}
c.setGregorianChange(new Date(0, 0, 1)); // Jan 1 1900
logln("With cutoff " + c.getGregorianChange());
logln(" isLeapYear(1800) = " + (b = c.isLeapYear(1800)));
logln(" (should be TRUE)");
if (b != true) {
errln("FAIL");
}
}
示例3: Test4136399
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* Calendar and GregorianCalendar hashCode() methods need improvement.
* Calendar needs a good implementation that subclasses can override,
* and GregorianCalendar should use that implementation.
*/
public void Test4136399() {
/* Note: This test is actually more strict than it has to be.
* Technically, there is no requirement that unequal objects have
* unequal hashes. We only require equal objects to have equal hashes.
* It is desirable for unequal objects to have distributed hashes, but
* there is no hard requirement here.
*
* In this test we make assumptions about certain attributes of calendar
* objects getting represented in the hash, which need not always be the
* case (although it does work currently with the given test). */
Calendar a = Calendar.getInstance();
Calendar b = (Calendar) a.clone();
if (a.hashCode() != b.hashCode()) {
errln("Calendar hash code unequal for cloned objects");
}
b.setMinimalDaysInFirstWeek(7 - a.getMinimalDaysInFirstWeek());
if (a.hashCode() == b.hashCode()) {
errln("Calendar hash code ignores minimal days in first week");
}
b.setMinimalDaysInFirstWeek(a.getMinimalDaysInFirstWeek());
b.setFirstDayOfWeek((a.getFirstDayOfWeek() % 7) + 1); // Next day
if (a.hashCode() == b.hashCode()) {
errln("Calendar hash code ignores first day of week");
}
b.setFirstDayOfWeek(a.getFirstDayOfWeek());
b.setLenient(!a.isLenient());
if (a.hashCode() == b.hashCode()) {
errln("Calendar hash code ignores lenient setting");
}
b.setLenient(a.isLenient());
// Assume getTimeZone() returns a reference, not a clone
// of a reference -- this is true as of this writing
b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset() + 60 * 60 * 1000);
if (a.hashCode() == b.hashCode()) {
errln("Calendar hash code ignores zone");
}
b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset());
GregorianCalendar c = new GregorianCalendar();
GregorianCalendar d = (GregorianCalendar) c.clone();
if (c.hashCode() != d.hashCode()) {
errln("GregorianCalendar hash code unequal for clones objects");
}
Date cutover = c.getGregorianChange();
d.setGregorianChange(new Date(cutover.getTime() + 24 * 60 * 60 * 1000));
if (c.hashCode() == d.hashCode()) {
errln("GregorianCalendar hash code ignores cutover");
}
}
示例4: Test4141665
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* GregorianCalendar.equals() ignores cutover date
*/
public void Test4141665() {
GregorianCalendar cal = new GregorianCalendar();
GregorianCalendar cal2 = (GregorianCalendar) cal.clone();
Date cut = cal.getGregorianChange();
Date cut2 = new Date(cut.getTime() + 100 * 24 * 60 * 60 * 1000L); // 100 days later
if (!cal.equals(cal2)) {
errln("Cloned GregorianCalendars not equal");
}
cal2.setGregorianChange(cut2);
if (cal.equals(cal2)) {
errln("GregorianCalendar.equals() ignores cutover");
}
}
示例5: Test4149677
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* Reported bug is that a GregorianCalendar with a cutover of Date(Long.MAX_VALUE)
* doesn't behave as a pure Julian calendar.
* CANNOT REPRODUCE THIS BUG
*/
public void Test4149677() {
TimeZone[] zones = {TimeZone.getTimeZone("GMT"),
TimeZone.getTimeZone("PST"),
TimeZone.getTimeZone("EAT")};
for (int i = 0; i < zones.length; ++i) {
GregorianCalendar calendar = new GregorianCalendar(zones[i]);
// Make sure extreme values don't wrap around
calendar.setTime(new Date(Long.MIN_VALUE));
if (calendar.get(ERA) != GregorianCalendar.BC) {
errln("Fail: Date(Long.MIN_VALUE) has an AD year in " + zones[i]);
}
calendar.setTime(new Date(Long.MAX_VALUE));
if (calendar.get(ERA) != GregorianCalendar.AD) {
errln("Fail: Date(Long.MAX_VALUE) has a BC year in " + zones[i]);
}
calendar.setGregorianChange(new Date(Long.MAX_VALUE));
// to obtain a pure Julian calendar
boolean is100Leap = calendar.isLeapYear(100);
if (!is100Leap) {
errln("test failed with zone " + zones[i].getID());
errln(" cutover date is Date(Long.MAX_VALUE)");
errln(" isLeapYear(100) returns: " + is100Leap);
}
}
}
示例6: getGregorianDate
import java.util.GregorianCalendar; //导入方法依赖的package包/类
static Date getGregorianDate(int year, int month, int dayOfMonth) {
GregorianCalendar g = new GregorianCalendar();
// Make g a pure Gregorian calendar
g.setGregorianChange(new Date(Long.MIN_VALUE));
g.clear();
g.set(year, month, dayOfMonth);
return g.getTime();
}
示例7: Test4167060
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* Calendar.getActualMaximum(YEAR) works wrong.
*
* Note: Before 1.5, this test case assumed that
* setGregorianChange didn't change object's date. But it was
* changed. See 4928615.
*/
public void Test4167060() {
int field = YEAR;
DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy G",
Locale.US);
int[][] dates = {
// year, month, day of month
{100, NOVEMBER, 1},
{-99 /*100BC*/, JANUARY, 1},
{1996, FEBRUARY, 29}};
String[] id = {"Hybrid", "Gregorian", "Julian"};
for (int k = 0; k < 3; ++k) {
logln("--- " + id[k] + " ---");
for (int j = 0; j < dates.length; ++j) {
GregorianCalendar calendar = new GregorianCalendar();
if (k == 1) {
calendar.setGregorianChange(new Date(Long.MIN_VALUE));
} else if (k == 2) {
calendar.setGregorianChange(new Date(Long.MAX_VALUE));
}
calendar.set(dates[j][0], dates[j][1], dates[j][2]);
format.setCalendar((Calendar) calendar.clone());
Date dateBefore = calendar.getTime();
int maxYear = calendar.getActualMaximum(field);
logln("maxYear: " + maxYear + " for " + format.format(calendar.getTime()));
logln("date before: " + format.format(dateBefore));
int[] years = {2000, maxYear - 1, maxYear, maxYear + 1};
for (int i = 0; i < years.length; i++) {
boolean valid = years[i] <= maxYear;
calendar.set(field, years[i]);
Date dateAfter = calendar.getTime();
int newYear = calendar.get(field);
calendar.setTime(dateBefore); // restore calendar for next use
logln(" Year " + years[i] + (valid ? " ok " : " bad")
+ " => " + format.format(dateAfter));
if (valid && newYear != years[i]) {
errln(" FAIL: " + newYear + " should be valid; date, month and time shouldn't change");
} else if (!valid && newYear == years[i]) {
errln(" FAIL: " + newYear + " should be invalid");
}
}
}
}
}