/** * Converts a <code>Date</code> value according to the requested <code>Type</code> to the proper <code>Date</code> * subclasses (<code>java.sql.Time</code>, <code>java.sql.Date</code>) if needed. If the requested type is unknown, no * conversion takes place and the input date is returned. * * @param fromDate The date to convert. * @param toType The requested type of date. * @return The converted date. */ public static Date normalizeDate( final Date fromDate, final Type toType ) { return normalizeDate( fromDate, toType, true ); }
/** * Converts a <code>Date</code> value according to the requested <code>Type</code> to the proper <code>Date</code> * subclasses (<code>java.sql.Time</code>, <code>java.sql.Date</code>) if needed. If the requested type is unknown, no * conversion takes place and the input date is returned. * * @param fromDate The date to convert. * @param toType The requested type of date. * @return The converted date. */ public static Date normalizeDate(final Date fromDate, final Type toType) { return normalizeDate(fromDate, toType, true); }
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters ) throws EvaluationException { final Date yesterday = yesterday( context ); final Date date = DateUtil.normalizeDate( yesterday, DateTimeType.DATE_TYPE ); return new TypeValuePair( DateTimeType.DATE_TYPE, date ); }
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters ) throws EvaluationException { final Date now = DateUtil.now( context ); final Date date = DateUtil.normalizeDate( now, DateTimeType.DATE_TYPE ); return new TypeValuePair( DateTimeType.DATE_TYPE, date ); } }
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters ) throws EvaluationException { final Date now = DateUtil.now( context ); final Date date = DateUtil.normalizeDate( now, DateTimeType.DATETIME_TYPE ); return new TypeValuePair( DateTimeType.DATETIME_TYPE, date ); } }
public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final Date yesterday = yesterday(context); final Date date = DateUtil.normalizeDate(yesterday, DateTimeType.DATE_TYPE); return new TypeValuePair(DateTimeType.DATE_TYPE, date); }
public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final Date now = DateUtil.now(context); final Date date = DateUtil.normalizeDate(now, DateTimeType.DATETIME_TYPE); return new TypeValuePair(DateTimeType.DATETIME_TYPE, date); } }
public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final Date now = DateUtil.now(context); final Date date = DateUtil.normalizeDate(now, DateTimeType.DATE_TYPE); return new TypeValuePair(DateTimeType.DATE_TYPE, date); } }
public static Date normalizeDate( Date fromDate, final Type toType, final boolean convertSerial ) { if ( fromDate == null ) { throw new IllegalArgumentException(); } if ( toType == null ) { throw new IllegalArgumentException(); } if ( convertSerial ) { BigDecimal serial = HSSFDateUtil.getExcelDate( fromDate ); serial = normalizeDate( serial, toType ); fromDate = HSSFDateUtil.getJavaDate( serial ); } // final GregorianCalendar gc = new GregorianCalendar(); // gc.setTime(fromDate); // gc.set(GregorianCalendar.MILLISECOND, 0); // fromDate = gc.getTime(); if ( toType.isFlagSet( Type.TIME_TYPE ) ) { return new Time( fromDate.getTime() ); } else if ( toType.isFlagSet( Type.DATE_TYPE ) ) { return new java.sql.Date( fromDate.getTime() ); } else if ( toType.isFlagSet( Type.DATETIME_TYPE ) ) { return new Date( fromDate.getTime() ); } return fromDate; }
serial = normalizeDate(serial, toType); fromDate = HSSFDateUtil.getJavaDate(serial);
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters ) throws EvaluationException { if ( parameters.getParameterCount() != 1 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type type = parameters.getType( 0 ); final Object value = parameters.getValue( 0 ); final Date date1 = typeRegistry.convertToDate( type, value ); final Date date = DateUtil.normalizeDate( date1, DateTimeType.DATE_TYPE ); return new TypeValuePair( DateTimeType.DATE_TYPE, date ); } }
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters ) throws EvaluationException { if ( parameters.getParameterCount() != 1 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type type = parameters.getType( 0 ); final Object value = parameters.getValue( 0 ); final Date date1 = typeRegistry.convertToDate( type, value ); final Date time = DateUtil.normalizeDate( date1, DateTimeType.TIME_TYPE ); return new TypeValuePair( DateTimeType.TIME_TYPE, time ); } }
|| targetType.isFlagSet( Type.TIME_TYPE ) ) { final Date toJavaDate = (Date) value; return DateUtil.normalizeDate( toJavaDate, targetType, false ); || targetType.isFlagSet( Type.TIME_TYPE ) ) { final BigDecimal fromAsBigDecimal = NumberUtil.getAsBigDecimal( serial ); final BigDecimal normalizedSerial = DateUtil.normalizeDate( fromAsBigDecimal, targetType ); final Date toJavaDate = HSSFDateUtil.getJavaDate( normalizedSerial ); return DateUtil.normalizeDate( toJavaDate, targetType, false );
public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type type = parameters.getType(0); final Object value = parameters.getValue(0); final Date date1 = typeRegistry.convertToDate(type, value); final Date time = DateUtil.normalizeDate(date1, DateTimeType.TIME_TYPE); return new TypeValuePair(DateTimeType.TIME_TYPE, time); } }
public Date convertToDate( final Type type1, final Object value ) throws EvaluationException { if ( type1.isFlagSet( Type.NUMERIC_TYPE ) || type1.isFlagSet( Type.ANY_TYPE ) ) { if ( type1.isFlagSet( Type.DATE_TYPE ) || type1.isFlagSet( Type.DATETIME_TYPE ) || type1.isFlagSet( Type.TIME_TYPE ) || type1.isFlagSet( Type.ANY_TYPE ) ) { if ( value instanceof Date ) { return DateUtil.normalizeDate( (Date) value, type1 ); } } } final Number serial = convertToNumber( type1, value ); final BigDecimal bd = NumberUtil.getAsBigDecimal( serial ); return HSSFDateUtil.getJavaDate( bd ); }
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters ) throws EvaluationException { if ( parameters.getParameterCount() > 1 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } final TypeRegistry typeRegistry = context.getTypeRegistry(); int type = 1; // default is Type 1 if ( parameters.getParameterCount() == 1 ) { final Number n = typeRegistry.convertToNumber( parameters.getType( 0 ), parameters.getValue( 0 ) ); if ( n == null ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } type = n.intValue(); if ( type < 1 || type > 2 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } } final LocalizationContext localizationContext = context.getLocalizationContext(); final Date prevweekday = prevweekday( type, localizationContext ); final Date date = DateUtil.normalizeDate( prevweekday, DateTimeType.DATE_TYPE ); return new TypeValuePair( DateTimeType.DATE_TYPE, date ); }
public Date convertToDate(final Type type1, final Object value) throws EvaluationException { if (type1.isFlagSet(Type.NUMERIC_TYPE) || type1.isFlagSet(Type.ANY_TYPE)) { if (type1.isFlagSet(Type.DATE_TYPE) || type1.isFlagSet(Type.DATETIME_TYPE) || type1.isFlagSet(Type.TIME_TYPE) || type1.isFlagSet(Type.ANY_TYPE)) { if (value instanceof Date) { return DateUtil.normalizeDate((Date) value, type1); } } } final Number serial = convertToNumber(type1, value); final BigDecimal bd = NumberUtil.getAsBigDecimal(serial); return HSSFDateUtil.getJavaDate(bd); }
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters ) throws EvaluationException { if ( parameters.getParameterCount() != 1 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Date d = typeRegistry.convertToDate( parameters.getType( 0 ), parameters.getValue( 0 ) ); if ( d == null ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } final LocalizationContext localizationContext = context.getLocalizationContext(); final Date monthend = monthend( d, localizationContext ); final Date date = DateUtil.normalizeDate( monthend, DateTimeType.DATE_TYPE ); return new TypeValuePair( DateTimeType.DATE_TYPE, date ); }
public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() > 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); int type = 1; // default is Type 1 if (parameters.getParameterCount() == 1) { final Number n = typeRegistry.convertToNumber(parameters.getType(0), parameters.getValue(0)); if (n == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } type = n.intValue(); if (type < 1 || type > 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } } final LocalizationContext localizationContext = context.getLocalizationContext(); final Date prevweekday = prevweekday(type, localizationContext); final Date date = DateUtil.normalizeDate(prevweekday, DateTimeType.DATE_TYPE); return new TypeValuePair(DateTimeType.DATE_TYPE, date); }
public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Date d = typeRegistry.convertToDate(parameters.getType(0), parameters.getValue(0)); if (d == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final LocalizationContext localizationContext = context.getLocalizationContext(); final Date monthend = monthend(d, localizationContext); final Date date = DateUtil.normalizeDate(monthend, DateTimeType.DATE_TYPE); return new TypeValuePair(DateTimeType.DATE_TYPE, date); }