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
package fr.into.common.util.data.calendar;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class CalendarUtil {
        protected static GregorianCalendar      targetCalendar  = new 
GregorianCalendar(), sourceCalendar = new GregorianCalendar();
        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 );
        }
        
        public static Date set(Date source, Date target, int... toSet) {
                if( target == null ) {
                        target = new Date();
                }
                targetCalendar.setTime( target );
                sourceCalendar.setTime( source );
                for( int calendarItem : toSet ) {
                        targetCalendar.set( calendarItem, sourceCalendar.get( 
calendarItem ) );                 
                }
                return targetCalendar.getTime();
        }
}

Reply via email to