summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormianrui2012-06-12 06:05:08 (EDT)
committer mwu2012-06-12 06:05:08 (EDT)
commit1cff733c50be504fa43e8e9b6838ae8aa6d1cec6 (patch)
tree0d6233e00c5f62089cb1648cd53876b1a6347dca
parent293c08c41b74cbe275650724d1f57819108be3f7 (diff)
downloadorg.eclipse.birt-1cff733c50be504fa43e8e9b6838ae8aa6d1cec6.zip
org.eclipse.birt-1cff733c50be504fa43e8e9b6838ae8aa6d1cec6.tar.gz
org.eclipse.birt-1cff733c50be504fa43e8e9b6838ae8aa6d1cec6.tar.bz2
TED – Issue 49390 Ability to create a date object from BIRT functions
-rw-r--r--data/org.eclipse.birt.core.script.function/plugin.properties1
-rw-r--r--data/org.eclipse.birt.core.script.function/plugin.xml17
-rw-r--r--data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java61
3 files changed, 79 insertions, 0 deletions
diff --git a/data/org.eclipse.birt.core.script.function/plugin.properties b/data/org.eclipse.birt.core.script.function/plugin.properties
index 8c58c55..a187c0f 100644
--- a/data/org.eclipse.birt.core.script.function/plugin.properties
+++ b/data/org.eclipse.birt.core.script.function/plugin.properties
@@ -96,6 +96,7 @@ FunctionDesc.minutes=The number of the minutes between two dates
FunctionDesc.months=The number of the months between two dates
FunctionDesc.seconds=The number of the seconds between two dates
FunctionDesc.years=The number of the years between two dates
+FunctionDesc.date=creat a new date
FunctionDesc.duration.year=Obtains the value of the YEARS field as an integer value,* or 0 if not present.\nThe lexicalDuration is the duration string presentation, "PnYnMnDTnHnMnS"(e.g. P5Y2M15DT4H40M20S )
FunctionDesc.duration.month=Obtains the value of the MONTHS field as an integer value,* or 0 if not present.\nThe lexicalDuration is duration string presentation, "PnYnMnDTnHnMnS"(e.g. P5Y2M15DT4H40M20S )
FunctionDesc.duration.day=Obtains the value of the DAYS field as an integer value,* or 0 if not present.\nThe lexicalDuration is duration string presentation, "PnYnMnDTnHnMnS"(e.g. P5Y2M15DT4H40M20S )
diff --git a/data/org.eclipse.birt.core.script.function/plugin.xml b/data/org.eclipse.birt.core.script.function/plugin.xml
index 5928c30..5efb5e7 100644
--- a/data/org.eclipse.birt.core.script.function/plugin.xml
+++ b/data/org.eclipse.birt.core.script.function/plugin.xml
@@ -326,6 +326,23 @@
factoryclass="org.eclipse.birt.core.script.function.bre.BirtDateTimeFunctionFactory"
name="BirtDateTime" desc="Provide DateTime operation functions.">
<Function
+ desc="%FunctionDesc.date"
+ name="date">
+ <DataType value="%dataType.DateTime"></DataType>
+ <Argument name="year">
+ <DataType value="%dataType.Integer"></DataType></Argument>
+ <Argument name="month">
+ <DataType value="%dataType.Integer"></DataType></Argument>
+ <Argument name="day">
+ <DataType value="%dataType.Integer"></DataType></Argument>
+ <Argument name="hours">
+ <DataType value="%dataType.Integer"></DataType></Argument>
+ <Argument name="minutes">
+ <DataType value="%dataType.Integer"></DataType></Argument>
+ <Argument name="seconds">
+ <DataType value="%dataType.Integer"></DataType></Argument>
+ </Function>
+ <Function
desc="%FunctionDesc.year"
name="year">
<DataType value="%dataType.Integer"></DataType>
diff --git a/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java b/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java
index 902b50c..0a8dc22 100644
--- a/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java
+++ b/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java
@@ -154,6 +154,8 @@ public class BirtDateTime implements IScriptFunctionExecutor
this.executor = new Function_FirstDayOfMonth( );
else if( "firstDayOfWeek".equals( functionName ))
this.executor = new Function_FirstDayOfWeek( );
+ else if( "date".equals( functionName ))
+ this.executor = new Function_Date( );
else
throw new BirtException( "org.eclipse.birt.core.script.function.bre",
null,
@@ -1357,6 +1359,65 @@ public class BirtDateTime implements IScriptFunctionExecutor
}
}
+ private static class Function_Date extends Function_temp
+ {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ Function_Date( )
+ {
+ minParamCount = 3;
+ maxParamCount = 6;
+ }
+
+ protected Object getValue( Object[] args ) throws BirtException
+ {
+ if ( existNullValue( args ) )
+ {
+ return null;
+ }
+ if ( args.length == 3 )
+ return getDate( ( (Number) args[0] ).intValue( ),
+ ( (Number) args[1] ).intValue( ),
+ ( (Number) args[2] ).intValue( ),
+ 0,
+ 0,
+ 0 );
+ else if ( args.length == 4 )
+ return getDate( ( (Number) args[0] ).intValue( ),
+ ( (Number) args[1] ).intValue( ),
+ ( (Number) args[2] ).intValue( ),
+ ( (Number) args[3] ).intValue( ),
+ 0,
+ 0 );
+ else if ( args.length == 5 )
+ return getDate( ( (Number) args[0] ).intValue( ),
+ ( (Number) args[1] ).intValue( ),
+ ( (Number) args[2] ).intValue( ),
+ ( (Number) args[3] ).intValue( ),
+ ( (Number) args[4] ).intValue( ),
+ 0 );
+ else
+ return getDate( ( (Number) args[0] ).intValue( ),
+ ( (Number) args[1] ).intValue( ),
+ ( (Number) args[2] ).intValue( ),
+ ( (Number) args[3] ).intValue( ),
+ ( (Number) args[4] ).intValue( ),
+ ( (Number) args[5] ).intValue( ) );
+ }
+ }
+
+ private static Date getDate( int year, int month, int day, int hours,
+ int minutes, int seconds )
+ {
+ Date newDate = new Date( );
+ Calendar calendar = getCalendar( newDate );
+ calendar.set( year, month, day, hours, minutes, seconds );
+ return calendar.getTime( );
+ }
/**
* Add num seconds
*