Hello,
Sorry for spamming, I found a bug in the class I sent you this morning: so
just to see how tedious it is to point to the same Date with separate
tc:date and tc:time tags, if every tag was just updating the fields he
shows, we could point to the same field without ths linking cables:
*public* Date getWorkStartTime() {
*return* getCurrentWorkTask().getWorkStart();
}
*public* Date getWorkStartDate() {
Date start = getCurrentWorkTask().getWorkStart();
*if*( start == *null* || CalendarUtil.*equalsDate*( start,
1970, 0, 1 ) )
*return* *null*;
*return* start;
}
*public* *void* setWorkStartDate(Date workStart) {
getCurrentWorkTask().setWorkStart( CalendarUtil.*setDate*(
workStart, getWorkStart() ) );
}
*public* String toString() {
*return* getCurrentWorkTask().toString();
}
To remind what I would like to have here's what I expected from these
components:
<tx:date
id ="workStartDate"
value ="#{intervention.*workStart*}"
label ="#{i18n.workStartDate}" >
< f:convertDateTime pattern ="dd.MM.yyyy" />
</ tx:date>
< tc:time
id ="workStart"
value= "#{intervention.*workStart*}" />
in that case all the code above is simplified in a pojo manner.
Regards,
Zied
2007/10/5, Zied Hamdi <[EMAIL PROTECTED]>:
>
> Hello again,
>
> Sorry I forgot we're in multitasking.
>
> Here's a better version.
>
> Regards,
> Zied
>
>
> 2007/10/5, Zied Hamdi <[EMAIL PROTECTED]>:
> >
> > Hello,
> >
> > I've just wrote a util class that could help in this task.
> >
> > Regards,
> > Zied
> >
> >
> > 2007/9/21, Zied Hamdi <[EMAIL PROTECTED]>:
> > >
> > >
> > > Sorry forgot to mention [tobago]
> > > ---------- Forwarded message ----------
> > > From: Zied Hamdi < [EMAIL PROTECTED] >
> > > Date: 21 sept. 2007 15:36
> > > Subject: separating the date and time components
> > > To: MyFaces < [email protected]>
> > >
> > > Hi,
> > >
> > > I have attempted to assemble a tx:date with a tc:time follow the same
> > > field (expecting each componenent will fill its data in the part it is
> > > concerned with)
> > >
> > > < tx:date
> > >
> > > id ="workStartDate"
> > >
> > > value ="#{intervention.workStart}"
> > >
> > > label ="#{i18n.workStartDate}" >
> > >
> > > < f:convertDateTime pattern = "dd.MM.yyyy" />
> > >
> > > </ tx:date>
> > >
> > >
> > >
> > > < tc:time
> > >
> > > id ="workStart"
> > >
> > > value = "#{intervention.workStart}" />
> > >
> > >
> > >
> > >
> > >
> > > The result is that tc:time seams to create a new instance with a date
> > > set to 0 (01.01.1970) instead of using GregorianCalendar.set() on the
> > > existing one.
> > >
> > > Do I have to cretae a minor issue on this behavior?
> > >
> > > --
> > > Zied Hamdi
> > > zatreex.sourceforge.net
> > >
> > >
> > >
> > > --
> > > Zied Hamdi
> > > zatreex.sourceforge.net
> > >
> > >
> >
> >
> > --
> > Zied Hamdi
> > zatreex.sourceforge.net
> >
> >
>
>
> --
> Zied Hamdi
> zatreex.sourceforge.net
>
>
--
Zied Hamdi
zatreex.sourceforge.net
package fr.into.common.util.data.calendar;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* Handle and compare dates and times in a multitasking env.
*
* @author Zied Hamdi on 5 oct. 07
*
*/
public class CalendarUtil {
public static final int[] TIME = {
Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND,
Calendar.MILLISECOND
};
public static final int[] DATE = {
Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH
};
public static Date setTime(Date source, Date target) {
return set( source, target, TIME );
}
public static Date setDate(Date source, Date target) {
return set( source, target, DATE );
}
/**
* Returns target updated with toSet fields from source
*
* @author Zied Hamdi for Into© corporation on 5 oct. 07
* @param source
* @param target
* @param toSet
* @return
*/
public static Date set(Date source, Date target, int... toSet) {
GregorianCalendar targetCalendar = new GregorianCalendar(),
sourceCalendar = new GregorianCalendar();
targetCalendar.setTime( target != null ? target : new Date( 0 )
);
sourceCalendar.setTime( source != null ? source : new Date( 0 )
);
for( int calendarItem : toSet ) {
targetCalendar.set( calendarItem, sourceCalendar.get(
calendarItem ) );
}
return targetCalendar.getTime();
}
public static boolean equals(Date date1, Date date2, int... toTest) {
if( date1 == date2 )
return true;
if( date1 == null || date2 == null )
return false;
GregorianCalendar targetCalendar = new GregorianCalendar(),
sourceCalendar = new GregorianCalendar();
targetCalendar.setTime( date2 );
sourceCalendar.setTime( date1 );
for( int calendarItem : toTest ) {
if( targetCalendar.get( calendarItem ) !=
sourceCalendar.get( calendarItem ) )
return false;
}
return true;
}
public static boolean equalsTime(Date date, int hour, int minute, int
second, int millisecond) {
return equals( TIME, date, hour, minute, second, millisecond );
}
public static boolean equalsDate(Date date, int year, int month, int
dayOfMonth) {
return equals( DATE, date, year, month, dayOfMonth );
}
/**
* Compares <code>values</code> with <code>date's</code> fields
* <code>toTest</code>. toTEst and values must be the same length. ex:
* <code>CalendarUtil.equalsDate( Calendar.YEAR, Calendar.MONTH,
Calendar.DAY_OF_MONTH, date, 1970, 0, 1 )</code>
*
* @author Zied Hamdi for Into© corporation on 5 oct. 07
* @param toTest
* @param date
* @param values
* @return
*/
public static boolean equals(int[] toTest, Date date, int... values) {
if( date == null )
return false;
if( values.length != toTest.length )
throw new IllegalArgumentException( "toTest and values
must be the same length." );
GregorianCalendar testCalendar = new GregorianCalendar();
testCalendar.setTime( date );
for( int i = 0; i < toTest.length; i++ ) {
if( testCalendar.get( toTest[i] ) != values[i] )
return false;
}
return true;
}
}