[DOCS-9548] Docs for SERVER-7695: Add variants of $week, $year, $dayOfWeek that conform to the ISO-6801 spec Created: 05/Dec/16  Updated: 08/Dec/17  Resolved: 08/Dec/17

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Emily Hall Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: delete-docs-tickets, expression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-7695 Add variants of $week, $year, $dayOfW... Closed
Participants:
Days since reply: 6 years, 9 weeks, 5 days ago

 Description   

Engineering Ticket Description:

We've decided to add the following operators:

  • $isoWeek
  • $isoDayOfWeek
  • $isoWeekYear

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: {$isoWeekYear: "$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 Kay Kim (Inactive) [ 08/Dec/17 ]

bulk closing duplicate tickets created after work was done.

Generated at Thu Feb 08 07:58:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.