You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by pm...@apache.org on 2007/06/21 15:08:51 UTC
svn commit: r549463 - in
/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule:
./ model/ util/
Author: pmahoney
Date: Thu Jun 21 06:08:49 2007
New Revision: 549463
URL: http://svn.apache.org/viewvc?view=rev&rev=549463
Log:
TOMAHAWK-811: Add timezone support to the schedule component. Thanks to Eduard Martinescu for the original patch.
Modified:
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/AbstractScheduleModel.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java Thu Jun 21 06:08:49 2007
@@ -19,6 +19,17 @@
package org.apache.myfaces.custom.schedule;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.TreeSet;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.custom.schedule.model.ScheduleDay;
@@ -28,13 +39,6 @@
import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.*;
-
/**
* <p>
* Abstract superclass for the week and month view renderers.
@@ -112,11 +116,10 @@
boolean isCurrentMonth, int rowspan) throws IOException
{
final String clientId = schedule.getClientId(context);
- final Map attributes = schedule.getAttributes();
final FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
final String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();
- final String dayHeaderId = clientId + "_header_" + ScheduleUtil.getDateId(day.getDate());
- final String dayBodyId = clientId + "_body_" + ScheduleUtil.getDateId(day.getDate());
+ final String dayHeaderId = clientId + "_header_" + ScheduleUtil.getDateId(day.getDate(), schedule.getModel().getTimeZone());
+ final String dayBodyId = clientId + "_body_" + ScheduleUtil.getDateId(day.getDate(), schedule.getModel().getTimeZone());
writer.startElement(HTML.TD_ELEM, schedule);
writer.writeAttribute("rowspan", String.valueOf(rowspan), null);
@@ -226,7 +229,7 @@
null);
writer.writeAttribute(HTML.ID_ATTR, dayBodyId, null);
-
+
//register an onclick event listener to a day cell which will capture
//the date
if (!schedule.isReadonly() && schedule.isSubmitOnClick()) {
@@ -365,12 +368,11 @@
* into account when determining the last clicked date.
*/
protected Date determineLastClickedDate(HtmlSchedule schedule, String dateId, String yPos) {
- Calendar cal = GregorianCalendar.getInstance();
- //the dateId is the schedule client id + "_" + yyyyMMdd
+ //the dateId is the schedule client id + "_" + yyyyMMdd
String day = dateId.substring(dateId.lastIndexOf("_") + 1);
- Date date = ScheduleUtil.getDateFromId(day);
+ Date date = ScheduleUtil.getDateFromId(day, schedule.getModel().getTimeZone());
- if (date != null) cal.setTime(date);
+ Calendar cal = getCalendarInstance(schedule, date != null ? date : new Date());
cal.set(Calendar.HOUR_OF_DAY, schedule.getVisibleStartHour());
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java Thu Jun 21 06:08:49 2007
@@ -36,6 +36,7 @@
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
@@ -211,22 +212,22 @@
protected String getDateString(FacesContext context, UIScheduleBase schedule,
Date date)
{
- DateFormat format;
- String pattern = schedule.getHeaderDateFormat();
- Locale viewLocale = context.getViewRoot().getLocale();
-
- if ((pattern != null) && (pattern.length() > 0))
- {
- format = new SimpleDateFormat(pattern, viewLocale);
- }
- else
- {
- format = DateFormat.getDateInstance(DateFormat.MEDIUM, viewLocale);
- }
- return format.format(date);
+ return getDateFormat(context, schedule, schedule.getHeaderDateFormat()).format(date);
}
+ protected static DateFormat getDateFormat(FacesContext context, UIScheduleBase schedule, String pattern)
+ {
+ Locale viewLocale = context.getViewRoot().getLocale();
+ DateFormat format = (pattern != null && pattern.length() > 0) ?
+ new SimpleDateFormat(pattern, viewLocale) :
+ DateFormat.getDateInstance(DateFormat.MEDIUM, viewLocale);
+
+ format.setTimeZone(schedule.getModel().getTimeZone());
+
+ return format;
+ }
+
/**
* <p>
* Allow the developer to specify custom CSS classnames for the schedule
@@ -306,6 +307,11 @@
public boolean getRendersChildren()
{
return true;
+ }
+
+ protected Calendar getCalendarInstance(HtmlSchedule schedule, Date date)
+ {
+ return ScheduleUtil.getCalendarInstance(date, schedule.getModel().getTimeZone());
}
}
//The End
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java Thu Jun 21 06:08:49 2007
@@ -21,7 +21,7 @@
import java.io.IOException;
import java.io.Serializable;
-import java.text.SimpleDateFormat;
+import java.text.DateFormat;
import java.util.Date;
import java.util.Map;
@@ -106,8 +106,9 @@
if (!entry.isAllDay())
{
- SimpleDateFormat format = new SimpleDateFormat(HtmlSchedule.HOUR_NOTATION_24.equals(schedule.getHourNotation()) ? "HH:mm" : "h:mma");
-
+ DateFormat format = AbstractScheduleRenderer.getDateFormat(context, schedule,
+ HtmlSchedule.HOUR_NOTATION_24.equals(schedule.getHourNotation()) ? "HH:mm" : "h:mma");
+
text.append(format.format(startTime));
if (!startTime.equals(endTime)) {
text.append("-");
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java Thu Jun 21 06:08:49 2007
@@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.Calendar;
-import java.util.GregorianCalendar;
import java.util.Iterator;
import javax.faces.component.UIComponent;
@@ -90,8 +89,7 @@
writer.writeAttribute(HTML.WIDTH_ATTR, "100%", null);
writer.startElement(HTML.TBODY_ELEM, schedule);
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(schedule.getModel().getSelectedDate());
+ Calendar cal = getCalendarInstance(schedule, schedule.getModel().getSelectedDate());
int selectedMonth = cal.get(Calendar.MONTH);
for (
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java Thu Jun 21 06:08:49 2007
@@ -29,7 +29,6 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.Calendar;
-import java.util.GregorianCalendar;
import java.util.Iterator;
@@ -88,14 +87,12 @@
writer.writeAttribute(HTML.WIDTH_ATTR, "100%", null);
writer.startElement(HTML.TBODY_ELEM, schedule);
- Calendar cal = GregorianCalendar.getInstance();
-
for (
Iterator dayIterator = schedule.getModel().iterator();
dayIterator.hasNext();
) {
ScheduleDay day = (ScheduleDay) dayIterator.next();
- cal.setTime(day.getDate());
+ Calendar cal = getCalendarInstance(schedule, day.getDate());
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java Thu Jun 21 06:08:49 2007
@@ -21,11 +21,11 @@
import java.io.IOException;
import java.io.Serializable;
-import java.text.SimpleDateFormat;
+import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
import java.util.Iterator;
+import java.util.TimeZone;
import java.util.TreeSet;
import javax.faces.component.UIComponent;
@@ -122,7 +122,7 @@
.hasNext();)
{
ScheduleDay day = (ScheduleDay) dayIterator.next();
- String dayBodyId = clientId + "_body_" + ScheduleUtil.getDateId(day.getDate());
+ String dayBodyId = clientId + "_body_" + ScheduleUtil.getDateId(day.getDate(), schedule.getModel().getTimeZone());
writer.startElement(HTML.TD_ELEM, schedule);
writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
"column"), null);
@@ -282,8 +282,8 @@
int startHour = getRenderedStartHour(schedule);
int endHour = getRenderedEndHour(schedule);
- SimpleDateFormat hourFormater = new SimpleDateFormat(HtmlSchedule.HOUR_NOTATION_12.equals(schedule.getHourNotation()) ? "hh" : "HH");
- SimpleDateFormat minuteFormater = new SimpleDateFormat("mm");
+ DateFormat hourFormater = getDateFormat(context, schedule, HtmlSchedule.HOUR_NOTATION_12.equals(schedule.getHourNotation()) ? "hh" : "HH");
+ DateFormat minuteFormater = getDateFormat(context, schedule, "mm");
// When firstDay is true, render the gutter
boolean firstDay = true;
@@ -413,7 +413,7 @@
{
int gutterHeight = intervalHeight;
- if (day.getIntervals() == null && interval.getStartMinutes() == 0)
+ if (day.getIntervals() == null && interval.getStartMinutes(getTimeZone(schedule)) == 0)
{
gutterHeight = (gutterHeight * 2) + 1;
renderGutter = false;
@@ -455,7 +455,7 @@
{
writer.startElement(HTML.TD_ELEM, schedule);
writer.writeAttribute(HTML.CLASS_ATTR, getCellClass(schedule,
- day, renderGutter, interval.getStartHours()), null);
+ day, renderGutter, interval.getStartHours(getTimeZone(schedule))), null);
writer.writeAttribute(HTML.STYLE_ATTR,
"overflow: hidden; height: " + intervalHeight + "px;", null);
if (interval.getLabel() != null)
@@ -703,7 +703,7 @@
.hasNext();)
{
ScheduleDay day = (ScheduleDay) dayIterator.next();
- final String dayHeaderId = clientId + "_header_" + ScheduleUtil.getDateId(day.getDate());
+ final String dayHeaderId = clientId + "_header_" + ScheduleUtil.getDateId(day.getDate(), schedule.getModel().getTimeZone());
writer.startElement(HTML.TD_ELEM, schedule);
writer.writeAttribute(HTML.ID_ATTR, dayHeaderId, null);
writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
@@ -754,12 +754,11 @@
* into account when determining the last clicked date.
*/
protected Date determineLastClickedDate(HtmlSchedule schedule, String dateId, String yPos) {
- Calendar cal = GregorianCalendar.getInstance();
- //the dateId is the schedule client id + "_" + yyyyMMdd
+ //the dateId is the schedule client id + "_" + yyyyMMdd
String day = dateId.substring(dateId.lastIndexOf("_") + 1);
- Date date = ScheduleUtil.getDateFromId(day);
+ Date date = ScheduleUtil.getDateFromId(day, schedule.getModel().getTimeZone());
- if (date != null) cal.setTime(date);
+ Calendar cal = getCalendarInstance(schedule, date != null ? date : new Date());
cal.set(Calendar.HOUR_OF_DAY, getRenderedStartHour(schedule));
//OK, we have the date, let's determine the time
try {
@@ -796,9 +795,9 @@
/**
* <p>
* When the start- and endtime of an entry are the same, should the entry
- * be rendered, fitting the entry box to the text?
+ * be rendered, fitting the entry box to the text?
* </p>
- *
+ *
* @param component the component
* @return whether or not zero length entries should be rendered
*/
@@ -901,8 +900,7 @@
int rowHeight = getRowHeight(schedule);
float width = (columnWidth * colspan) - 0.5f;
float left = column * columnWidth;
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(day.getDate());
+ Calendar cal = getCalendarInstance(schedule, day.getDate());
int curyear = cal.get(Calendar.YEAR);
int curmonth = cal.get(Calendar.MONTH);
@@ -1049,6 +1047,14 @@
return height <= 0 ? getDefaultRowHeight() : height;
}
return getDefaultRowHeight();
+ }
+
+ private TimeZone getTimeZone(UIScheduleBase schedule)
+ {
+
+ return schedule != null && schedule.getModel().getTimeZone() != null ?
+ schedule.getModel().getTimeZone()
+ : TimeZone.getDefault();
}
}
//The End
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/AbstractScheduleModel.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/AbstractScheduleModel.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/AbstractScheduleModel.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/AbstractScheduleModel.java Thu Jun 21 06:08:49 2007
@@ -23,10 +23,12 @@
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
-import java.util.GregorianCalendar;
import java.util.Iterator;
+import java.util.TimeZone;
import java.util.TreeSet;
+import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
+
/**
* <p>
* Extend this class to create your own implementation of a ScheduleModel
@@ -49,6 +51,8 @@
private int mode;
+ protected final TimeZone timeZone;
+
// ~ Constructors
// -----------------------------------------------------------
@@ -57,13 +61,26 @@
*/
public AbstractScheduleModel()
{
- this.days = new TreeSet();
+ this(TimeZone.getDefault());
+ }
+
+ public AbstractScheduleModel(TimeZone timeZone)
+ {
+ this.days = new TreeSet();
+ this.timeZone = timeZone;
}
// ~ Methods
// ----------------------------------------------------------------
/**
+ * Returns the timezone setting for this model
+ */
+ public TimeZone getTimeZone () {
+ return this.timeZone;
+ }
+
+ /**
* @see org.apache.myfaces.custom.schedule.model.ScheduleModel#isEmpty()
*/
public boolean isEmpty()
@@ -242,9 +259,7 @@
clear();
- Calendar cal = GregorianCalendar.getInstance();
- cal.setFirstDayOfWeek(Calendar.MONDAY);
- cal.setTime(date);
+ Calendar cal = getCalendarInstance(date);
// go back to the first day of the month;
cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DAY_OF_MONTH));
@@ -299,8 +314,7 @@
clear();
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(date);
+ Calendar cal = getCalendarInstance(date);
// go back to the monday of this week
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
@@ -341,8 +355,7 @@
clear();
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(date);
+ Calendar cal = getCalendarInstance(date);
// go back to the monday of this week
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
@@ -383,7 +396,7 @@
return null;
}
- ScheduleDay day = new ScheduleDay(date);
+ ScheduleDay day = new ScheduleDay(date, getTimeZone());
loadDayAttributes(day);
days.add(day);
@@ -454,6 +467,11 @@
day.addEntry(entry);
}
}
+ }
+
+ protected Calendar getCalendarInstance(Date date) {
+
+ return ScheduleUtil.getCalendarInstance(date, getTimeZone());
}
}
// The End
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java Thu Jun 21 06:08:49 2007
@@ -25,7 +25,7 @@
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
-import java.util.GregorianCalendar;
+import java.util.TimeZone;
import java.util.TreeSet;
import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
@@ -54,6 +54,7 @@
private String specialDayName;
private boolean workingDay;
private TreeSet intervals;
+ private final TimeZone timeZone;
//~ Constructors -----------------------------------------------------------
@@ -66,15 +67,26 @@
*/
public Day(Date date)
{
- super();
+ this(date, TimeZone.getDefault());
+ }
+
+ /**
+ * Creates a new Day object.
+ *
+ * @param date the date
+ * @param timeZone The timezone
+ *
+ * @throws NullPointerException when the date is null
+ */
+ public Day(Date date, TimeZone timeZone)
+ {
this.date = date;
+ this.timeZone = timeZone;
if (date == null) {
throw new NullPointerException("date should not be null");
}
-
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(date);
+ Calendar cal = getCalendarInstance(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
@@ -83,9 +95,14 @@
cal.add(Calendar.DATE, 1);
this.dayEnd = cal.getTime();
}
-
+
//~ Methods ----------------------------------------------------------------
+ protected Calendar getCalendarInstance(Date date) {
+
+ return ScheduleUtil.getCalendarInstance(date, timeZone);
+ }
+
/**
* @return Returns the date.
*/
@@ -155,8 +172,7 @@
*/
public boolean isWorkingDay()
{
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(date);
+ Calendar cal = getCalendarInstance(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
@@ -171,7 +187,8 @@
*
* @return A chronologically ordered set of intervals.
*/
- public TreeSet getIntervals() {
+ public TreeSet getIntervals()
+ {
return intervals;
}
@@ -209,7 +226,7 @@
if (o instanceof Day) {
Day other = (Day) o;
- int returnint = ScheduleUtil.compareDays(date, other.getDate());
+ int returnint = ScheduleUtil.compareDays(date, other.getDate(), timeZone);
return returnint;
}
@@ -225,7 +242,7 @@
if (o instanceof Day) {
Day other = (Day) o;
- return ScheduleUtil.isSameDay(date, other.getDate());
+ return ScheduleUtil.isSameDay(date, other.getDate(), timeZone);
}
return false;
@@ -246,7 +263,7 @@
return false;
}
- return ScheduleUtil.isSameDay(date, this.date);
+ return ScheduleUtil.isSameDay(date, this.date, timeZone);
}
/**
@@ -254,7 +271,7 @@
*/
public int hashCode()
{
- return ScheduleUtil.getHashCodeForDay(date);
+ return ScheduleUtil.getHashCodeForDay(date, timeZone);
}
}
//The End
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java Thu Jun 21 06:08:49 2007
@@ -23,7 +23,7 @@
import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
+import java.util.TimeZone;
import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
@@ -52,10 +52,28 @@
private String subtitle;
private String title;
private boolean allDay;
+ private TimeZone timeZone;
//~ Methods ----------------------------------------------------------------
/**
+ * @return the current timezone
+ */
+ public TimeZone getTimeZone ()
+ {
+ return this.timeZone;
+ }
+
+ /**
+ * Set current timezone
+ * @param timeZone the timezone
+ */
+ public void setTimeZone (TimeZone timeZone)
+ {
+ this.timeZone = timeZone;
+ }
+
+ /**
* @param description The description to set.
*/
public void setDescription(String description)
@@ -84,18 +102,17 @@
*/
public Date getEndTime()
{
- if (endTime == null) endTime = new Date();
- if (isAllDay()) {
- Calendar cal = GregorianCalendar.getInstance();
- Date truncated = ScheduleUtil.truncate(endTime);
- cal.setTime(truncated);
- cal.add(Calendar.MILLISECOND, -1);
- truncated = cal.getTime();
- if (!truncated.equals(endTime)) {
- cal.add(Calendar.DATE, 1);
- }
- return cal.getTime();
- }
+ if (endTime == null) endTime = new Date();
+ if (isAllDay()) {
+ Date truncated = ScheduleUtil.truncate(endTime, getTimeZone());
+ Calendar cal = ScheduleUtil.getCalendarInstance(truncated, getTimeZone());
+ cal.add(Calendar.MILLISECOND, -1);
+ truncated = cal.getTime();
+ if (!truncated.equals(endTime)) {
+ cal.add(Calendar.DATE, 1);
+ }
+ return cal.getTime();
+ }
return endTime;
}
@@ -128,12 +145,12 @@
*/
public Date getStartTime()
{
- if (startTime == null) startTime = new Date();
- if (isAllDay()) {
- return ScheduleUtil.truncate(startTime);
- } else {
+ if (startTime == null) startTime = new Date();
+ if (isAllDay()) {
+ return ScheduleUtil.truncate(startTime, getTimeZone());
+ } else {
return startTime;
- }
+ }
}
/**
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java Thu Jun 21 06:08:49 2007
@@ -22,7 +22,9 @@
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
/**
* <p>
@@ -96,19 +98,16 @@
return !startTime.before(last.getEndTime());
}
- public int getStartHours()
+ public int getStartHours(TimeZone timeZone)
{
- Calendar calendar = GregorianCalendar.getInstance();
- calendar.setTime(getStartTime());
- return calendar.get(Calendar.HOUR_OF_DAY);
+ return ScheduleUtil.getCalendarInstance(getStartTime(), timeZone).get(Calendar.HOUR_OF_DAY);
}
- public int getStartMinutes() {
- Calendar calendar = GregorianCalendar.getInstance();
- calendar.setTime(getStartTime());
+ public int getStartMinutes(TimeZone timeZone)
+ {
- return calendar.get(Calendar.MINUTE);
+ return ScheduleUtil.getCalendarInstance(getStartTime(), timeZone).get(Calendar.MINUTE);
}
public long getDuration()
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java Thu Jun 21 06:08:49 2007
@@ -25,9 +25,9 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
+import java.util.TimeZone;
import java.util.TreeSet;
import org.apache.myfaces.custom.schedule.util.ScheduleEntryComparator;
@@ -62,7 +62,17 @@
*/
public ScheduleDay(Date date)
{
- super(date);
+ this(date, TimeZone.getDefault());
+ }
+
+ /**
+ * Creates a new ScheduleDay object.
+ *
+ * @param date the date
+ */
+ public ScheduleDay(Date date, TimeZone tz)
+ {
+ super(date, tz);
this.entries = new TreeSet(new ScheduleEntryComparator());
}
@@ -94,8 +104,7 @@
return false;
}
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(entry.getEndTime());
+ Calendar cal = getCalendarInstance(entry.getEndTime());
cal.add(Calendar.DATE, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
@@ -166,8 +175,6 @@
*/
public int getLastEventHour()
{
- Calendar endTime = GregorianCalendar.getInstance();
-
// Check all events, as the last to finish may not be the last to begin
Date lastEnd = null;
@@ -183,7 +190,7 @@
return 0;
}
- endTime.setTime(lastEnd);
+ Calendar endTime = getCalendarInstance(lastEnd);
if (endTime.get(Calendar.MINUTE) > 0){
// Round up to next hour
@@ -207,8 +214,7 @@
ScheduleEntry next = (ScheduleEntry) it.next();
if (!next.isAllDay()) {
- startTime = GregorianCalendar.getInstance();
- startTime.setTime(next.getStartTime());
+ startTime = getCalendarInstance(next.getStartTime());
break;
}
}
@@ -323,8 +329,7 @@
}
private Date initDate(Date date, int hour) {
- Calendar calendar = GregorianCalendar.getInstance();
- calendar.setTime(date);
+ Calendar calendar = getCalendarInstance(date);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java Thu Jun 21 06:08:49 2007
@@ -21,6 +21,7 @@
import java.util.Date;
import java.util.Iterator;
+import java.util.TimeZone;
/**
@@ -140,5 +141,10 @@
* Reload the entries for the currently selected period
*/
public abstract void refresh();
+
+ /**
+ * @return The timezone for which the model should be built
+ */
+ public abstract TimeZone getTimeZone();
}
//The End
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java?view=diff&rev=549463&r1=549462&r2=549463
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java Thu Jun 21 06:08:49 2007
@@ -24,6 +24,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.TimeZone;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -43,7 +44,7 @@
public class ScheduleUtil
{
//~ Class Variables --------------------------------------------------------
- private final static SimpleDateFormat DATE_ID_FORMATTER = new SimpleDateFormat("yyyyMMdd");
+ private final static String DATE_ID_PATTERN = "yyyyMMdd";
//~ Constructors -----------------------------------------------------------
/**
@@ -190,14 +191,13 @@
*
* @return the hashCode of the truncated date
*/
- public static int getHashCodeForDay(Date date)
+ public static int getHashCodeForDay(Date date,TimeZone tz)
{
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
-
- return new Integer(calendar.get(Calendar.ERA)).hashCode() ^
- new Integer(calendar.get(Calendar.YEAR)).hashCode() ^
- new Integer(calendar.get(Calendar.DAY_OF_YEAR)).hashCode();
+ Calendar calendar = getCalendarInstance(date, tz);
+
+ return new Integer(calendar.get(Calendar.ERA)).hashCode() ^
+ new Integer(calendar.get(Calendar.YEAR)).hashCode() ^
+ new Integer(calendar.get(Calendar.DAY_OF_YEAR)).hashCode();
}
/**
@@ -287,22 +287,20 @@
*/
public static boolean isSameDay(
Date date1,
- Date date2
+ Date date2,
+ TimeZone tz
)
{
if ((date1 == null) || (date2 == null)) {
return false;
}
-
- Calendar calendar1 = Calendar.getInstance();
- calendar1.setTime(date1);
-
- Calendar calendar2 = Calendar.getInstance();
- calendar2.setTime(date2);
-
+
+ Calendar calendar1 = getCalendarInstance(date1, tz);
+ Calendar calendar2 = getCalendarInstance(date2, tz);
+
return (calendar1.get(Calendar.ERA) == calendar2.get(Calendar.ERA) &&
- calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) &&
- calendar1.get(Calendar.DAY_OF_YEAR) == calendar2.get(Calendar.DAY_OF_YEAR));
+ calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) &&
+ calendar1.get(Calendar.DAY_OF_YEAR) == calendar2.get(Calendar.DAY_OF_YEAR));
}
/**
@@ -372,7 +370,8 @@
*/
public static int compareDays(
Date date1,
- Date date2
+ Date date2,
+ TimeZone tz
)
{
if (date1 == null) {
@@ -382,20 +381,20 @@
if (date2 == null) {
return 1;
}
-
- return truncate(date1).compareTo(truncate(date2));
+
+ return truncate(date1,tz).compareTo(truncate(date2,tz));
}
-
+
/**
* truncate the given Date to 00:00:00 that same day
- *
+ *
* @param date the date that should be truncated
* @return the truncated date
*/
- public static Date truncate(Date date) {
+ public static Date truncate(Date date, TimeZone tz)
+ {
if (date == null) return null;
- Calendar cal = GregorianCalendar.getInstance();
- cal.setTime(date);
+ Calendar cal = getCalendarInstance(date, tz);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
@@ -409,9 +408,10 @@
* @param date the date
* @return the identifier for this date
*/
- public static String getDateId(Date date) {
+ public static String getDateId(Date date, TimeZone timeZone)
+ {
if (date == null) return "NULL";
- return DATE_ID_FORMATTER.format(date);
+ return getDateIdFormater(timeZone).format(date);
}
/**
@@ -420,16 +420,36 @@
* @param id the date ID
* @return the date
*/
- public static Date getDateFromId(String id) {
+ public static Date getDateFromId(String id, TimeZone timeZone)
+ {
if (id == null || id.length() == 0 || "null".equals(id)) return null;
try
{
- return DATE_ID_FORMATTER.parse(id);
+ return getDateIdFormater(timeZone).parse(id);
}
catch (ParseException e)
{
return null;
}
+ }
+
+ public static Calendar getCalendarInstance(Date date, TimeZone timeZone)
+ {
+ Calendar cal = GregorianCalendar.getInstance(
+ timeZone != null ? timeZone : TimeZone.getDefault());
+ cal.setFirstDayOfWeek(Calendar.MONDAY);
+ cal.setTime(date);
+
+ return cal;
+ }
+
+ private static SimpleDateFormat getDateIdFormater(TimeZone timeZone)
+ {
+ SimpleDateFormat format = new SimpleDateFormat(DATE_ID_PATTERN);
+
+ format.setTimeZone(timeZone);
+
+ return format;
}
}
//The End