Example #1
0
 private function _filter($attribute, $params, $format)
 {
     if (!($date = DateTime::createFromFormat($format, $this->{$attribute}))) {
         return false;
     }
     $date->setFormat($format);
     return $date;
 }
Example #2
0
 /**
  * format html for date
  * @param string $datetime: value from database (EX: Y-m-d)
  * @param string $format: new format
  * @param mixed $htmlOpts [tag=>'span', class=>'abc']
  * @return string
  */
 public static function htmlDateTimeFormatFromDB($datetime, $format, $htmlOpts = false)
 {
     $date = \DateTime::createFromFormat(self::FM_DB_DATETIME, $datetime);
     $datestr = $date->format($format);
     if ($htmlOpts === false) {
         return $datestr;
     }
     $dt = getdate($date->getTimestamp());
     $daysweek = $dt[self::FN_KEY_GETDATE_DAYSOFWEEK_INT];
     $dateFormatInstall = self::getDateFormatInstall();
     $textcolor = $dateFormatInstall['weekday'][$daysweek]['text-color'];
     $tag = isset($htmlOpts['tag']) ? $htmlOpts['tag'] : 'span';
     $fulltag = '<' . $tag . ' class="{0}">{1}';
     $fulltag .= '</' . $tag . '>';
     $css = (isset($htmlOpts['class']) ? $htmlOpts['class'] : '') . ' ' . $textcolor;
     return StringUtils::format($fulltag, [$css, $datestr]);
 }