Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
None
Description
Observed behavior: The documentation says that $week will be 0 for days before the first sunday of the year. However, if the first day of the year is a sunday $week is implemented to be 0 for days before the second sunday of the year.
Expected behavior: $week is 0 for days before the first sunday of the year, as described in the documentation.
Test:
c = db.c;
|
c.drop();
|
|
|
// Sunday Jan 1 1984
|
sun = new Date( 1984, 0, 1 );
|
assert.eq( 1984, sun.getFullYear() );
|
assert.eq( 0, sun.getMonth() );
|
assert.eq( 1, sun.getDate() );
|
assert.eq( 0, sun.getDay() );
|
|
|
// Monday Jan 2 1984
|
mon = new Date( 1984, 0, 2 );
|
assert.eq( 1984, mon.getFullYear() );
|
assert.eq( 0, mon.getMonth() );
|
assert.eq( 2, mon.getDate() );
|
assert.eq( 1, mon.getDay() );
|
|
|
c.save( {} );
|
|
|
// These dates are not before the first sunday of the year and are expected to be in week 1.
|
assert.eq( 1, c.aggregate( { $project:{ a:{ $week:[ sun ] } } } ).result[ 0 ].a );
|
assert.eq( 1, c.aggregate( { $project:{ a:{ $week:[ mon ] } } } ).result[ 0 ].a );
|