[
http://issues.apache.org/jira/browse/TOMAHAWK-614?page=comments#action_12430154
]
Mikhail Grushinskiy commented on TOMAHAWK-614:
----------------------------------------------
Here sample code to fix it.
This is not a patch yet. Trick is in setting
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(1);
for every calendar used in a code. TimeZone has to be consistent and
configurable everywhere too.
I think getCalendar() should be moved into base abstract class for a
ScheduleModel and
AbstractScheduleModel should have gettter/setter for timeZone and
all places for schedule instead of doing GregorialCalendar.getInstance() we
should make a call
to model.getCalendar(). See code below
/**
* @return Calendar with settings
*/
public Calendar {
String userTimeZone = getTimeZone();
TimeZone tz = TimeZone.getTimeZone(userTimeZone);
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTimeZone(tz);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(1);
return calendar;
}
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import org.apache.myfaces.custom.schedule.model.SimpleScheduleModel;
import org.apache.myfaces.custom.schedule.model.ScheduleDay;
import org.apache.myfaces.custom.schedule.model.ScheduleEntry;
public class ScheduleModel extends SimpleScheduleModel implements
Serializable {
public static final String VER_ID="$Id$";
/**
* serialVersionUID
*/
private static final long serialVersionUID =
-7391783268115864166L;
private String timeZone = null;
public String getTimeZone() {
return timeZone;
}
public void setTimeZone(String timeZone) {
this.timeZone = timeZone;
}
/**
* @return Calendar with settings
*/
public Calendar getCalendar() {
String userTimeZone = getTimeZone();
TimeZone tz = TimeZone.getTimeZone(userTimeZone);
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTimeZone(tz);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(1);
return calendar;
}
/**
* <p>
* navigate to the specified week
* </p>
*
* @param date
* the date to navigate to
*/
protected void setWeek(Date date) {
if (date == null) {
return;
}
clear();
Calendar cal = getCalendar();
cal.setTime(date);
// go back to the monday of this week
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
ScheduleDay firstDay = null;
ScheduleDay lastDay = null;
for (int i = 0; i < 7; i++) {
ScheduleDay addedDay = add(cal.getTime());
if (firstDay == null) {
firstDay = addedDay;
}
lastDay = addedDay;
cal.add(Calendar.DATE, 1);
}
load(firstDay.getDayStart(), lastDay.getDayEnd());
}
/*
* (non-Javadoc)
*
* @see
org.apache.myfaces.custom.schedule.model.AbstractScheduleModel#setWorkWe
ek(java.util.Date)
*/
@Override
protected void setWorkWeek(Date date) {
if (date == null) {
return;
}
clear();
Calendar cal = getCalendar();
cal.setTime(date);
// go back to the monday of this week
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
ScheduleDay firstDay = null;
ScheduleDay lastDay = null;
for (int i = 0; i < 5; i++) {
ScheduleDay addedDay = add(cal.getTime());
if (firstDay == null) {
firstDay = addedDay;
}
lastDay = addedDay;
cal.add(Calendar.DATE, 1);
}
load(firstDay.getDayStart(), lastDay.getDayEnd());
}
private void load(Date startDate, Date endDate) {
Collection entries = loadEntries(startDate, endDate);
for (Iterator entryIterator = entries.iterator();
entryIterator
.hasNext();) {
ScheduleEntry entry = (ScheduleEntry)
entryIterator.next();
for (Iterator dayIterator = days.iterator();
dayIterator.hasNext();) {
ScheduleDay day = (ScheduleDay)
dayIterator.next();
day.addEntry(entry);
}
}
}
}
> Schedule for January is missing January 1, 2006
> -----------------------------------------------
>
> Key: TOMAHAWK-614
> URL: http://issues.apache.org/jira/browse/TOMAHAWK-614
> Project: MyFaces Tomahawk
> Issue Type: Bug
> Components: Schedule
> Environment: all
> Reporter: Mikhail Grushinskiy
> Priority: Minor
> Fix For: 1.1.4-SNAPSHOT, 1.1.5-SNAPSHOT
>
> Attachments: AbstractScheduleModel.java.patch,
> AbstractScheduleModel.java.patch
>
>
> Schedule for January is missing January 1, 2006. Somehow January 1, 2006 is
> not appearing on January 2006 schedule (basically whole week ending with it
> is missing)
>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira