rep__date_html()
This method, is used to generate HTML representation of a date and time based on a given DateTime object, using a specified list of date formats, and wraps each formatted part of the date in appropriate HTML spans with class names for styling.
Namespace
REP_Malcolm
Parameters
$date
DateTime
Date time object
$formats
array
List of date format
Return
array
Date and time
Source
File: \includes\rep-helper-functions.php
function rep__date_html( $date, $formats=['d','F','y'] ){
ob_start();
if( $date ) :
if( !empty( $formats ) && is_array( $formats ) ) : ?>
<span class="rep-date"><?php
foreach( $formats as $format ) :
$value = $date->format( $format );
if( $value ) :
$class = "";
if( in_array( $format, ['D','l','N','w','z'] ) ) $class = "day";
elseif( in_array( $format, ['d','j','jS'] ) ) $class = "date";
elseif( $format == 'W' ) $class = "week";
elseif( in_array( $format, ['F','m','M','n','t'] ) ) $class = "month";
elseif( in_array( $format, ['L','o','X','x','Y','y'] ) ) $class = "year";
elseif( in_array( $format, ['g','G','h','H'] ) ) $class = "hour";
elseif( in_array( $format, ['i'] ) ) $class = "minute";
elseif( in_array( $format, ['g:i', 'G:i', 'h:i', 'H:i'] ) ) $class = "hour-minute";
elseif( in_array( $format, ['a','A'] ) ) $class = "meridiem"; ?>
<span class="<?=$class?>"><?=$value?></span><?php
endif;
endforeach; ?>
</span><?php
endif;
endif;
return ob_get_clean();
}