You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ba...@locus.apache.org on 2000/09/05 21:23:53 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon/processor/xsp/library/calendar XSPCalendar.java
balld 00/09/05 12:23:52
Modified: src/org/apache/cocoon/processor/xsp/library/calendar
XSPCalendar.java
Log:
Fixed a bug where there could be 5 weeks in a month if the first day
was a Sunday and added week_of_year and day_of_year. Also, since I
think that all things really should have a sample (esp something this easy)
I've knocked together a page which will display a years calendar from
the current month.
courtesy of john morrison.
Revision Changes Path
1.2 +8 -4 xml-cocoon/src/org/apache/cocoon/processor/xsp/library/calendar/XSPCalendar.java
Index: XSPCalendar.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/library/calendar/XSPCalendar.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XSPCalendar.java 2000/09/04 17:32:31 1.1
+++ XSPCalendar.java 2000/09/05 19:23:51 1.2
@@ -70,7 +70,7 @@
/** Generates a calendar of the form:
<pre>
<month number="3" name="March">
- <week number="1">
+ <week number="1" week_of_year="20">
<day/>
<day/>
<day/>
@@ -79,14 +79,14 @@
<day number="1" string="01 March 2000"/>
<day number="2" string="02 March 2000"/>
</week>
- <week number="2">
+ <week number="2" week_of_year="21">
<day number="3"/>
<day number="4"/>
<day number="5"/>
<day number="6"/>
<day number="7"/>
<day number="8"/>
- <day number="9"/>
+ <day number="9" day_of_year="100"/>
</week>
...
</month>
@@ -106,6 +106,8 @@
Element week_element = document.createElement("week");
int week_number = 1;
week_element.setAttribute("number","1");
+ int week_of_year_number = calendar.get(Calendar.WEEK_OF_YEAR);
+ week_element.setAttribute("week_of_year",""+week_of_year_number);
month_element.appendChild(week_element);
calendar.set(Calendar.DAY_OF_MONTH,1);
Calendar temp = (Calendar)calendar.clone();
@@ -115,14 +117,16 @@
}
temp.setTime(calendar.getTime());
while (temp.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)) {
- if (temp.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
+ if (temp.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY && temp.get(Calendar.DAY_OF_MONTH) != 1) {
week_number++;
week_element = document.createElement("week");
week_element.setAttribute("number",""+week_number);
+ week_element.setAttribute("week_of_year",""+(week_of_year_number + week_number));
month_element.appendChild(week_element);
}
Element day_element = document.createElement("day");
day_element.setAttribute("number",""+temp.get(Calendar.DAY_OF_MONTH));
+ day_element.setAttribute("day_of_year",""+temp.get(Calendar.DAY_OF_YEAR));
day_element.setAttribute("string",""+format.format(temp.getTime()));
week_element.appendChild(day_element);
temp.add(Calendar.DATE,1);