| Total Complexity | 103 |
| Total Lines | 486 |
| Duplicated Lines | 0 % |
| Coverage | 93.62% |
| Changes | 0 | ||
Complex classes like Date often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Date, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class Date |
||
| 29 | { |
||
| 30 | |||
| 31 | use AffixesTrait, |
||
| 32 | DisplayTrait, |
||
| 33 | FormattingTrait, |
||
| 34 | TextCaseTrait; |
||
| 35 | |||
| 36 | // ymd |
||
| 37 | const DATE_RANGE_STATE_NONE = 0; // 000 |
||
| 38 | const DATE_RANGE_STATE_DAY = 1; // 001 |
||
| 39 | const DATE_RANGE_STATE_MONTH = 2; // 010 |
||
| 40 | const DATE_RANGE_STATE_MONTHDAY = 3; // 011 |
||
| 41 | const DATE_RANGE_STATE_YEAR = 4; // 100 |
||
| 42 | const DATE_RANGE_STATE_YEARDAY = 5; // 101 |
||
| 43 | const DATE_RANGE_STATE_YEARMONTH = 6; // 110 |
||
| 44 | const DATE_RANGE_STATE_YEARMONTHDAY = 7; // 111 |
||
| 45 | |||
| 46 | private static $localizedDateFormats = [ |
||
| 47 | 'numeric', |
||
| 48 | 'text' |
||
| 49 | ]; |
||
| 50 | |||
| 51 | /** |
||
|
1 ignored issue
–
show
|
|||
| 52 | * @var ArrayList |
||
| 53 | */ |
||
| 54 | private $dateParts; |
||
| 55 | |||
| 56 | /** |
||
|
1 ignored issue
–
show
|
|||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private $form = ""; |
||
| 60 | |||
| 61 | /** |
||
|
1 ignored issue
–
show
|
|||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | private $variable = ""; |
||
| 65 | |||
| 66 | /** |
||
|
1 ignored issue
–
show
|
|||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | private $datePartsAttribute = ""; |
||
| 70 | |||
| 71 | 56 | public function __construct(\SimpleXMLElement $node) |
|
| 72 | { |
||
| 73 | 56 | $this->dateParts = new ArrayList(); |
|
| 74 | |||
| 75 | /** @var \SimpleXMLElement $attribute */ |
||
|
3 ignored issues
–
show
|
|||
| 76 | 56 | foreach ($node->attributes() as $attribute) { |
|
| 77 | 56 | switch ($attribute->getName()) { |
|
| 78 | 56 | case 'form': |
|
| 79 | 27 | $this->form = (string) $attribute; |
|
| 80 | 27 | break; |
|
| 81 | 56 | case 'variable': |
|
| 82 | 56 | $this->variable = (string) $attribute; |
|
| 83 | 56 | break; |
|
| 84 | 34 | case 'date-parts': |
|
| 85 | 56 | $this->datePartsAttribute = (string) $attribute; |
|
| 86 | } |
||
| 87 | } |
||
| 88 | /** @var \SimpleXMLElement $child */ |
||
|
3 ignored issues
–
show
|
|||
| 89 | 56 | foreach ($node->children() as $child) { |
|
| 90 | 43 | if ($child->getName() === "date-part") { |
|
| 91 | 43 | $datePartName = (string) $child->attributes()["name"]; |
|
| 92 | 43 | $this->dateParts->set($this->form . "-" . $datePartName, Util\Factory::create($child)); |
|
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | 56 | $this->initAffixesAttributes($node); |
|
| 97 | 56 | $this->initDisplayAttributes($node); |
|
| 98 | 56 | $this->initFormattingAttributes($node); |
|
| 99 | 56 | $this->initTextCaseAttributes($node); |
|
| 100 | 56 | } |
|
| 101 | |||
| 102 | /** |
||
|
1 ignored issue
–
show
|
|||
| 103 | * @param $data |
||
|
1 ignored issue
–
show
|
|||
| 104 | * @return string |
||
|
1 ignored issue
–
show
|
|||
| 105 | */ |
||
| 106 | 49 | public function render($data) |
|
| 107 | { |
||
| 108 | 49 | $ret = ""; |
|
| 109 | 49 | $var = null; |
|
| 110 | 49 | if (isset($data->{$this->variable})) { |
|
| 111 | 48 | $var = $data->{$this->variable}; |
|
| 112 | } else { |
||
| 113 | 7 | return ""; |
|
| 114 | } |
||
| 115 | |||
| 116 | try { |
||
| 117 | 48 | $this->prepareDatePartsInVariable($data, $var); |
|
| 118 | 1 | } catch (CiteProcException $e) { |
|
| 119 | 1 | if (!preg_match("/(\p{L}+)\s?([\-\-\&,])\s?(\p{L}+)/u", $data->{$this->variable}->raw)) { |
|
| 120 | 1 | return $this->addAffixes($this->format($this->applyTextCase($data->{$this->variable}->raw))); |
|
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | 48 | $form = $this->form; |
|
| 125 | 48 | $dateParts = !empty($this->datePartsAttribute) ? explode("-", $this->datePartsAttribute) : []; |
|
| 126 | 48 | $this->prepareDatePartsChildren($dateParts, $form); |
|
| 127 | |||
| 128 | |||
| 129 | // No date-parts in date-part attribute defined, take into account that the defined date-part children will be used. |
||
| 130 | 48 | if (empty($this->datePartsAttribute) && $this->dateParts->count() > 0) { |
|
| 131 | /** @var DatePart $part */ |
||
|
3 ignored issues
–
show
|
|||
| 132 | 36 | foreach ($this->dateParts as $part) { |
|
| 133 | 36 | $dateParts[] = $part->getName(); |
|
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | /* cs:date may have one or more cs:date-part child elements (see Date-part). The attributes set on |
||
| 138 | these elements override those specified for the localized date formats (e.g. to get abbreviated months for all |
||
| 139 | locales, the form attribute on the month-cs:date-part element can be set to “short”). These cs:date-part |
||
| 140 | elements do not affect which, or in what order, date parts are rendered. Affixes, which are very |
||
| 141 | locale-specific, are not allowed on these cs:date-part elements. */ |
||
| 142 | |||
| 143 | 48 | if ($this->dateParts->count() > 0) { |
|
| 144 | |||
| 145 | /* if (isset($var->raw) && !preg_match("/(\p{L}+)\s?([\-\-\&,])\s?(\p{L}+)/u", $var->raw) && $this->dateParts->count() > 0) { |
||
| 146 | //$var->{"date-parts"} = []; |
||
| 147 | } else*/ |
||
| 148 | 47 | if (!isset($var->{'date-parts'})) { // ignore empty date-parts |
|
| 149 | return ""; |
||
| 150 | } |
||
| 151 | |||
| 152 | 47 | if (count($data->{$this->variable}->{'date-parts'}) === 1) { |
|
| 153 | 46 | $data_ = $this->createDateTime($data->{$this->variable}->{'date-parts'}); |
|
| 154 | /** @var DatePart $datePart */ |
||
|
3 ignored issues
–
show
|
|||
| 155 | 46 | foreach ($this->dateParts as $key => $datePart) { |
|
| 156 | 46 | list($f, $p) = explode("-", $key); |
|
| 157 | 46 | if (in_array($p, $dateParts)) { |
|
| 158 | 46 | $ret .= $datePart->render($data_[0], $this); |
|
| 159 | } |
||
| 160 | } |
||
| 161 | 1 | } else if (count($var->{'date-parts'}) === 2) { //date range |
|
| 162 | 1 | $data_ = $this->createDateTime($var->{'date-parts'}); |
|
| 163 | 1 | $from = $data_[0]; |
|
| 164 | 1 | $to = $data_[1]; |
|
| 165 | 1 | $interval = $to->diff($from); |
|
| 166 | 1 | $delim = ""; |
|
| 167 | 1 | $toRender = 0; |
|
| 168 | 1 | if ($interval->y > 0) { |
|
| 169 | 1 | $toRender |= self::DATE_RANGE_STATE_YEAR; |
|
| 170 | 1 | $delim = $this->dateParts->get($this->form . "-year")->getRangeDelimiter(); |
|
| 171 | } |
||
| 172 | 1 | if ($interval->m > 0 && $from->getMonth() - $to->getMonth() !== 0) { |
|
| 173 | 1 | $toRender |= self::DATE_RANGE_STATE_MONTH; |
|
| 174 | 1 | $delim = $this->dateParts->get($this->form . "-month")->getRangeDelimiter(); |
|
| 175 | } |
||
| 176 | 1 | if ($interval->d > 0 && $from->getDay() - $to->getDay() !== 0) { |
|
| 177 | 1 | $toRender |= self::DATE_RANGE_STATE_DAY; |
|
| 178 | 1 | $delim = $this->dateParts->get($this->form . "-day")->getRangeDelimiter(); |
|
| 179 | } |
||
| 180 | |||
| 181 | 1 | $ret = $this->renderDateRange($toRender, $from, $to, $delim); |
|
| 182 | } |
||
| 183 | |||
| 184 | 47 | if (isset($var->raw) && preg_match("/(\p{L}+)\s?([\-\-\&,])\s?(\p{L}+)/u", $var->raw, $matches)) { |
|
| 185 | return $matches[1] . $matches[2] . $matches[3]; |
||
| 186 | } |
||
| 187 | } |
||
| 188 | // fallback: |
||
| 189 | // When there are no dateParts children, but date-parts attribute in date |
||
| 190 | // render numeric |
||
| 191 | 1 | else if (!empty($this->datePartsAttribute)) { |
|
| 192 | 1 | $data = $this->createDateTime($var->{'date-parts'}); |
|
| 193 | 1 | $ret = $this->renderNumeric($data[0]); |
|
| 194 | } |
||
| 195 | |||
| 196 | 48 | return !empty($ret) ? $this->addAffixes($this->format($this->applyTextCase($ret))) : ""; |
|
| 197 | } |
||
| 198 | |||
| 199 | 48 | private function createDateTime($dates) |
|
|
1 ignored issue
–
show
|
|||
| 200 | { |
||
| 201 | 48 | $data = []; |
|
| 202 | 48 | foreach ($dates as $date) { |
|
| 203 | 48 | $date = $this->cleanDate($date); |
|
| 204 | 48 | if ($date[0] < 1000) { |
|
| 205 | 1 | $dateTime = new DateTime(0, 0, 0); |
|
| 206 | 1 | $dateTime->setDay(0)->setMonth(0)->setYear(0); |
|
| 207 | 1 | $data[] = $dateTime; |
|
| 208 | } |
||
| 209 | 48 | $dateTime = new DateTime($date[0], array_key_exists(1, $date) ? $date[1] : 1, array_key_exists(2, $date) ? $date[2] : 1); |
|
| 210 | 48 | if (!array_key_exists(1, $date)) { |
|
| 211 | 26 | $dateTime->setMonth(0); |
|
| 212 | } |
||
| 213 | 48 | if (!array_key_exists(2, $date)) { |
|
| 214 | 31 | $dateTime->setDay(0); |
|
| 215 | } |
||
| 216 | 48 | $data[] = $dateTime; |
|
| 217 | } |
||
| 218 | |||
| 219 | 48 | return $data; |
|
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
|
1 ignored issue
–
show
|
|||
| 223 | * @param integer $differentParts |
||
|
3 ignored issues
–
show
|
|||
| 224 | * @param DateTime $from |
||
|
2 ignored issues
–
show
|
|||
| 225 | * @param DateTime $to |
||
|
2 ignored issues
–
show
|
|||
| 226 | * @param $delim |
||
|
1 ignored issue
–
show
|
|||
| 227 | * @return string |
||
|
1 ignored issue
–
show
|
|||
| 228 | */ |
||
| 229 | 1 | private function renderDateRange($differentParts, DateTime $from, DateTime $to, $delim) |
|
|
1 ignored issue
–
show
|
|||
| 230 | { |
||
| 231 | 1 | $ret = ""; |
|
| 232 | 1 | $dateParts_ = []; |
|
| 233 | switch ($differentParts) { |
||
| 234 | 1 | case self::DATE_RANGE_STATE_YEAR: |
|
| 235 | 1 | foreach ($this->dateParts as $key => $datePart) { |
|
| 236 | 1 | if (strpos($key, "year") !== false) { |
|
| 237 | 1 | $ret .= $this->renderOneRangePart($datePart, $from, $to, $delim); |
|
| 238 | } |
||
| 239 | 1 | if (strpos($key, "month") !== false) { |
|
| 240 | 1 | $day = !empty($d = $from->getMonth()) ? $d : ""; |
|
| 241 | 1 | $ret .= $day; |
|
| 242 | } |
||
| 243 | 1 | if (strpos($key, "day") !== false) { |
|
| 244 | 1 | $day = !empty($d = $from->getDay()) ? $datePart->render($from, $this) : ""; |
|
| 245 | 1 | $ret .= $day; |
|
| 246 | } |
||
| 247 | } |
||
| 248 | 1 | break; |
|
| 249 | 1 | case self::DATE_RANGE_STATE_MONTH: |
|
| 250 | /** |
||
|
1 ignored issue
–
show
|
|||
| 251 | * @var string $key |
||
| 252 | * @var DatePart $datePart |
||
| 253 | */ |
||
| 254 | 1 | foreach ($this->dateParts as $key => $datePart) { |
|
| 255 | 1 | if (strpos($key, "year") !== false) { |
|
| 256 | 1 | $ret .= $datePart->render($from, $this); |
|
| 257 | } |
||
| 258 | 1 | if (strpos($key, "month")) { |
|
| 259 | 1 | $ret .= $this->renderOneRangePart($datePart, $from, $to, $delim); |
|
| 260 | } |
||
| 261 | 1 | if (strpos($key, "day") !== false) { |
|
| 262 | 1 | $day = !empty($d = $from->getDay()) ? $datePart->render($from, $this) : ""; |
|
| 263 | 1 | $ret .= $day; |
|
| 264 | } |
||
| 265 | } |
||
| 266 | 1 | break; |
|
| 267 | 1 | case self::DATE_RANGE_STATE_DAY: |
|
| 268 | /** |
||
|
1 ignored issue
–
show
|
|||
| 269 | * @var string $key |
||
| 270 | * @var DatePart $datePart |
||
| 271 | */ |
||
| 272 | 1 | foreach ($this->dateParts as $key => $datePart) { |
|
| 273 | 1 | if (strpos($key, "year") !== false) { |
|
| 274 | 1 | $ret .= $datePart->render($from, $this); |
|
| 275 | } |
||
| 276 | 1 | if (strpos($key, "month") !== false) { |
|
| 277 | 1 | $ret .= $datePart->render($from, $this); |
|
| 278 | } |
||
| 279 | 1 | if (strpos($key, "day")) { |
|
| 280 | 1 | $ret .= $this->renderOneRangePart($datePart, $from, $to, $delim); |
|
| 281 | } |
||
| 282 | } |
||
| 283 | 1 | break; |
|
| 284 | 1 | case self::DATE_RANGE_STATE_YEARMONTHDAY: |
|
| 285 | 1 | $i = 0; |
|
| 286 | 1 | foreach ($this->dateParts as $datePart) { |
|
| 287 | 1 | if ($i === $this->dateParts->count() - 1) { |
|
| 288 | 1 | $ret .= $datePart->renderPrefix(); |
|
| 289 | 1 | $ret .= $datePart->renderWithoutAffixes($from, $this); |
|
| 290 | } else { |
||
| 291 | 1 | $ret .= $datePart->render($from, $this); |
|
| 292 | } |
||
| 293 | 1 | ++$i; |
|
| 294 | } |
||
| 295 | 1 | $ret .= $delim; |
|
| 296 | 1 | $i = 0; |
|
| 297 | 1 | foreach ($this->dateParts as $datePart) { |
|
| 298 | 1 | if ($i == 0) { |
|
| 299 | 1 | $ret .= $datePart->renderWithoutAffixes($to, $this); |
|
| 300 | 1 | $ret .= $datePart->renderSuffix(); |
|
| 301 | } else { |
||
| 302 | 1 | $ret .= $datePart->render($to, $this); |
|
| 303 | } |
||
| 304 | 1 | ++$i; |
|
| 305 | } |
||
| 306 | 1 | break; |
|
| 307 | 1 | case self::DATE_RANGE_STATE_YEARMONTH: |
|
| 308 | 1 | $dp = $this->dateParts->toArray(); |
|
| 309 | 1 | $i = 0; |
|
| 310 | 1 | $dateParts_ = []; |
|
| 311 | 1 | array_walk($dp, function($datePart, $key) use (&$i, &$dateParts_, $differentParts) { |
|
| 312 | 1 | if (strpos($key, "year") !== false || strpos($key, "month") !== false) { |
|
| 313 | 1 | $dateParts_["yearmonth"][] = $datePart; |
|
| 314 | } |
||
| 315 | 1 | if (strpos($key, "day") !== false) { |
|
| 316 | 1 | $dateParts_["day"] = $datePart; |
|
| 317 | } |
||
| 318 | 1 | }); |
|
| 319 | 1 | break; |
|
| 320 | 1 | case self::DATE_RANGE_STATE_YEARDAY: |
|
| 321 | $dp = $this->dateParts->toArray(); |
||
| 322 | $i = 0; |
||
| 323 | $dateParts_ = []; |
||
| 324 | array_walk($dp, function($datePart, $key) use (&$i, &$dateParts_, $differentParts) { |
||
| 325 | if (strpos($key, "year") !== false || strpos($key, "day") !== false) { |
||
| 326 | $dateParts_["yearday"][] = $datePart; |
||
| 327 | } |
||
| 328 | if (strpos($key, "month") !== false) { |
||
| 329 | $dateParts_["month"] = $datePart; |
||
| 330 | } |
||
| 331 | }); |
||
| 332 | break; |
||
| 333 | 1 | case self::DATE_RANGE_STATE_MONTHDAY: |
|
| 334 | 1 | $dp = $this->dateParts->toArray(); |
|
| 335 | 1 | $i = 0; |
|
| 336 | 1 | $dateParts_ = []; |
|
| 337 | 1 | array_walk($dp, function($datePart, $key) use (&$i, &$dateParts_, $differentParts) { |
|
| 338 | //$bit = sprintf("%03d", decbin($differentParts)); |
||
| 339 | 1 | if (strpos($key, "month") !== false || strpos($key, "day") !== false) { |
|
| 340 | 1 | $dateParts_["monthday"][] = $datePart; |
|
| 341 | } |
||
| 342 | 1 | if (strpos($key, "year") !== false) { |
|
| 343 | 1 | $dateParts_["year"] = $datePart; |
|
| 344 | } |
||
| 345 | 1 | }); |
|
| 346 | 1 | break; |
|
| 347 | } |
||
| 348 | switch ($differentParts) { |
||
| 349 | 1 | case self::DATE_RANGE_STATE_YEARMONTH: |
|
| 350 | 1 | case self::DATE_RANGE_STATE_YEARDAY: |
|
| 351 | 1 | case self::DATE_RANGE_STATE_MONTHDAY: |
|
| 352 | /** |
||
|
1 ignored issue
–
show
|
|||
| 353 | * @var $key |
||
| 354 | * @var DatePart $datePart */ |
||
|
1 ignored issue
–
show
|
|||
| 355 | 1 | foreach ($dateParts_ as $key => $datePart) { |
|
| 356 | 1 | if (is_array($datePart)) { |
|
| 357 | |||
| 358 | 1 | $f = $datePart[0]->render($from, $this); |
|
| 359 | 1 | $f .= $datePart[1]->renderPrefix(); |
|
| 360 | 1 | $f .= $datePart[1]->renderWithoutAffixes($from, $this); |
|
| 361 | 1 | $t = $datePart[0]->renderWithoutAffixes($to, $this); |
|
| 362 | 1 | $t .= $datePart[0]->renderSuffix(); |
|
| 363 | 1 | $t .= $datePart[1]->render($to, $this); |
|
| 364 | 1 | $ret .= $f . $delim . $t; |
|
| 365 | } else { |
||
| 366 | 1 | $ret .= $datePart->render($from, $this); |
|
| 367 | } |
||
| 368 | } |
||
| 369 | 1 | break; |
|
| 370 | } |
||
| 371 | 1 | return $ret; |
|
| 372 | } |
||
| 373 | |||
| 374 | /** |
||
|
1 ignored issue
–
show
|
|||
| 375 | * @param $datePart |
||
|
1 ignored issue
–
show
|
|||
| 376 | * @param DateTime $from |
||
|
2 ignored issues
–
show
|
|||
| 377 | * @param DateTime $to |
||
|
2 ignored issues
–
show
|
|||
| 378 | * @param $delim |
||
|
1 ignored issue
–
show
|
|||
| 379 | * @return string |
||
|
1 ignored issue
–
show
|
|||
| 380 | */ |
||
| 381 | 1 | protected function renderOneRangePart(DatePart $datePart, $from, $to, $delim) |
|
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
|
1 ignored issue
–
show
|
|||
| 391 | * @param string $format |
||
|
2 ignored issues
–
show
|
|||
| 392 | * @return bool |
||
|
1 ignored issue
–
show
|
|||
| 393 | */ |
||
| 394 | 14 | private function hasDatePartsFromLocales($format) |
|
|
1 ignored issue
–
show
|
|||
| 395 | { |
||
| 396 | 14 | $dateXml = CiteProc::getContext()->getLocale()->getDateXml(); |
|
| 397 | 14 | return !empty($dateXml[$format]); |
|
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
|
1 ignored issue
–
show
|
|||
| 401 | * @param string $format |
||
|
2 ignored issues
–
show
|
|||
| 402 | * @return array |
||
|
1 ignored issue
–
show
|
|||
| 403 | */ |
||
| 404 | 14 | private function getDatePartsFromLocales($format) |
|
|
1 ignored issue
–
show
|
|||
| 405 | { |
||
| 406 | 14 | $ret = []; |
|
| 407 | // date parts from locales |
||
| 408 | 14 | $dateFromLocale_ = CiteProc::getContext()->getLocale()->getDateXml(); |
|
| 409 | 14 | $dateFromLocale = $dateFromLocale_[$format]; |
|
| 410 | |||
| 411 | // no custom date parts within the date element (this)? |
||
| 412 | 14 | if (!empty($dateFromLocale)) { |
|
| 413 | |||
| 414 | 14 | $dateForm = array_filter(is_array($dateFromLocale) ? $dateFromLocale : [$dateFromLocale], function($element) use ($format) { |
|
| 415 | /** @var \SimpleXMLElement $element */ |
||
|
3 ignored issues
–
show
|
|||
| 416 | 14 | $dateForm = (string) $element->attributes()["form"]; |
|
| 417 | 14 | return $dateForm === $format; |
|
| 418 | 14 | }); |
|
| 419 | |||
| 420 | //has dateForm from locale children (date-part elements)? |
||
| 421 | 14 | $localeDate = array_pop($dateForm); |
|
| 422 | |||
| 423 | 14 | if ($localeDate instanceof \SimpleXMLElement && $localeDate->count() > 0) { |
|
| 424 | 14 | foreach ($localeDate as $child) { |
|
| 425 | 14 | $ret[] = $child; |
|
| 426 | } |
||
| 427 | } |
||
| 428 | } |
||
| 429 | 14 | return $ret; |
|
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
|
1 ignored issue
–
show
|
|||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | 26 | public function getVariable() |
|
| 436 | { |
||
| 437 | 26 | return $this->variable; |
|
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
|
1 ignored issue
–
show
|
|||
| 441 | * @param $data |
||
|
1 ignored issue
–
show
|
|||
| 442 | * @param $var |
||
|
1 ignored issue
–
show
|
|||
| 443 | * @throws CiteProcException |
||
|
1 ignored issue
–
show
|
|||
| 444 | */ |
||
| 445 | 48 | private function prepareDatePartsInVariable($data, $var) |
|
|
1 ignored issue
–
show
|
|||
| 446 | { |
||
| 447 | 48 | if (!isset($data->{$this->variable}->{'date-parts'}) || empty($data->{$this->variable}->{'date-parts'})) { |
|
| 448 | 4 | if (isset($data->{$this->variable}->raw) && !empty($data->{$this->variable}->raw)) { |
|
| 449 | //try { |
||
| 450 | // try to parse date parts from "raw" attribute |
||
| 451 | 4 | $var->{'date-parts'} = Util\DateHelper::parseDateParts($data->{$this->variable}); |
|
| 452 | //} catch (CiteProcException $e) { |
||
| 453 | // if (!preg_match("/(\p{L}+)\s?([\-\-\&,])\s?(\p{L}+)/u", $data->{$this->variable}->raw)) { |
||
| 454 | // return $this->addAffixes($this->format($this->applyTextCase($data->{$this->variable}->raw))); |
||
| 455 | // } |
||
| 456 | //} |
||
| 457 | } else { |
||
| 458 | throw new CiteProcException("No valid date format"); |
||
| 459 | //return ""; |
||
| 460 | } |
||
| 461 | } |
||
| 462 | 48 | } |
|
| 463 | |||
| 464 | /** |
||
|
1 ignored issue
–
show
|
|||
| 465 | * @param string $form |
||
|
1 ignored issue
–
show
|
|||
| 466 | */ |
||
| 467 | 48 | private function prepareDatePartsChildren($dateParts, $form) |
|
| 491 | } |
||
| 492 | } |
||
| 493 | } |
||
| 494 | 48 | } |
|
| 495 | |||
| 496 | |||
| 497 | 1 | private function renderNumeric(DateTime $date) |
|
|
1 ignored issue
–
show
|
|||
| 498 | { |
||
| 499 | 1 | return $date->renderNumeric(); |
|
| 500 | } |
||
| 501 | |||
| 502 | 11 | public function getForm() |
|
| 503 | { |
||
| 504 | 11 | return $this->form; |
|
| 505 | } |
||
| 506 | |||
| 507 | 48 | private function cleanDate($date) |
|
| 514 | } |
||
| 515 | } |