[CSHARP-1623] Add variants of $week, $year, $dayOfWeek that conform to the ISO-6801 spec* Created: 06/Apr/16  Updated: 27/May/22  Resolved: 25/Aug/16

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: None
Fix Version/s: 2.4

Type: New Feature Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-7695 Add variants of $week, $year, $dayOfW... Closed
is depended on by DRIVERS-297 Aggregation Framework Support for 3.4 Closed
Epic Link: MongoDB 3.4
Server Compat: 3.3

 Description   

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.



 Comments   
Comment by Githook User [ 29/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1623: add support for $dateToString.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/79853e2b37ad8c87501799379bb9f7a2a31d9086

Comment by Githook User [ 24/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1623: add support for $dateToString.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/79853e2b37ad8c87501799379bb9f7a2a31d9086

Comment by Githook User [ 21/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1623: add support for $dateToString.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/562988b1942eb9c9008d9346cb7e47ab5cfbd66a

Comment by Githook User [ 16/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1623: add support for $dateToString.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/7069b08bf8469b6a8becaaa1051107716e84725c

Comment by Githook User [ 31/Aug/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1623: add support for $dateToString.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/92f36bd08d7d988c414790538d04782712608210

Comment by Githook User [ 29/Aug/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1623: add support for $dateToString.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/6e41ce4bfc1af2f72511aa1375bd2d7c7c8bcf68

Comment by Githook User [ 25/Aug/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1623: add support for $dateToString.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/67254c5456e15004332a2ca495d770b14b9087af

Generated at Wed Feb 07 21:40:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.