1.. title:: clang-tidy - objc-nsdate-formatter 2 3objc-nsdate-formatter 4===================== 5 6When ``NSDateFormatter`` is used to convert an ``NSDate`` type to a ``String`` type, the user 7can specify a custom format string. Certain format specifiers are undesirable 8despite being legal. See http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns for all legal date patterns. 9 10This checker reports as warnings the following string patterns in a date format specifier: 11 12#. yyyy + ww : Calendar year specified with week of a week year (unless YYYY is also specified). 13 14 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `yyyy-ww`; 15 | Output string: `2014-01` (Wrong because it’s not the first week of 2014) 16 17 * | **Example 2:** Input Date: `29 December 2014` ; Format String: `dd-MM-yyyy (ww-YYYY)`; 18 | Output string: `29-12-2014 (01-2015)` (This is correct) 19 20#. F without ee/EE : Numeric day of week in a month without actual day. 21 22 * | **Example:** Input Date: `29 December 2014` ; Format String: `F-MM`; 23 | Output string: `5-12` (Wrong because it reads as *5th ___ of Dec* in English) 24 25#. F without MM : Numeric day of week in a month without month. 26 27 * | **Example:** Input Date: `29 December 2014` ; Format String: `F-EE` 28 | Output string: `5-Mon` (Wrong because it reads as *5th Mon of ___* in English) 29 30#. WW without MM : Week of the month without the month. 31 32 * | **Example:** Input Date: `29 December 2014` ; Format String: `WW-yyyy` 33 | Output string: `05-2014` (Wrong because it reads as *5th Week of ___* in English) 34 35#. YYYY + QQ : Week year specified with quarter of normal year (unless yyyy is also specified). 36 37 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-QQ` 38 | Output string: `2015-04` (Wrong because it’s not the 4th quarter of 2015) 39 40 * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (QQ-yyyy)` 41 | Output string: `01-2015 (04-2014)` (This is correct) 42 43#. YYYY + MM : Week year specified with Month of a calendar year (unless yyyy is also specified). 44 45 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-MM` 46 | Output string: `2015-12` (Wrong because it’s not the 12th month of 2015) 47 48 * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (MM-yyyy)` 49 | Output string: `01-2015 (12-2014)` (This is correct) 50 51#. YYYY + DD : Week year with day of a calendar year (unless yyyy is also specified). 52 53 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-DD` 54 | Output string: `2015-363` (Wrong because it’s not the 363rd day of 2015) 55 56 * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (DD-yyyy)` 57 | Output string: `01-2015 (363-2014)` (This is correct) 58 59#. YYYY + WW : Week year with week of a calendar year (unless yyyy is also specified). 60 61 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-WW` 62 | Output string: `2015-05` (Wrong because it’s not the 5th week of 2015) 63 64 * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (WW-MM-yyyy)` 65 | Output string: `01-2015 (05-12-2014)` (This is correct) 66 67#. YYYY + F : Week year with day of week in a calendar month (unless yyyy is also specified). 68 69 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-ww-F-EE` 70 | Output string: `2015-01-5-Mon` (Wrong because it’s not the 5th Monday of January in 2015) 71 72 * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (F-EE-MM-yyyy)` 73 | Output string: `01-2015 (5-Mon-12-2014)` (This is correct) 74