3Wheels
02-01-2002, 03:11 PM
Hi All,
I've been running a Java scheduler application for several years, but ran into a problem this morning with the Calendar object. I use the after() method to determine if schedule entries are old. If they are older than today, I delete the entries. Today, Calendar seems to think 1/29/2002, 1/30/2002 and 1/31/2002 all come AFTER 2/1/2002. However, it correctly understands that 1/28/2002 comes BEFORE 2/1/2002.
Below is a code sample. I wonder if anyone can explain what I'm seeing. Any info is appreciated.
import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
import java.lang.*;
// Here is the output of this program under jdk1.2.2:
//
// 2/1/2002 DOES NOT come after 1/31/2002??? BAD
// 2/1/2002 DOES NOT come after 1/30/2002??? BAD
// 2/1/2002 DOES NOT come after 1/29/2002??? BAD
// 2/1/2002 comes after 1/28/2002, good
//
public class BuggyCalendar {
public static void main (String[] args) {
Calendar calendar = Calendar.getInstance(); // For today, 2/2
Calendar calendar2 = Calendar.getInstance(); // For yesterday 1/31
Calendar calendar3 = Calendar.getInstance(); // 1/30
Calendar calendar4 = Calendar.getInstance(); // 1/29
Calendar calendar5 = Calendar.getInstance(); // 1/28
// Year: 2002 for all 5 dates
Integer Iyy = new Integer("2002");
// Month for today is "02", February
Integer Ifeb = new Integer("02");
// Month for all other dates is "01", January
Integer Ijan = new Integer("01");
// Today 2-1-2002
Integer Idd = new Integer("01");
// Yesterday 1-31-2002
Integer Idd2 = new Integer("31");
// Wednesday 1-30-2002
Integer Idd3 = new Integer("30");
// Tuesday 1-29-2002
Integer Idd4 = new Integer("29");
// Monday 1-28-2002
Integer Idd5 = new Integer("28");
// Calendar object to hold today's date: 2-1-2002
calendar.set(Iyy.intValue(), Ifeb.intValue(), Idd.intValue());
// Calendar object to hold yesterday, 1-31-2002
calendar2.set(Iyy.intValue(), Ijan.intValue(), Idd2.intValue());
// Calendar object to hold 1-30-2002
calendar3.set(Iyy.intValue(), Ijan.intValue(), Idd3.intValue());
// Calendar object to hold 1-29-2002
calendar4.set(Iyy.intValue(), Ijan.intValue(), Idd4.intValue());
// Calendar object to hold 1-28-2002
calendar5.set(Iyy.intValue(), Ijan.intValue(), Idd5.intValue());
if ( calendar.after(calendar2) ) {
System.out.println("2/1/2002 comes after 1/31/2002, good");
}
else {
System.out.println("2/1/2002 DOES NOT come after 1/31/2002??? BAD");
}
if ( calendar.after(calendar3) ) {
System.out.println("2/1/2002 comes after 1/30/2002, good");
}
else {
System.out.println("2/1/2002 DOES NOT come after 1/30/2002??? BAD");
}
if ( calendar.after(calendar4) ) {
System.out.println("2/1/2002 comes after 1/29/2002, good");
}
else {
System.out.println("2/1/2002 DOES NOT come after 1/29/2002??? BAD");
}
if ( calendar.after(calendar5) ) {
System.out.println("2/1/2002 comes after 1/28/2002, good");
}
else {
System.out.println("2/1/2002 DOES NOT come after 1/28/2002??? BAD");
}
}
}
I've been running a Java scheduler application for several years, but ran into a problem this morning with the Calendar object. I use the after() method to determine if schedule entries are old. If they are older than today, I delete the entries. Today, Calendar seems to think 1/29/2002, 1/30/2002 and 1/31/2002 all come AFTER 2/1/2002. However, it correctly understands that 1/28/2002 comes BEFORE 2/1/2002.
Below is a code sample. I wonder if anyone can explain what I'm seeing. Any info is appreciated.
import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
import java.lang.*;
// Here is the output of this program under jdk1.2.2:
//
// 2/1/2002 DOES NOT come after 1/31/2002??? BAD
// 2/1/2002 DOES NOT come after 1/30/2002??? BAD
// 2/1/2002 DOES NOT come after 1/29/2002??? BAD
// 2/1/2002 comes after 1/28/2002, good
//
public class BuggyCalendar {
public static void main (String[] args) {
Calendar calendar = Calendar.getInstance(); // For today, 2/2
Calendar calendar2 = Calendar.getInstance(); // For yesterday 1/31
Calendar calendar3 = Calendar.getInstance(); // 1/30
Calendar calendar4 = Calendar.getInstance(); // 1/29
Calendar calendar5 = Calendar.getInstance(); // 1/28
// Year: 2002 for all 5 dates
Integer Iyy = new Integer("2002");
// Month for today is "02", February
Integer Ifeb = new Integer("02");
// Month for all other dates is "01", January
Integer Ijan = new Integer("01");
// Today 2-1-2002
Integer Idd = new Integer("01");
// Yesterday 1-31-2002
Integer Idd2 = new Integer("31");
// Wednesday 1-30-2002
Integer Idd3 = new Integer("30");
// Tuesday 1-29-2002
Integer Idd4 = new Integer("29");
// Monday 1-28-2002
Integer Idd5 = new Integer("28");
// Calendar object to hold today's date: 2-1-2002
calendar.set(Iyy.intValue(), Ifeb.intValue(), Idd.intValue());
// Calendar object to hold yesterday, 1-31-2002
calendar2.set(Iyy.intValue(), Ijan.intValue(), Idd2.intValue());
// Calendar object to hold 1-30-2002
calendar3.set(Iyy.intValue(), Ijan.intValue(), Idd3.intValue());
// Calendar object to hold 1-29-2002
calendar4.set(Iyy.intValue(), Ijan.intValue(), Idd4.intValue());
// Calendar object to hold 1-28-2002
calendar5.set(Iyy.intValue(), Ijan.intValue(), Idd5.intValue());
if ( calendar.after(calendar2) ) {
System.out.println("2/1/2002 comes after 1/31/2002, good");
}
else {
System.out.println("2/1/2002 DOES NOT come after 1/31/2002??? BAD");
}
if ( calendar.after(calendar3) ) {
System.out.println("2/1/2002 comes after 1/30/2002, good");
}
else {
System.out.println("2/1/2002 DOES NOT come after 1/30/2002??? BAD");
}
if ( calendar.after(calendar4) ) {
System.out.println("2/1/2002 comes after 1/29/2002, good");
}
else {
System.out.println("2/1/2002 DOES NOT come after 1/29/2002??? BAD");
}
if ( calendar.after(calendar5) ) {
System.out.println("2/1/2002 comes after 1/28/2002, good");
}
else {
System.out.println("2/1/2002 DOES NOT come after 1/28/2002??? BAD");
}
}
}