| author | pshi | 2011-11-27 22:40:57 (EST) |
|---|---|---|
| committer | mwu | 2011-11-27 22:40:57 (EST) |
| commit | 5263ecd05e1586b0533c8d7bd54b94392c45efa2 (patch) (side-by-side diff) | |
| tree | f53c33f3c321418a383f4cfbec902d159797b8ba | |
| parent | 3fcea111db6ae4b8684896799ee4f82f4dba2dff (diff) | |
| download | org.eclipse.birt-5263ecd05e1586b0533c8d7bd54b94392c45efa2.zip org.eclipse.birt-5263ecd05e1586b0533c8d7bd54b94392c45efa2.tar.gz org.eclipse.birt-5263ecd05e1586b0533c8d7bd54b94392c45efa2.tar.bz2 | |
fix bug 45553, the week to date function has some bugs when the week
across month or year, update some unit test
9 files changed, 84 insertions, 13 deletions
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD9.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD9.txt index c800e48..970e143 100644 --- a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD9.txt +++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD9.txt @@ -6,3 +6,5 @@ year quarter month week-of-month 2011 4 10 3
year quarter month week-of-month
2011 4 10 4
+year quarter month week-of-month
+2011 4 10 5
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/QuarterToDateFunctionTest.testFunctions4.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/QuarterToDateFunctionTest.testFunctions4.txt index 97ebecb..bbbc27a 100644 --- a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/QuarterToDateFunctionTest.testFunctions4.txt +++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/QuarterToDateFunctionTest.testFunctions4.txt @@ -1,8 +1,8 @@ -2002 3 7 1 +2002 2 6 5 2002 3 7 2 2002 3 7 3 2002 3 7 4 -2002 3 8 0 +2002 3 7 5 2002 3 8 1 2002 3 8 2 -2002 3 8 3
\ No newline at end of file +2002 3 8 3 diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/QuarterToDateFunctionTest.testFunctions5.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/QuarterToDateFunctionTest.testFunctions5.txt index 13c803b..eebf8bc 100644 --- a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/QuarterToDateFunctionTest.testFunctions5.txt +++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/QuarterToDateFunctionTest.testFunctions5.txt @@ -1,8 +1,8 @@ -2002 3 7 1 +2002 2 6 5 2002 3 7 2 2002 3 7 3 2002 3 7 4 -2002 3 8 0 +2002 3 7 5 2002 3 8 1 2002 3 8 2 2002 3 8 3 @@ -10,4 +10,5 @@ 2002 3 9 1 2002 3 9 2 2002 3 9 3 -2002 3 9 4
\ No newline at end of file +2002 3 9 4 +2002 3 9 5 diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing13.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing13.txt index 50e3d1b..a3ddd3d 100644 --- a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing13.txt +++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing13.txt @@ -7,7 +7,7 @@ year quarter month week-of-month week-of-year year quarter month week-of-month week-of-year
2011 3 9 1 36
year quarter month week-of-month week-of-year
-2011 3 9 0 35
+2011 3 8 5 35
year quarter month week-of-month week-of-year
2011 3 8 4 34
year quarter month week-of-month week-of-year
@@ -15,7 +15,7 @@ year quarter month week-of-month week-of-year year quarter month week-of-month week-of-year
2011 3 8 2 32
year quarter month week-of-month week-of-year
-2011 3 8 1 31
+2011 3 7 5 31
year quarter month week-of-month week-of-year
2011 3 7 4 30
year quarter month week-of-month week-of-year
@@ -24,3 +24,5 @@ year quarter month week-of-month week-of-year 2011 3 7 2 28
year quarter month week-of-month week-of-year
2011 3 7 1 27
+year quarter month week-of-month week-of-year
+2011 2 6 5 26
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 3efb90e..506d94e 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 @@ -37,6 +37,8 @@ abstract public class AbstractMDX int[] values )
{
String type = "";
+ int year_woy = 1;
+ int year = 1;
for ( int i = 0; i < values.length; i++ )
{
if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) )
@@ -61,15 +63,31 @@ abstract public class AbstractMDX else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) )
{
- cal.get( Calendar.WEEK_OF_MONTH );
+ year_woy = cal.get( Calendar.YEAR_WOY );
+ year = cal.get( Calendar.YEAR );
+ // year_woy < year, means last week of previous year
+ // for example. 2011/1/1, the year_woy is 2010
+ if ( year_woy < year )
+ {
+ cal.add( Calendar.DAY_OF_WEEK, 7 );
+ }
+ cal.set( Calendar.DAY_OF_WEEK, 1 );
cal.set( Calendar.WEEK_OF_MONTH, values[i] );
+
type = WEEK;
}
else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR ) )
{
- cal.get( Calendar.WEEK_OF_YEAR );
+ year_woy = cal.get( Calendar.YEAR_WOY );
+ year = cal.get( Calendar.YEAR );
+ if ( year_woy < year )
+ {
+ cal.add( Calendar.DAY_OF_WEEK, 7 );
+ }
+ cal.set( Calendar.DAY_OF_WEEK, 1 );
cal.set( Calendar.WEEK_OF_YEAR, values[i] );
+
type = WEEK;
}
else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK ) )
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateFunction.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateFunction.java index 1876eae..90c75b4 100644 --- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateFunction.java +++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateFunction.java @@ -37,7 +37,6 @@ public class MonthToDateFunction extends AbstractMDX Calendar cal = new GregorianCalendar( TimeMemberUtil.getTimeZone( ),
TimeMemberUtil.getDefaultLocale( ) );
cal.clear( );
- cal.set( Calendar.DAY_OF_MONTH, 28 );
String baseType = translateToCal( cal, levelTypes, values );
int[] tmp;
if ( baseType.equals( MONTH ) )
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 c0bb306..a4742af 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 @@ -34,6 +34,7 @@ public class PreviousNPeriodsFunction extends AbstractMDX implements IParallelPe Calendar cal = new GregorianCalendar( TimeMemberUtil.getTimeZone( ),
TimeMemberUtil.getDefaultLocale( ) );
+ cal.clear( );
translateToCal( cal, levels, values );
if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) )
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingFunction.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingFunction.java index 06243f1..ff9ae24 100644 --- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingFunction.java +++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingFunction.java @@ -44,7 +44,9 @@ public class TrailingFunction extends AbstractMDX implements IPeriodsFunction cal1.clear( );
String calculateUnit = translateToCal( cal1, levelTypes, values );
Calendar cal2 = (Calendar) cal1.clone( );
-
+ int dayOfWeek = 1;
+ int year = 1;
+ int year_woy = 1;
if ( levelType.equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) )
{
cal1.add( Calendar.YEAR, offset );
@@ -60,10 +62,42 @@ public class TrailingFunction extends AbstractMDX implements IPeriodsFunction }
else if ( levelType.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) )
{
+ if ( !calculateUnit.equals( DAY ) )
+ {
+ year_woy = cal1.get( Calendar.YEAR_WOY );
+ year = cal1.get( Calendar.YEAR );
+ // year_woy < year, means last week of previous year
+ // for example. 2011/1/1, the year_woy is 2010
+ if ( year_woy < year )
+ {
+ cal1.add( Calendar.DAY_OF_WEEK, 7 );
+ }
+ dayOfWeek = cal1.get( Calendar.DAY_OF_WEEK );
+ if ( dayOfWeek > 1 )
+ {
+ cal1.add( Calendar.DAY_OF_WEEK, 1 - dayOfWeek );
+ }
+ }
cal1.add( Calendar.WEEK_OF_YEAR, offset );
}
else if ( levelType.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR ) )
{
+ if ( !calculateUnit.equals( DAY ) )
+ {
+ year_woy = cal1.get( Calendar.YEAR_WOY );
+ year = cal1.get( Calendar.YEAR );
+ // year_woy < year, means last week of previous year
+ // for example. 2011/1/1, the year_woy is 2010
+ if ( year_woy < year )
+ {
+ cal1.add( Calendar.DAY_OF_WEEK, 7 );
+ }
+ dayOfWeek = cal1.get( Calendar.DAY_OF_WEEK );
+ if ( dayOfWeek > 1 )
+ {
+ cal1.add( Calendar.DAY_OF_WEEK, 1 - dayOfWeek );
+ }
+ }
cal1.add( Calendar.WEEK_OF_YEAR, offset );
}
else if ( levelType.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH ) )
@@ -78,7 +112,7 @@ public class TrailingFunction extends AbstractMDX implements IPeriodsFunction {
cal1.add( Calendar.DATE, offset );
}
-
+
timeMembers.add( member );
// TimeMember.levelTypes=["year"(2009),"month"(3)],TrailingFunciton.levelType="Quarter",offset=1
@@ -96,6 +130,19 @@ public class TrailingFunction extends AbstractMDX implements IPeriodsFunction }
else if ( calculateUnit.equals( WEEK ) )
{
+ year_woy = cal1.get( Calendar.YEAR_WOY );
+ year = cal1.get( Calendar.YEAR );
+ // year_woy < year, means last week of previous year
+ // for example. 2011/1/1, the year_woy is 2010
+ if ( year_woy < year )
+ {
+ cal1.add( Calendar.DAY_OF_WEEK, 7 );
+ }
+ dayOfWeek = cal1.get( Calendar.DAY_OF_WEEK );
+ if ( dayOfWeek > 1 )
+ {
+ cal1.add( Calendar.DAY_OF_WEEK, 1 - dayOfWeek );
+ }
cal1.add( Calendar.WEEK_OF_YEAR, -Math.abs( offset ) / offset );
}
else if ( calculateUnit.equals( MONTH ) )
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateFunciton.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateFunciton.java index 634bfe5..320bc95 100644 --- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateFunciton.java +++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateFunciton.java @@ -32,6 +32,7 @@ public class WeekToDateFunciton extends AbstractMDX implements IPeriodsFunction Calendar cal = new GregorianCalendar( TimeMemberUtil.getTimeZone( ),
TimeMemberUtil.getDefaultLocale( ) );
+ cal.clear( );
String baseType = translateToCal( cal, levelTypes, values );
if ( baseType.equals( WEEK ) )
|

