You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Mikhail Grushinskiy (JIRA)" <de...@myfaces.apache.org> on 2006/08/23 04:54:14 UTC

[jira] Created: (TOMAHAWK-614) Schedule for January is missing January 1, 2006

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


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

        

[jira] Updated: (TOMAHAWK-614) Schedule for January is missing January 1, 2006

Posted by "Mikhail Grushinskiy (JIRA)" <de...@myfaces.apache.org>.
     [ http://issues.apache.org/jira/browse/TOMAHAWK-614?page=all ]

Mikhail Grushinskiy updated TOMAHAWK-614:
-----------------------------------------

    Status: Open  (was: Patch Available)

> 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

        

[jira] Commented: (TOMAHAWK-614) Schedule for January is missing January 1, 2006

Posted by "Mikhail Grushinskiy (JIRA)" <de...@myfaces.apache.org>.
    [ http://issues.apache.org/jira/browse/TOMAHAWK-614?page=comments#action_12430148 ] 
            
Mikhail Grushinskiy commented on TOMAHAWK-614:
----------------------------------------------

If I select January 1, 2006 as current date on weekly view it gives me week starting with January 2nd, which is clearly a bug.


> 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

        

[jira] Updated: (TOMAHAWK-614) Schedule for January is missing January 1, 2006

Posted by "Mikhail Grushinskiy (JIRA)" <de...@myfaces.apache.org>.
     [ http://issues.apache.org/jira/browse/TOMAHAWK-614?page=all ]

Mikhail Grushinskiy updated TOMAHAWK-614:
-----------------------------------------

    Status: Patch Available  (was: Open)

> 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

        

[jira] Commented: (TOMAHAWK-614) Schedule for January is missing January 1, 2006

Posted by "Mikhail Grushinskiy (JIRA)" <de...@myfaces.apache.org>.
    [ http://issues.apache.org/jira/browse/TOMAHAWK-614?page=comments#action_12430162 ] 
            
Mikhail Grushinskiy commented on TOMAHAWK-614:
----------------------------------------------

Here is improved version of the code

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 {

       /**
        * serialVersionUID
        */
       private static final long serialVersionUID =
-2291773335106774130L;

       public static final String VER_ID = "$Id$";

       private String timeZone;
       private Date startDate;
       private Date endDate;

       public String getTimeZone() {
               return timeZone;
       }

       public void setTimeZone(String timeZone) {
               this.timeZone = timeZone;
       }

       /**
        * @return Calendar with settings
        */
       public Calendar getCalendar() {
               Calendar calendar = GregorianCalendar.getInstance();
               String userTimeZone = getTimeZone();
               if (userTimeZone != null) {
                       TimeZone tz =
TimeZone.getTimeZone(userTimeZone);
                       calendar.setTimeZone(tz);
               }
               calendar.setFirstDayOfWeek(Calendar.MONDAY);
               calendar.setMinimalDaysInFirstWeek(1);
               return calendar;
       }

       /*
        * (non-Javadoc)
        *
        * @see
org.apache.myfaces.custom.schedule.model.AbstractScheduleModel#setWeek(j
ava.util.Date)
        */
       @Override
       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);
               }
               startDate = firstDay.getDayStart();
               endDate = lastDay.getDayEnd();
               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);
               }
               startDate = firstDay.getDayStart();
               endDate = lastDay.getDayEnd();
               load(firstDay.getDayStart(), lastDay.getDayEnd());
       }

       /*
        * (non-Javadoc)
        *
        * @see
org.apache.myfaces.custom.schedule.model.AbstractScheduleModel#setMonth(
java.util.Date)
        */
       @Override
       protected void setMonth(Date date) {
               if (date == null) {
                       return;
               }
               clear();

               Calendar cal = getCalendar();
               cal.setTime(date);

               // go back to the first day of the month;
               cal.set(Calendar.DAY_OF_MONTH,
cal.getMinimum(Calendar.DAY_OF_MONTH));

               Date temp = cal.getTime();
               cal.add(Calendar.MONTH, 1);
               int nextMonth = cal.get(Calendar.MONTH);
               cal.setTime(temp);

               ScheduleDay firstDay = null;
               ScheduleDay lastDay = null;

               // we want to show the whole first week, including the
days from the
               // previous month
               cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

               while (true) {
                       ScheduleDay addedDay = add(cal.getTime());

                       if (firstDay == null) {
                               firstDay = addedDay;
                       }

                       lastDay = addedDay;
                       cal.add(Calendar.DATE, 1);

                       // stop when we are at the last day of the last
week
                       if (cal.get(Calendar.MONTH) == nextMonth
                                       && cal.get(Calendar.DAY_OF_WEEK)
== Calendar.MONDAY) {
                               break;
                       }
               }
               startDate = firstDay.getDayStart();
               endDate = lastDay.getDayEnd();
               load(firstDay.getDayStart(), lastDay.getDayEnd());
       }

       /* (non-Javadoc)
        * @see
org.apache.myfaces.custom.schedule.model.AbstractScheduleModel#setDay(ja
va.util.Date)
        */
       @Override
       protected void setDay(Date date) {
               if (date == null) {
                       return;
               }
               clear();
               ScheduleDay day = add(date);
               startDate = day.getDayStart();
               endDate = day.getDayEnd();
               load(day.getDayStart(), day.getDayEnd());
       }

       /**
        * @param startDate
        * @param endDate
        */
       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);
                       }
               }
       }

       public Date getEndDate() {
               return endDate;
       }

       public void setEndDate(Date endDate) {
               this.endDate = endDate;
       }

       public Date getStartDate() {
               return startDate;
       }

       public void setStartDate(Date startDate) {
               this.startDate = startDate;
       }
}


> 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

        

[jira] Updated: (TOMAHAWK-614) Schedule for January is missing January 1, 2006

Posted by "Mikhail Grushinskiy (JIRA)" <de...@myfaces.apache.org>.
     [ http://issues.apache.org/jira/browse/TOMAHAWK-614?page=all ]

Mikhail Grushinskiy updated TOMAHAWK-614:
-----------------------------------------

    Status: Patch Available  (was: Open)

> 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

        

[jira] Commented: (TOMAHAWK-614) Schedule for January is missing January 1, 2006

Posted by "Mikhail Grushinskiy (JIRA)" <de...@myfaces.apache.org>.
    [ 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