Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6190

$week operator does not conform to spec when first day of the year is a sunday

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.0-rc0
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None

      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 );
      

            Assignee:
            aaron Aaron Staple
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: