WordPress.org

Forums

Radio Station
Show Page Time Display 24hr Fix (code) (2 posts)

  1. Grant2013
    Member
    Posted 1 year ago #

    If you are using the single-show.php template and displaying 24HR time there is a little problem with the 12am time output.

    If a show starts at midnight and ends at 2am it outputs like this :

    12:00 - 02:00

    Instead of what it should be doing which is :

    00:00 - 02:00

    The code below will fix it so it displays correctly.

    Open single-show.php and find the code that converts to 24hr time. (it's clearly commented)

    Replace it with the following :

    //24hr Time
    $shifts = get_post_meta(get_the_ID(), 'show_sched', true);
    if($shifts) {
    
    foreach($shifts as $shift) {
    
    if($shift['start_hour'] >= 1 & $shift['start_hour'] <= 11 && $shift['start_meridian'] == 'pm') {
    $shift['start_hour'] = $shift['start_hour'] + 12;
    }
    
    if($shift['end_hour'] >= 1 & $shift['end_hour'] <= 11 && $shift['end_meridian'] == 'pm') {
    $shift['end_hour'] = $shift['end_hour'] + 12;
    }
    
    // make sure that 12pm still displays correctly
    if($shift['start_hour'] == 12 && $shift['start_meridian'] == 'pm') {
    $shift['start_hour'] = '12';
    }
    
    if($shift['end_hour'] == 12 && $shift['end_meridian'] == 'pm') {
    $shift['end_hour'] = '12';
    }
    
    // fixes 12am display by replacing time with 00
    if($shift['start_hour'] == 12 && $shift['start_meridian'] == 'am') {
    $shift['start_hour'] = '00';
    }
    
    if($shift['end_hour'] == 12 && $shift['end_meridian'] == 'am') {
    $shift['end_hour'] = '00';
    }
    
    // adds leading zero to 24 hour time between 1am and 10am
    if($shift['start_hour'] >= 1 && $shift['start_hour'] <= 10) {
    $shift['start_hour'] = '0'.$shift['start_hour'];
    }
    
    if($shift['end_hour'] >= 1 && $shift['end_hour'] <= 10) {
    $shift['end_hour'] = '0'.$shift['end_hour'];
    }

    There's probably a much more elegant way to do this but it works ;)
    https://wordpress.org/plugins/radio-station/

  2. Grant2013
    Member
    Posted 1 year ago #

    Hang on, little problem, it's removing 12:00 as well.

    EDIT....

    Cor, that was a little git!

    Ok, code above fixed and working ;)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Radio Station
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.