summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpshi2011-12-07 05:26:30 (EST)
committer mwu2011-12-07 05:26:30 (EST)
commita8224dfb64403e4267d99056f55023d569057191 (patch)
treeb4c3a30e4b676bea5865538f56af58a593dd6127
parenta8a192cb179e47a3e172c3da64bdd3b0b0b63ef5 (diff)
downloadorg.eclipse.birt-a8224dfb64403e4267d99056f55023d569057191.zip
org.eclipse.birt-a8224dfb64403e4267d99056f55023d569057191.tar.gz
org.eclipse.birt-a8224dfb64403e4267d99056f55023d569057191.tar.bz2
fix some bugs related to the week level
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/AbstractMDX.java43
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/PreviousNPeriodsFunction.java1
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeMemberUtil.java4
3 files changed, 45 insertions, 3 deletions
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/AbstractMDX.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/AbstractMDX.java
index f2e4e66..610c270 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/AbstractMDX.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/AbstractMDX.java
@@ -42,6 +42,7 @@ abstract public class AbstractMDX
{
String type = "";
int dayOfWeek = 1;
+ int month = 1 ;
for ( int i = 0; i < values.length; i++ )
{
if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) )
@@ -62,6 +63,7 @@ abstract public class AbstractMDX
{
cal.set( Calendar.MONTH, values[i] - 1 );
type = MONTH;
+ month = values[i] - 1;
}
else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) )
@@ -84,6 +86,7 @@ abstract public class AbstractMDX
cal.set( Calendar.WEEK_OF_MONTH, values[i] );
+ setAcrossMonthWeekDay(cal, month);
type = WEEK;
}
@@ -106,6 +109,8 @@ abstract public class AbstractMDX
}
cal.set( Calendar.WEEK_OF_YEAR, values[i] );
+ setAcrossMonthWeekDay(cal, month);
+
type = WEEK;
}
else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK ) )
@@ -134,6 +139,26 @@ abstract public class AbstractMDX
return type;
}
+
+ private void setAcrossMonthWeekDay(Calendar cal, int monthBase)
+ {
+ int month = cal.get( Calendar.MONTH );
+ if ( month == monthBase )
+ {
+ return;
+ }
+
+ cal.set( Calendar.DAY_OF_WEEK, 1 );
+ int monthStart = cal.get( Calendar.MONTH );
+
+ if ( monthStart == monthBase )
+ {
+ return;
+ }
+
+ cal.set( Calendar.DAY_OF_WEEK, 7 );
+
+ }
/**
* get the TimeMember.values from Calendar
*
@@ -215,9 +240,16 @@ abstract public class AbstractMDX
else if ( type.equals( "quarterToDate" ) )
{
int quarter = cal.get( Calendar.MONTH ) / 3 + 1;
- startMonth = quarter * 3 - 2;
- startCal.set( Calendar.MONTH, startMonth - 1 );
+ startMonth = quarter * 3 - 3;
+ startCal.set( Calendar.MONTH, startMonth );
startCal.set( Calendar.DAY_OF_MONTH, 1 );
+ if ( startMonth == 0 && startCal.get( Calendar.WEEK_OF_YEAR ) > 1 )
+ {
+ int[] newValues = getValueFromCal( startCal, levels );
+ TimeMember newMember = new TimeMember( newValues, levels );
+ list.add( newMember );
+ startCal.add( Calendar.WEEK_OF_YEAR, 1 );
+ }
startWeek = startCal.get( Calendar.WEEK_OF_YEAR );
}
else if ( type.equals( "monthToDate" ) )
@@ -225,6 +257,13 @@ abstract public class AbstractMDX
startMonth = cal.get( Calendar.MONTH );
startCal.set( Calendar.MONTH, startMonth );
startCal.set( Calendar.DAY_OF_MONTH, 1 );
+ if ( startMonth == 0 && startCal.get( Calendar.WEEK_OF_YEAR ) > 1 )
+ {
+ int[] newValues = getValueFromCal( startCal, levels );
+ TimeMember newMember = new TimeMember( newValues, levels );
+ list.add( newMember );
+ startCal.add( Calendar.WEEK_OF_YEAR, 1 );
+ }
startWeek = startCal.get( Calendar.WEEK_OF_YEAR );
}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/PreviousNPeriodsFunction.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/PreviousNPeriodsFunction.java
index 890dc2c..a76bcd9 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/PreviousNPeriodsFunction.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/PreviousNPeriodsFunction.java
@@ -55,7 +55,6 @@ public class PreviousNPeriodsFunction extends AbstractMDX implements IParallelPe
else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK ) )
cal.add( Calendar.DAY_OF_WEEK, offset );
- setReferenceDate( new ReferenceDate( cal.getTime( ) ));
int[] newValues = getValueFromCal( cal, levels );
TimeMember newMember = new TimeMember( newValues, levels );
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeMemberUtil.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeMemberUtil.java
index e09d8b3..83d3737 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeMemberUtil.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeMemberUtil.java
@@ -81,6 +81,10 @@ public class TimeMemberUtil
}
else if( TimeMember.TIME_LEVEL_TYPE_MONTH.equals( cellTimeMember.getLevelType()[i] ) )
{
+ // if level is month, and the reference date is 2011.3.31,
+ // the month is 2, so the date will set to 2011.2.31, the calendar will adapt the date to 2011.3
+ // here we set the month to 1.
+ cal.set( Calendar.DAY_OF_MONTH, 1 );
cal.set( Calendar.MONTH, cellTimeMember.getMemberValue()[i] - 1 );
}
else if( TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH.equals( cellTimeMember.getLevelType()[i] ) )