Skip to content

Commit

Permalink
Add mc_date_badge() to format a date badge.
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Dec 17, 2024
1 parent 47dcc22 commit ab57052
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/my-calendar-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ function mc_create_tags( $event, $context = 'filters' ) {
$e['dtend'] = mc_date( 'Y-m-d\TH:i:s', $hcal_dt_end, false ); // Date: hcal formatted end.
$e['userstart'] = '<time class="mc-user-time" data-label="' . __( 'Local time:', 'my-calendar' ) . '">' . mc_date( 'Y-m-d\TH:i:s\Z', $event->ts_occur_begin, false ) . '</time>';
$e['userend'] = '<time class="mc-user-time" data-label="' . __( 'Local time:', 'my-calendar' ) . '">' . mc_date( 'Y-m-d\TH:i:s\Z', $event->ts_occur_end, false ) . '</time>';
$e['datebadge'] = '<time class="mc-date-badge" datetime="' . mc_date( 'Y-m-d', strtotime( $real_begin_date ) ) . '"><span class="month">' . mc_date( 'M', strtotime( $real_begin_date ) ) . '</span><span class="day">' . mc_date( 'j', strtotime( $real_begin_date ) ) . '</span></time>';
$e['datebadge'] = mc_date_badge( $real_begin_date );
/**
* Start date format used in 'date' and 'daterange' template tags. Fallback value for `datespan`. Default from My Calendar settings.
*
Expand Down Expand Up @@ -1001,6 +1001,30 @@ function mc_get_details_label( $event, $e ) {
return $e_label;
}

/**
* Format a date into a badge.
*
* @param int $date Datestamp.
*
* @return string
*/
function mc_date_badge( $date ) {
$badge = '<time class="mc-date-badge" datetime="' . mc_date( 'Y-m-d', strtotime( $date ) ) . '"><span class="month">' . mc_date( 'M', strtotime( $date ) ) . '</span><span class="day">' . mc_date( 'j', strtotime( $date ) ) . '</span></time>';
/**
* Filter the date badge HTML.
*
* @hook mc_date_badge
*
* @param {string} $badge HTML output of the badge.
* @param {int} $date Datestamp.
*
* @return {string}
*/
$badge = apply_filters( 'mc_date_badge', $badge, $date );

return $badge;
}

/**
* Format a timestamp for use in iCal.
*
Expand Down

0 comments on commit ab57052

Please sign in to comment.