Monday, 3 February 2014

DateHelper (date_format) in symfony

DateHelper (date_format) in symfony


DateHelper has a particular function format_date which is quite good for formatting dates, esp that come straight from the propel object. However looking at the Helper file DateHelper.php you cant really tell what sort of formats does it accept and no it doesnt take the standard PHP date formats.
Digging a little further I found the details in another file sfDateFormat.class.php and as the class states.

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
   switch ($pattern)
    {
      case 'd':
        return $this->formatInfo->ShortDatePattern;
        break;
      case 'D':
        return $this->formatInfo->LongDatePattern;
        break;
      case 'p':
        return $this->formatInfo->MediumDatePattern;
        break;
      case 'P':
        return $this->formatInfo->FullDatePattern;
        break;        
      case 't':
        return $this->formatInfo->ShortTimePattern;
        break;
      case 'T':
        return $this->formatInfo->LongTimePattern;
        break;
      case 'q':
        return $this->formatInfo->MediumTimePattern;
        break;
      case 'Q':
        return $this->formatInfo->FullTimePattern;
        break;
      case 'f':
        return $this->formatInfo->formatDateTime($this->formatInfo->LongDatePattern, $this->formatInfo->ShortTimePattern);
        break;
      case 'F':
        return $this->formatInfo->formatDateTime($this->formatInfo->LongDatePattern, $this->formatInfo->LongTimePattern);
        break;
      case 'g':
        return $this->formatInfo->formatDateTime($this->formatInfo->ShortDatePattern, $this->formatInfo->ShortTimePattern);
        break;
      case 'G':
        return $this->formatInfo->formatDateTime($this->formatInfo->ShortDatePattern, $this->formatInfo->LongTimePattern);
        break;
      case 'i':
        return 'yyyy-MM-dd';
        break;
      case 'I':
        return 'yyyy-MM-dd HH:mm:ss';
        break;
      case 'M':
      case 'm':
        return 'MMMM dd';
        break;
      case 'R':
      case 'r':
        return 'EEE, dd MMM yyyy HH:mm:ss';
        break;
      case 's':
        return 'yyyy-MM-ddTHH:mm:ss';
        break;
      case 'u':
        return 'yyyy-MM-dd HH:mm:ss z';
        break;
      case 'U':
        return 'EEEE dd MMMM yyyy HH:mm:ss';
        break;
      case 'Y':
      case 'y':
        return 'yyyy MMMM';
        break;
      default :
        return $pattern;
    }

No comments:

Post a Comment