Repository navigation
Expand file tree
/
Copy pathDate.php
More file actions
162 lines (150 loc) · 4.33 KB
/
Copy pathDate.php
File metadata and controls
162 lines (150 loc) · 4.33 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Google_Format_Date
* @author Thomas Schaefer
* @copyright Thomas Schaefer
* @since 2009-05-20
* @desc Formats a JavaScript Date value in a variety of ways, including
* "January 1, 2009," "1/1/09" and "Jan 1, 2009.
*
*/
/**
* Google_Format_Date
* @author Thomas Schaefer
* @copyright Thomas Schaefer
* @since 2009-05-20
* @desc Formats a JavaScript Date value in a variety of ways, including
* "January 1, 2009," "1/1/09" and "Jan 1, 2009.
* {@example test_google_vis_table_date.php}
*
*/
class Google_Format_Date extends Google_Format implements Google_Format_Interface {
/**
* @var string $provider
*/
private $provider = 'google';
/**
* @var string $scope
*/
private $scope = 'visualization';
/**
* @var string $type
*/
private $type = 'DateFormat';
/**
* @var string $dataTable
*/
private $dataTable = 'data';
/**
* @var integer $srcColumnIndices
*/
private $srcColumnIndices = 0;
/**
* @var string $prefix
*/
private $prefix = '';
/**
* @var array $properties
*/
protected $properties;
/**
* constructor
* @param string $prefix
*/
public function __construct($prefix='') {
$this->prefix = '_'.$prefix;
$this->properties = new stdClass;
}
/**
* desc The standard format() method to apply formatting to the specified
* column.
* @param string $dataTable
* @param integer $srcColumnIndices
*/
public function format($dataTable, $srcColumnIndices) {
if(is_string($dataTable)) {
$this->dataTable = $dataTable;
} else {
$e = new Google_Exception_Format("Expecting a parameter of type string. (transfered type: ". gettype($pattern).')');
$e->show();
}
if(is_integer($srcColumnIndices) or is_array($srcColumnIndices) ) {
$this->srcColumnIndices = $srcColumnIndices;
} else {
$e = new Google_Exception_Format("source column is expecting a parameter of type integer or array of integers. (transfered type: ". gettype($pattern).')');
$e->show();
}
}
/**
* formatType
* @desc A quick formatting option for the date. The following string values
* are supported, reformatting the date February 28, 2008 as shown:
* 'short' - Short format: e.g., "2/28/08"
* 'medium' - Medium format: e.g., "Feb 28, 2008"
* 'long' - Long format: e.g., "February 28, 2008"
* You cannot specify both formatType and pattern.
*
* @param string $column short|medium|long
* @return void
*/
public function formatType($formatType='short') {
switch($formatType){
case "short":
case "medium":
case "long":
$this->properties->formatType = (string)$formatType;
break;
}
}
/**
* pattern
*
* @desc A custom format pattern to apply to the value, similar to the ICU
* date and time format.
* You cannot specify both formatType and pattern.
* @example
* <code>
* var formatter3 = new google.visualization.DateFormat({pattern: "EEE, MMM d, ''yy"});
* </code>
* @see http://code.google.com/intl/de-DE/apis/visualization/documentation/reference.html#dateformatter
* @param string $pattern
* @return void
*/
public function pattern($pattern) {
$this->properties->pattern = $pattern;
}
/**
* timezone
* @desc The time zone in which to display the date value. This is a numeric
* value, indicating GMT + this number of time zones (can be negative). Date
* object are created by default with the assumed time zone of the computer
* on which they are created; this option is used to display that value in a
* different time zone. For example, if you created a Date object of 5pm noon
* on a computer located in Greenwich, England, and specified timeZone to be
* -5 (options['timeZone'] = -5, or Eastern Pacific Time in the US), the value
* displayed would be 12 noon.
*
* @param integer $timeZone
* @return void
*/
public function timezone($timeZone) {
$this->properties->timeZone = (int) $timeZone;
}
/**
* @desc table date formatter template
* @return string
*/
public function __toString() {
$string = 'var formatter'.$this->prefix.'=new ';
$string .= $this->provider;
$string .= '.';
$string .= $this->scope;
$string .= '.';
$string .= $this->type;
$string .= '('.(!empty($this->properties)?Google_Base::toJson($this->properties):'').');';
$string .= "\n";
$string .= 'formatter'.$this->prefix.'.format('.$this->dataTable.', '.$this->srcColumnIndices.');';
$string .= "\n";
return $string;
}
}