Framework  3.9
date_type_renderer.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8  Copyright (c) 2007-2010 Sonjara, Inc
9 
10  Permission is hereby granted, free of charge, to any person
11  obtaining a copy of this software and associated documentation
12  files (the "Software"), to deal in the Software without
13  restriction, including without limitation the rights to use,
14  copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following
17  conditions:
18 
19  The above copyright notice and this permission notice shall be
20  included in all copies or substantial portions of the Software.
21 
22  Except as contained in this notice, the name(s) of the above
23  copyright holders shall not be used in advertising or otherwise
24  to promote the sale, use or other dealings in this Software
25  without prior written authorization.
26 
27  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
29  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34  OTHER DEALINGS IN THE SOFTWARE.
35 
36 *****************************************************************/
37 
38 require_once realpath(dirname(__FILE__)."/abstract_type_renderer.inc");
39 
41 {
42 
43  function DateTypeRenderer()
44  {
45  }
46 
47  /*
48  * If no template, use formatDateShort, otherwise,
49  * format using template provided the date function:
50  *
51  * http://php.net/manual/en/function.date.php
52  *
53  * examples:
54  * {my_date:m/d/Y} returns the default 2/12/11
55  * {my_date:l F j, Y} returns long format Monday February 12, 2011
56  * {my_date:F d, Y} returns February 12, 2011
57  *
58  * Template shorthand:
59  * {my_date:short} - returns format 1 above
60  * {my_date:daylong} = returns format 2 above
61  * {my_date:long} - returns format 3 above
62  *
63  */
64  static function format($date, $template = "")
65  {
66  $text = "";
67 
68  if($date && !$template)
69  $template = "m/d/Y";
70  $template = AbstractTypeRenderer::translationDateTemplate($template, false);
71 
72  // Blank for zero dates
73  if (!strncmp("0000-00-00", $date, 10)) return "";
74 
75  if($date)
76  {
77  $dateObj = new DateTime($date);
78  $text = $dateObj->format($template);
79  }
80 
81  // return blank if no date
82  return $text;
83  }
84 }
85 
static translationDateTemplate($template, $includeTime=true)
static format($date, $template="")