Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1623

Add variants of $week, $year, $dayOfWeek that conform to the ISO-6801 spec*

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4
    • Affects Version/s: None
    • Component/s: Linq
    • None

      We've decided to add the following operators:

      • $isoWeek
      • $isoDayOfWeek
      • $isoYear

      And to add the corresponding substitutions "%G", "%V", and "%u" to the $dateToString expression.

      Example

      Input

      {_id: 0, date: ISODate("2016-01-01T00:00:00Z")}  // Thu, Jan 1, 2016
      

      Pipeline

      db.coll.aggregate([{
          $project: {
              dayOfWeek: {$dayOfWeek: "$date"},
              isoDayOfWeek: {$isoDayOfWeek: "$date"},
              year: {$year: "$date"},
              isoYear: {$isoYear: "$date"},
              week: {$week: "$date"},
              isoWeek: {$isoWeek: "$date"},
              isoString: {$dateToString: {format: "%G-W%V-%u", date: "$date"}}
          }
      }])
      

      Output

      {
        _id: 0,
        dayOfWeek: 6,  // 1 is Sunday, 7 is Saturday
        isoDayOfWeek: 5,  // 1 is Monday, 7 is Sunday
        year: 2016,
        isoYear: 2015,  // 2016 starts on Jan 4th under ISO calendar.
        week: 0,
        isoWeek: 53,
        isoString: "2015-W53-5"  // $dateToString is also modified to support
                                 // the concepts above.
      }
      

      Additional Notes

      Original Description

      It would be very useful for $week to have an option to start from Monday. Get it from current locale, is first that came in my mind.

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            rathi.gnanasekaran Rathi Gnanasekaran
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: