File: nsdate-formatter.rst

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (73 lines) | stat: -rw-r--r-- 3,756 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
.. title:: clang-tidy - objc-nsdate-formatter

objc-nsdate-formatter
=====================

When ``NSDateFormatter`` is used to convert an ``NSDate`` type to a ``String`` type, the user
can specify a custom format string. Certain format specifiers are undesirable
despite being legal. See http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns for all legal date patterns.

This checker reports as warnings the following string patterns in a date format specifier:

#. yyyy + ww : Calendar year specified with week of a week year (unless YYYY is also specified).
  
   * | **Example 1:** Input Date: `29 December 2014` ; Format String: `yyyy-ww`; 
     | Output string: `2014-01` (Wrong because it’s not the first week of 2014)
    
   * | **Example 2:** Input Date: `29 December 2014` ; Format String: `dd-MM-yyyy (ww-YYYY)`; 
     | Output string: `29-12-2014 (01-2015)` (This is correct)
    
#. F without ee/EE : Numeric day of week in a month without actual day.
    
   * | **Example:** Input Date: `29 December 2014` ; Format String: `F-MM`; 
     | Output string: `5-12` (Wrong because it reads as *5th ___ of Dec* in English)
    
#. F without MM : Numeric day of week in a month without month.
   
   * | **Example:** Input Date: `29 December 2014` ; Format String: `F-EE`
     | Output string: `5-Mon` (Wrong because it reads as *5th Mon of ___* in English)
    
#. WW without MM : Week of the month without the month.
   
   * | **Example:** Input Date: `29 December 2014` ; Format String: `WW-yyyy`
     | Output string: `05-2014` (Wrong because it reads as *5th Week of ___* in English)
    
#. YYYY + QQ : Week year specified with quarter of normal year (unless yyyy is also specified).
   
   * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-QQ`
     | Output string: `2015-04` (Wrong because it’s not the 4th quarter of 2015)
    
   * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (QQ-yyyy)`
     | Output string: `01-2015 (04-2014)` (This is correct)
    
#. YYYY + MM :  Week year specified with Month of a calendar year (unless yyyy is also specified).
    
   * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-MM`
     | Output string: `2015-12` (Wrong because it’s not the 12th month of 2015)
    
   * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (MM-yyyy)`
     | Output string: `01-2015 (12-2014)` (This is correct)
    
#. YYYY + DD : Week year with day of a calendar year (unless yyyy is also specified).
    
   * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-DD`
     | Output string: `2015-363` (Wrong because it’s not the 363rd day of 2015)
    
   * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (DD-yyyy)`
     | Output string: `01-2015 (363-2014)` (This is correct)
    
#. YYYY + WW : Week year with week of a calendar year (unless yyyy is also specified).
    
   * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-WW`
     | Output string: `2015-05` (Wrong because it’s not the 5th week of 2015)
    
   * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (WW-MM-yyyy)`
     | Output string: `01-2015 (05-12-2014)` (This is correct)
    
#. YYYY + F : Week year with day of week in a calendar month (unless yyyy is also specified).
    
   * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-ww-F-EE`
     | Output string: `2015-01-5-Mon` (Wrong because it’s not the 5th Monday of January in 2015)
    
   * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (F-EE-MM-yyyy)`
     | Output string: `01-2015 (5-Mon-12-2014)` (This is correct)