public static Date getJavaDate( final BigDecimal date, final boolean excelBugCompatible, final int zeroDate ) { int correction = 1; final BigDecimal wholeDays = NumberUtil.performIntRounding( date ); final int wholeDaysInt = wholeDays.intValue() - zeroDate; if ( excelBugCompatible ) { // if we deal with a date that is after the 28th februar, adjust the date by one to handle the fact // that excel thinks the 29th February 1900 exists. // by tuning this variable, we map the int-value for the 29th to the next day. if ( wholeDaysInt > 59 ) { correction = 0; } } final BigDecimal fractionNum = date.subtract( wholeDays ); final BigDecimal fraction = fractionNum.multiply( DAY_MILLISECONDS ); // the use of the calendar could be probably removed, as there is no magic in converting // a running number into a date. final GregorianCalendar calendar = new GregorianCalendar( 1900, 0, wholeDaysInt + correction ); calendar.set( Calendar.MILLISECOND, fraction.setScale( 0, BigDecimal.ROUND_HALF_UP ).intValue() ); return calendar.getTime(); } }
public static Date getJavaDate(final BigDecimal date, final boolean excelBugCompatible, final int zeroDate) { int correction = 1; final BigDecimal wholeDays = NumberUtil.performIntRounding(date); final int wholeDaysInt = wholeDays.intValue() - zeroDate; if (excelBugCompatible) { // if we deal with a date that is after the 28th februar, adjust the date by one to handle the fact // that excel thinks the 29th February 1900 exists. // by tuning this variable, we map the int-value for the 29th to the next day. if (wholeDaysInt > 59) { correction = 0; } } final BigDecimal fractionNum = date.subtract(wholeDays); final BigDecimal fraction = fractionNum.multiply(DAY_MILLISECONDS); // the use of the calendar could be probably removed, as there is no magic in converting // a running number into a date. final GregorianCalendar calendar = new GregorianCalendar(1900, 0, wholeDaysInt + correction); calendar.set(Calendar.MILLISECOND, fraction.setScale(0, BigDecimal.ROUND_HALF_UP).intValue()); return calendar.getTime(); } }
public static BigDecimal normalizeDate( final BigDecimal fromSerialDate, final Type toType ) { if ( fromSerialDate == null ) { throw new IllegalArgumentException(); } if ( toType == null ) { throw new IllegalArgumentException(); } if ( toType.isFlagSet( Type.TIME_TYPE ) ) { final BigDecimal o = fromSerialDate.setScale( LibFormulaBoot.GLOBAL_SCALE, BigDecimal.ROUND_UP ); return o.subtract( new BigDecimal( o.intValue() ) ); // only return the decimal part // final Double d = new Double(fromSerialDate.doubleValue() // - fromSerialDate.intValue()); // return d; } else if ( toType.isFlagSet( Type.DATE_TYPE ) ) { return NumberUtil.performIntRounding( fromSerialDate ); } else { // else it must be date-time, so return it unchanged .. return fromSerialDate; } }
public static BigDecimal normalizeDate(final BigDecimal fromSerialDate, final Type toType) { if (fromSerialDate == null) { throw new IllegalArgumentException(); } if (toType == null) { throw new IllegalArgumentException(); } if (toType.isFlagSet(Type.TIME_TYPE)) { final BigDecimal o = fromSerialDate.setScale(LibFormulaBoot.GLOBAL_SCALE, BigDecimal.ROUND_UP); return o.subtract(new BigDecimal(o.intValue())); // only return the decimal part // final Double d = new Double(fromSerialDate.doubleValue() // - fromSerialDate.intValue()); // return d; } else if (toType.isFlagSet(Type.DATE_TYPE)) { return NumberUtil.performIntRounding(fromSerialDate); } else { // else it must be date-time, so return it unchanged .. return fromSerialDate; } }
protected long computeDays( final ParameterCallback parameters, final TypeRegistry typeRegistry ) throws EvaluationException { final Number date1 = typeRegistry.convertToNumber( parameters.getType( 0 ), parameters.getValue( 0 ) ); final Number date2 = typeRegistry.convertToNumber( parameters.getType( 1 ), parameters.getValue( 1 ) ); final BigDecimal dn1 = NumberUtil.performIntRounding( NumberUtil.getAsBigDecimal( date1 ) ); final BigDecimal dn2 = NumberUtil.performIntRounding( NumberUtil.getAsBigDecimal( date2 ) ); return dn2.longValue() - dn1.longValue(); }
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 Number n = typeRegistry.convertToNumber( parameters.getType( 0 ), parameters.getValue( 0 ) ); if ( n == null ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } final BigDecimal bd = NumberUtil.getAsBigDecimal( n ); final BigDecimal day = new BigDecimal( NumberUtil.performIntRounding( bd ).intValue() ); final BigDecimal dayFraction = bd.subtract( day ); final BigDecimal hourAndMinutesVal = dayFraction.multiply( HOUR_24 ); final BigDecimal hours = NumberUtil.performIntRounding( hourAndMinutesVal ); return new TypeValuePair( NumberType.GENERIC_NUMBER, hours ); } }
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 Number n = typeRegistry.convertToNumber(parameters.getType(0), parameters.getValue(0)); if (n == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final BigDecimal bd = NumberUtil.getAsBigDecimal(n); final BigDecimal day = new BigDecimal(NumberUtil.performIntRounding(bd).intValue()); final BigDecimal dayFraction = bd.subtract(day); final BigDecimal hourAndMinutesVal = dayFraction.multiply(HOUR_24); final BigDecimal hours = NumberUtil.performIntRounding(hourAndMinutesVal); return new TypeValuePair(NumberType.GENERIC_NUMBER, hours); } }
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 Number n = typeRegistry.convertToNumber( parameters.getType( 0 ), parameters.getValue( 0 ) ); if ( n == null ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } // calculation is as follows // time * 24 so that we get the full hours (which we remove later) final BigDecimal bd = NumberUtil.getAsBigDecimal( n ); final BigDecimal hours = bd.multiply( MINUTES_PER_DAY ); final BigDecimal dayAndHoursAsInt = NumberUtil.performIntRounding( hours ); final BigDecimal minutesFraction = hours.subtract( dayAndHoursAsInt ); // Multiply the minutes with 60 to get the minutes as ints final BigDecimal seconds = minutesFraction.multiply( SECONDS ); final BigDecimal secondsAsInt = NumberUtil.performIntRounding( seconds ); return new TypeValuePair( NumberType.GENERIC_NUMBER, secondsAsInt ); } }
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 Number n = typeRegistry.convertToNumber(parameters.getType(0), parameters.getValue(0)); if (n == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } // calculation is as follows // time * 24 so that we get the full hours (which we remove later) final BigDecimal bd = NumberUtil.getAsBigDecimal(n); final BigDecimal hours = bd.multiply(HOURS); final BigDecimal dayAndHoursAsInt = new BigDecimal(NumberUtil.performIntRounding(hours).intValue()); final BigDecimal minutesFraction = hours.subtract(dayAndHoursAsInt); // Multiply the minutes with 60 to get the minutes as ints final BigDecimal minutes = minutesFraction.multiply(MINUTES); final BigDecimal minutesAsInt = minutes.setScale(0, BigDecimal.ROUND_HALF_UP); return new TypeValuePair(NumberType.GENERIC_NUMBER, minutesAsInt); } }
final BigDecimal dayAndHoursAsInt = NumberUtil.performIntRounding(hours); final BigDecimal minutesFraction = hours.subtract(dayAndHoursAsInt); final BigDecimal secondsAsInt = NumberUtil.performIntRounding(seconds);
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 Number n = typeRegistry.convertToNumber( parameters.getType( 0 ), parameters.getValue( 0 ) ); if ( n == null ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } // calculation is as follows // time * 24 so that we get the full hours (which we remove later) final BigDecimal bd = NumberUtil.getAsBigDecimal( n ); final BigDecimal hours = bd.multiply( HOURS ); final BigDecimal dayAndHoursAsInt = new BigDecimal( NumberUtil.performIntRounding( hours ).intValue() ); final BigDecimal minutesFraction = hours.subtract( dayAndHoursAsInt ); // Multiply the minutes with 60 to get the minutes as ints final BigDecimal minutes = minutesFraction.multiply( MINUTES ); // Fix for PRD-5499, contributed by Lionel Elie Mamane // final BigDecimal minutesAsInt = minutes.setScale( 0, BigDecimal.ROUND_HALF_UP ); final BigDecimal minutesAsInt = NumberUtil.performMinuteRounding( minutes ); return new TypeValuePair( NumberType.GENERIC_NUMBER, minutesAsInt ); } }
(parameters.getType(1), parameters.getValue(1)); final BigDecimal dn1 = NumberUtil.performIntRounding(NumberUtil.getAsBigDecimal(date1)); final BigDecimal dn2 = NumberUtil.performIntRounding(NumberUtil.getAsBigDecimal(date2));
public TypeValuePair evaluate( final FormulaContext context, final ParameterCallback parameters ) throws EvaluationException { if ( parameters.getParameterCount() != 1 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } final Type type1 = parameters.getType( 0 ); final Object value1 = parameters.getValue( 0 ); final Number result = context.getTypeRegistry().convertToNumber( type1, value1 ); if ( result == null ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } final Number ret = NumberUtil.performIntRounding( NumberUtil.getAsBigDecimal( result ) ); return new TypeValuePair( NumberType.GENERIC_NUMBER, ret ); }
public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final Number ret = NumberUtil.performIntRounding(NumberUtil.getAsBigDecimal(result)); return new TypeValuePair(NumberType.GENERIC_NUMBER, ret); }