Changeset 3129
- Timestamp:
- 04/25/08 08:27:55 (2 months ago)
- Files:
-
- trunk/Solar/Filter/ValidateIsoDate.php (modified) (2 diffs)
- trunk/Solar/Filter/ValidateIsoTime.php (modified) (2 diffs)
- trunk/Solar/Filter/ValidateIsoTimestamp.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Solar/Filter/ValidateIsoDate.php
r2926 r3129 25 25 * 26 26 */ 27 class Solar_Filter_ValidateIsoDate extends Solar_Filter_ Abstract{27 class Solar_Filter_ValidateIsoDate extends Solar_Filter_ValidateIsoTimestamp { 28 28 29 29 /** … … 41 41 public function validateIsoDate($value) 42 42 { 43 // look for Ymd keys? 44 if (is_array($value)) { 45 $value = $this->_arrayToDate($value); 46 } 47 43 48 if ($this->_filter->validateBlank($value)) { 44 49 return ! $this->_filter->getRequire(); trunk/Solar/Filter/ValidateIsoTime.php
r2926 r3129 25 25 * 26 26 */ 27 class Solar_Filter_ValidateIsoTime extends Solar_Filter_ Abstract{27 class Solar_Filter_ValidateIsoTime extends Solar_Filter_ValidateIsoTimestamp { 28 28 29 29 /** 30 30 * 31 31 * Validates that the value is an ISO 8601 time string (hh:ii::ss format). 32 * 33 * As an alternative, the value may be an array with all of the keys for 34 * `H`, `i`, and optionally `s`, in which case the value is 35 * converted to an ISO 8601 string before validating it. 32 36 * 33 37 * Per note from Chris Drozdowski about ISO 8601, allows two … … 42 46 public function validateIsoTime($value) 43 47 { 48 // look for His keys? 49 if (is_array($value)) { 50 $value = $this->_arrayToTime($value); 51 } 52 44 53 $expr = '/^(([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]$/D'; 45 54 trunk/Solar/Filter/ValidateIsoTimestamp.php
r2926 r3129 32 32 * 33 33 * The format is "yyyy-mm-ddThh:ii:ss" (note the literal "T" in the 34 * middle, which acts as a separator -- may also be a space). 34 * middle, which acts as a separator -- may also be a space). As an 35 * alternative, the value may be an array with all of the keys for 36 * `Y, m, d, H, i`, and optionally `s`, in which case the value is 37 * converted to an ISO 8601 string before validating it. 35 38 * 36 39 * Also checks that the date itself is valid (for example, no Feb 30). … … 43 46 public function validateIsoTimestamp($value) 44 47 { 48 // look for YmdHis keys? 49 if (is_array($value)) { 50 $value = $this->_arrayToTimestamp($value); 51 } 52 45 53 if ($this->_filter->validateBlank($value)) { 46 54 return ! $this->_filter->getRequire(); … … 73 81 return true; 74 82 } 83 84 /** 85 * 86 * Converts an array of timestamp parts to a string timestamp. 87 * 88 * @var array $array The array of timestamp parts. 89 * 90 * @return string 91 * 92 */ 93 protected function _arrayToTimestamp($array) 94 { 95 $value = $this->_arrayToDate($array) 96 . ' ' 97 . $this->_arrayToTime($array); 98 99 return trim($value); 100 } 101 102 /** 103 * 104 * Converts an array of date parts to a string date. 105 * 106 * @var array $array The array of date parts. 107 * 108 * @return string 109 * 110 */ 111 protected function _arrayToDate($array) 112 { 113 $date = array_key_exists('Y', $array) && 114 trim($array['Y']) != '' && 115 array_key_exists('m', $array) && 116 trim($array['m']) != '' && 117 array_key_exists('d', $array) && 118 trim($array['d']) != ''; 119 120 if (! $date) { 121 return; 122 } 123 124 return $array['Y'] . '-' 125 . $array['m'] . '-' 126 . $array['d']; 127 } 128 129 /** 130 * 131 * Converts an array of time parts to a string time. 132 * 133 * @var array $array The array of time parts. 134 * 135 * @return string 136 * 137 */ 138 protected function _arrayToTime($array) 139 { 140 $time = array_key_exists('H', $array) && 141 trim($array['H']) != '' && 142 array_key_exists('i', $array) && 143 trim($array['i']) != ''; 144 145 if (! $time) { 146 return; 147 } 148 149 $s = array_key_exists('s', $array) && trim($array['s']) != '' 150 ? $array['s'] 151 : '00'; 152 153 return $array['H'] . ':' 154 . $array['i'] . ':' 155 . $s; 156 } 75 157 }
