Framework  3.9
timestamp_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 
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  * default format: date("Y-m-d H:i:s", strtotime($data));
54  * examples:
55  * 1) {my_timestamp:m/d/Y g:ia} returns 2/12/2011 12:30am
56  * 2) {my_datetime:l F j, Y g:ia} returns long format Monday February 12, 2011 12:30am
57  * 3) {my_datetime:F d, Y g:ia} returns February 12, 2011 12:30am
58  *
59  * Template shorthand:
60  * {my_timestamp:short} - returns format 1 above
61  * {my_timestamp:daylong} = returns format 2 above
62  * {my_timestamp:long} - returns format 3 above
63  */
64  static function format($timestamp, $template = "")
65  {
66  trace("TimestampTypeRenderer template is $template and value is $timestamp", 5);
67 
68  $text = "";
69 
70  if (!$timestamp) return "N/A";
71 
72  // This default is needed for XML transation but is not
73  // a user-readable format.
74  elseif($timestamp && !$template)
75  $template = "Y-m-d H:i:s";
76 
77  $template = AbstractTypeRenderer::translationDateTemplate($template);
78 
79  if($timestamp)
80  {
81  $dateObj = new DateTime($timestamp);
82  $text = $dateObj->format($template);
83 
84  }
85  return $text;
86  /*
87  if (preg_match("/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$/", $timestamp))
88  {
89  $timestamp = preg_replace("/\\D/", "", $timestamp);
90  }
91 
92  if (preg_match("/^\\d{14}$/", $timestamp))
93  {
94  $yyyy = substr($timestamp,0,4);
95  $mm = substr($timestamp,4,2);
96  $dd = substr($timestamp,6,2);
97  $hh = substr($timestamp,8,2);
98  $mi = substr($timestamp,10,2);
99  $ss = substr($timestamp,12,2);
100 
101  if ($yyyy == '0000')
102  $text = "N/A";
103 
104  if($timestamp)
105  $text = date($template, mktime($hh,$mi,$ss,$mm,$dd,$yyyy));
106  }
107  else
108  {
109  $text = date($template, strftime($timestamp));
110  }*/
111 
112  return $text;
113  }
114 }
115 
static translationDateTemplate($template, $includeTime=true)
static format($timestamp, $template="")
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010