/** * Check whether this value is equal to the Date supplied. * * @param date * The Date to check for equality * @return true if the Date representation of the value is equal to date. */ public boolean isEqualTo( Date date ) { return getDate() == date; }
/** * Search for a value, if it doesn't occur in the row, return the default value. * * @param valuename * The valuename to look for * @param def * The default value to return * @return The Date representation of the value found or the default */ public Date getDate( String valuename, Date def ) { Value v = searchValue( valuename ); if ( v == null ) { return def; } return v.getDate(); }
public Value last_day() throws KettleValueException { if ( getType() == VALUE_TYPE_DATE ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); int last_day = cal.getActualMaximum( Calendar.DAY_OF_MONTH ); cal.set( Calendar.DAY_OF_MONTH, last_day ); setValue( cal.getTime() ); } else { throw new KettleValueException( "Function last_day only works on a date" ); } return this; }
public Value first_day() throws KettleValueException { if ( getType() == VALUE_TYPE_DATE ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); cal.set( Calendar.DAY_OF_MONTH, 1 ); setValue( cal.getTime() ); } else { throw new KettleValueException( "Function first_day only works on a date" ); } return this; }
public Value add_months( int months ) throws KettleValueException { if ( getType() == VALUE_TYPE_DATE ) { if ( !isNull() && getDate() != null ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); int year = cal.get( Calendar.YEAR ); int month = cal.get( Calendar.MONTH ); int day = cal.get( Calendar.DAY_OF_MONTH ); month += months; int newyear = year + (int) Math.floor( month / 12 ); int newmonth = month % 12; cal.set( newyear, newmonth, 1 ); int newday = cal.getActualMaximum( Calendar.DAY_OF_MONTH ); if ( newday < day ) { cal.set( Calendar.DAY_OF_MONTH, newday ); } else { cal.set( Calendar.DAY_OF_MONTH, day ); } setValue( cal.getTime() ); } } else { throw new KettleValueException( "Function add_months only works on a date!" ); } return this; }
/** * Add a number of days to a Date value. * * @param days * The number of days to add to the current date value * @return The resulting value * @throws KettleValueException */ public Value add_days( long days ) throws KettleValueException { if ( getType() == VALUE_TYPE_DATE ) { if ( !isNull() && getDate() != null ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); cal.add( Calendar.DAY_OF_YEAR, (int) days ); setValue( cal.getTime() ); } } else { throw new KettleValueException( "Function add_days only works on a date!" ); } return this; }
return v.getDate(); } catch ( Exception e2 ) { try {
public Value trunc() throws KettleValueException { if ( isNull() ) { return this; // don't do anything, leave it at NULL! } if ( isInteger() ) { // Nothing return this; } if ( isBigNumber() ) { getBigNumber().setScale( 0, BigDecimal.ROUND_FLOOR ); } else if ( isNumber() ) { setValue( Math.floor( getNumber() ) ); } else if ( isDate() ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); cal.set( Calendar.MILLISECOND, 0 ); cal.set( Calendar.SECOND, 0 ); cal.set( Calendar.MINUTE, 0 ); cal.set( Calendar.HOUR_OF_DAY, 0 ); setValue( cal.getTime() ); } else { throw new KettleValueException( "Function TRUNC only works on numbers and dates" ); } return this; }
} else if ( isDate() ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() );
public Value dat2str( String arg0, String arg1 ) throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getType() == VALUE_TYPE_DATE ) { SimpleDateFormat df = new SimpleDateFormat(); DateFormatSymbols dfs = new DateFormatSymbols(); if ( arg1 != null ) { dfs.setLocalPatternChars( arg1 ); } if ( arg0 != null ) { df.applyPattern( arg0 ); } try { setValue( df.format( getDate() ) ); } catch ( Exception e ) { setType( VALUE_TYPE_STRING ); setNull(); throw new KettleValueException( "TO_CHAR Couldn't convert Date to String " + e.toString() ); } } else { throw new KettleValueException( "Function DAT2STR only works on a date" ); } } return this; }
Date dat = v.getDate(); if ( dat != null ) { dbl = dat.getTime();
Date dat = v.getDate(); if ( dat != null ) { dbl = dat.getTime();
isNull() || ( isString() && ( getString() == null || getString().length() == 0 ) ) || ( isDate() && getDate() == null ) || ( isBigNumber() && getBigNumber() == null ); boolean n2 = v.isNull() || ( v.isString() && ( v.getString() == null || v.getString().length() == 0 ) ) || ( v.isDate() && v.getDate() == null ) || ( v.isBigNumber() && v.getBigNumber() == null );
/** * Convert this Value from type String to another type * * @param newtype * The Value type to convert to. */ public void convertString( int newtype ) throws KettleValueException { switch ( newtype ) { case VALUE_TYPE_STRING: break; case VALUE_TYPE_NUMBER: setValue( getNumber() ); break; case VALUE_TYPE_DATE: setValue( getDate() ); break; case VALUE_TYPE_BOOLEAN: setValue( getBoolean() ); break; case VALUE_TYPE_INTEGER: setValue( getInteger() ); break; case VALUE_TYPE_BIGNUMBER: setValue( getBigNumber() ); break; default: throw new KettleValueException( "Please specify the type to convert to from String type." ); } }
return value.getInteger(); case ValueMetaInterface.TYPE_DATE: return value.getDate(); case ValueMetaInterface.TYPE_BOOLEAN: return value.getBoolean();