96 lines · plain
1.. title:: clang-tidy - objc-nsdate-formatter2 3objc-nsdate-formatter4=====================5 6When ``NSDateFormatter`` is used to convert an ``NSDate`` type to a ``String``7type, the user can specify a custom format string. Certain format specifiers8are undesirable despite being legal.9See http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns10for all legal date patterns.11 12This checker reports as warnings the following string patterns in a date13format specifier:14 15#. yyyy + ww : Calendar year specified with week of a week year16 (unless YYYY is also specified).17 18 * | **Example 1:** Input Date: `29 December 2014` ;19 | Format String: `yyyy-ww`;20 | Output string: `2014-01` (Wrong because it’s not the first week of 2014)21 22 * | **Example 2:** Input Date: `29 December 2014` ;23 | Format String: `dd-MM-yyyy (ww-YYYY)`;24 | Output string: `29-12-2014 (01-2015)` (This is correct)25 26#. F without ee/EE : Numeric day of week in a month without actual day.27 28 * | **Example:** Input Date: `29 December 2014` ; Format String: `F-MM`;29 | Output string: `5-12` (Wrong because it reads as *5th ___ of Dec* in30 | English)31 32#. F without MM : Numeric day of week in a month without month.33 34 * | **Example:** Input Date: `29 December 2014` ; Format String: `F-EE`35 | Output string: `5-Mon` (Wrong because it reads as *5th Mon of ___* in36 | English)37 38#. WW without MM : Week of the month without the month.39 40 * | **Example:** Input Date: `29 December 2014` ; Format String: `WW-yyyy`41 | Output string: `05-2014` (Wrong because it reads as *5th Week of ___* in42 | English)43 44#. YYYY + QQ : Week year specified with quarter of normal year45 (unless yyyy is also specified).46 47 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-QQ`48 | Output string: `2015-04` (Wrong because it’s not the 4th quarter of49 | 2015)50 51 * | **Example 2:** Input Date: `29 December 2014` ;52 | Format String: `ww-YYYY (QQ-yyyy)`53 | Output string: `01-2015 (04-2014)` (This is correct)54 55#. YYYY + MM : Week year specified with Month of a calendar year56 (unless yyyy is also specified).57 58 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-MM`59 | Output string: `2015-12` (Wrong because it’s not the 12th month of 2015)60 61 * | **Example 2:** Input Date: `29 December 2014` ;62 | Format String: `ww-YYYY (MM-yyyy)`63 | Output string: `01-2015 (12-2014)` (This is correct)64 65#. YYYY + DD : Week year with day of a calendar year66 (unless yyyy is also specified).67 68 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-DD`69 | Output string: `2015-363` (Wrong because it’s not the 363rd day of 2015)70 71 * | **Example 2:** Input Date: `29 December 2014` ;72 | Format String: `ww-YYYY (DD-yyyy)`73 | Output string: `01-2015 (363-2014)` (This is correct)74 75#. YYYY + WW : Week year with week of a calendar year76 (unless yyyy is also specified).77 78 * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-WW`79 | Output string: `2015-05` (Wrong because it’s not the 5th week of 2015)80 81 * | **Example 2:** Input Date: `29 December 2014` ;82 | Format String: `ww-YYYY (WW-MM-yyyy)`83 | Output string: `01-2015 (05-12-2014)` (This is correct)84 85#. YYYY + F : Week year with day of week in a calendar month86 (unless yyyy is also specified).87 88 * | **Example 1:** Input Date: `29 December 2014` ;89 | Format String: `YYYY-ww-F-EE`90 | Output string: `2015-01-5-Mon` (Wrong because it’s not the 5th Monday of91 | January in 2015)92 93 * | **Example 2:** Input Date: `29 December 2014` ;94 | Format String: `ww-YYYY (F-EE-MM-yyyy)`95 | Output string: `01-2015 (5-Mon-12-2014)` (This is correct)96