classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A little problem with Date.getDate()


From: Wu, Gansha
Subject: A little problem with Date.getDate()
Date: Tue, 31 Jul 2001 08:56:16 +0800

This is the fourth of the series.

Date.getDate() will return 7 when today is Sunday, it's semantically wrong 
according to Java library documentation. It should return 0.

        The DAY_OF_WEEK value is set in GregorianCalendar:

                private void calculateDay(int day, boolean gregorian)
                {
                    // the epoch is a Thursday.
                    int weekday = (day + THURSDAY) % 7;
                    if (weekday <= 0)    <- notice here. 
                        weekday += 7;     <- notice here.
                    fields[DAY_OF_WEEK] = weekday;
                    ... ...
                }

But there seems to be problems to change in GregorianCalendar.java, so I made
 a patch in Date.java:
                -   return cal.get(Calendar.DAY_OF_WEEK);
                +  int day = cal.get(Calendar.DAY_OF_WEEK);
                +  return day == 7?0:day;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]