Plugin Directory

Changeset 3470542


Ignore:
Timestamp:
02/26/2026 04:56:23 PM (4 weeks ago)
Author:
dramb
Message:

Update date/time localisation to use Wordpress settings rather than the server locale. Modularise the date/time localisation code to aid maintenance and reduce duplication. Version bump to 1.0.8

Location:
cs-integration
Files:
86 added
9 edited

Legend:

Unmodified
Added
Removed
  • cs-integration/trunk/README.md

    r3468771 r3470542  
    44* Requires at least: 6.4
    55* Tested up to: 6.9
    6 * Stable tag: 1.0.7
     6* Stable tag: 1.0.8
    77* License: GPLv2 or later
    88
     
    209209## Changelog
    210210
     211### 1.0.8
     212**2026-02-26**
     213* Refactored the Locale code to use the wordpress site locale rather than
     214  the server locale, and to use the wordpress admin settings for full
     215  date or time output.  This means the time and date output should always
     216  be sympathetic with the Wordpress site settings.  Also moved all the
     217  time and date string creation to a new module so it can be easily
     218  modified without having to update many files.
     219* Version bump to 1.0.8
     220
    211221### 1.0.7
    212222
  • cs-integration/trunk/README.txt

    r3468771 r3470542  
    44* Requires at least: 6.4
    55* Tested up to: 6.9
    6 * Stable tag: 1.0.7
     6* Stable tag: 1.0.8
    77* License: GPLv2 or later
    88
     
    209209== Changelog ==
    210210
     211= 1.0.8 =
     212
     213**2026-02-26**
     214* Refactored the Locale code to use the wordpress site locale rather than
     215  the server locale, and to use the wordpress admin settings for full
     216  date or time output.  This means the time and date output should always
     217  be sympathetic with the Wordpress site settings.  Also moved all the
     218  time and date string creation to a new module so it can be easily
     219  modified without having to update many files.
     220* Version bump to 1.0.8
     221
     222
    211223= 1.0.7 =
    212224
  • cs-integration/trunk/cs-integration.php

    r3468771 r3470542  
    2020 * Plugin URI:        https://github.com/AlwynBarry/cs-integration
    2121 * Description:       CS Integration provides shortcodes to request and display JSON data from the public JSON ChurchSuite feeds.
    22  * Version:           1.0.7
     22 * Version:           1.0.8
    2323 * Author:            Alwyn Barry
    2424 * Author URI:        https://github.com/AlwynBarry/
     
    3939 * This will be updated it as we release new versions.
    4040 */
    41 const CS_INTEGRATION_VERSION = '1.0.7';
     41const CS_INTEGRATION_VERSION = '1.0.8';
    4242
    4343/**
  • cs-integration/trunk/public/shortcodes/class-cs-calendar-event-view.php

    r3468771 r3470542  
    44
    55
     6require_once plugin_dir_path( __FILE__ ) . 'class-cs-date-utilities.php';
    67require_once plugin_dir_path( __FILE__ ) . 'class-churchsuite.php';
    78require_once plugin_dir_path( __FILE__ ) . 'class-cs-view.php';
    89require_once plugin_dir_path( __FILE__ ) . 'class-cs-event.php';
    910
     11use amb_dev\CSI\Cs_Date_Utilities;
    1012use amb_dev\CSI\ChurchSuite as ChurchSuite;
    1113use amb_dev\CSI\Cs_View as Cs_View;
     
    5961     */
    6062    public function display() : string {
    61         // A value to prevent repeated creation of a new instance
    62         $timeFormat = datefmt_create(
    63             \Locale::getDefault(),
    64             \IntlDateFormatter::NONE,
    65             \IntlDateFormatter::SHORT,
    66             null,
    67             \IntlDateFormatter::GREGORIAN
    68         );
    6963        // Display the event wrapper, and include the event unique ID, the event
    7064        // status and the event category as classes to be styled, if these are set
     
    8680        $event_time = '';
    8781        if ( $this->cs_event->is_start_date() ) {
    88             $event_time .= '    <div class="cs-time"><span class="cs-start-time">' . datefmt_format( $timeFormat, $this->cs_event->get_start_date() ) . '</span>';
    89             $event_time .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="cs-end-time">' . datefmt_format( $timeFormat, $this->cs_event->get_end_date() ) . '</span>' : '';
     82            $event_time .= '    <div class="cs-time"><span class="cs-start-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_start_date() ) . '</span>';
     83            $event_time .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="cs-end-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_end_date() ) . '</span>' : '';
    9084            $event_time .= '</div>' . "\n";
    9185        }
  • cs-integration/trunk/public/shortcodes/class-cs-calendar-shortcode.php

    r3468771 r3470542  
    44
    55
     6require_once plugin_dir_path( __FILE__ ) . 'class-cs-date-utilities.php';
    67require_once plugin_dir_path( __FILE__ ) . 'class-churchsuite.php';
    78require_once plugin_dir_path( __FILE__ ) . 'class-cs-shortcode.php';
     
    910require_once plugin_dir_path( __FILE__ ) . 'class-cs-calendar-event-view.php';
    1011
     12use amb_dev\CSI\Cs_Date_Utilities;
    1113use amb_dev\CSI\ChurchSuite as ChurchSuite;
    1214use amb_dev\CSI\Cs_Shortcode as Cs_Shortcode;
     
    4749     * Constant values created to prevent unnecessary re-creation of values used in expressions
    4850     */
    49     protected \IntlDateFormatter $shortDayFormat;
    50     protected \IntlDateFormatter $shortMonthFormat;
    51     protected \IntlDateFormatter $longMonthFormat;
    5251    protected readonly \DateInterval $one_day;
    5352    protected readonly \DateInterval $one_week;
     
    7372     */
    7473    public function __construct( $atts ) {
    75         // Set the date formatters used to remove repeated instance creation
    76         $this->set_date_formatters();
    77 
     74       
    7875        // Set the date constants used to remove repeated instance creation
    79         $this->page_url = get_permalink();
    8076        $this->one_day = \DateInterval::createFromDateString( '1 day' );
    8177        $this->one_week = \DateInterval::createFromDateString( '1 week' );
    8278        $this->one_month = \DateInterval::createFromDateString( '1 month' );
     79
     80        // Set the values always required by this shortcode
     81        $this->page_url = get_permalink();
    8382        $this->today = new \DateTime();
    8483        $this->today->setTime( 0, 0 );
     
    8685        // Set the requested base date.  This either comes from the page query
    8786        // or, if there is an error with the date supplied by the page query or
    88         // no page query date, we check for a date_start attribute.  If the
    89         // date_start attribute is not correctly formed, we
     87        // no page query date, we check for a date_start attribute.
    9088        $query_value = get_query_var('cs-date');
    9189        if ( ( $query_value !== '' ) && ( $date = \DateTime::createFromFormat( "Y-m-d", $query_value ) ) ) {
     
    119117
    120118    /*
    121      * Set the 'constant' values used to remove repeated instance creation of the required date formatters.
    122      *
    123      * @since   1.0.2
    124      */
    125     private function set_date_formatters() {
    126         $this->shortDayFormat = datefmt_create(
    127             \Locale::getDefault(),
    128             \IntlDateFormatter::FULL,
    129             \IntlDateFormatter::NONE,
    130             null,
    131             \IntlDateFormatter::GREGORIAN,
    132             'EEE'
    133         );
    134         $this->shortMonthFormat = datefmt_create(
    135             \Locale::getDefault(),
    136             \IntlDateFormatter::FULL,
    137             \IntlDateFormatter::NONE,
    138             null,
    139             \IntlDateFormatter::GREGORIAN,
    140             'MMM'
    141         );
    142         $this->longMonthFormat = datefmt_create(
    143             \Locale::getDefault(),
    144             \IntlDateFormatter::FULL,
    145             \IntlDateFormatter::NONE,
    146             null,
    147             \IntlDateFormatter::GREGORIAN,
    148             'MMMM'
    149         );
    150     }
    151 
    152     /*
    153119     * Returns the number of days in a given month and year, taking into account leap years.
    154120     *
     
    262228            . '    <div class="cs-calendar-month-header">' . "\n"
    263229            . '      <div class="cs-calendar-month-title">' . "\n"
    264             . '        ' . datefmt_format($this->longMonthFormat, $date) .  ' ' . $date->format( 'Y' ) . "\n"
     230            . '        ' . Cs_Date_Utilities::get_month_name_by_locale( $date ) .  ' ' . Cs_Date_Utilities::get_year_by_locale( $date ) . "\n"
    265231            . '      </div>' . "\n"
    266232            . '      <div class="cs-calendar-month-nav">' . "\n"
     
    287253        $period = new \DatePeriod( $sunday_date, $this->one_day, $saturday_date );
    288254        foreach ( $period as $day ) {
    289             $output .= '        <div class="cs-calendar-day-name-cell">' . datefmt_format($this->shortDayFormat, $day) . '</div>' . "\n";
     255            $output .= '        <div class="cs-calendar-day-name-cell">' . Cs_Date_Utilities::get_short_day_name_by_locale( $day ) . '</div>' . "\n";
    290256        }
    291257
     
    327293        $day = (int) $date->format( 'j' );
    328294        $output .= '    <div class="cs-date' . ( ( $day === 1 ) ? ' cs-first-day' : '' ) . '">' . "\n";
    329         $output .= '      <span class="cs-day">' . $date->format( 'D' ) . '</span>' . "\n";
    330         $output .= '      <span class="cs-date-number">' . $day . '</span>' . "\n";
    331         $output .= '      <span class="cs-month">' . datefmt_format($this->shortMonthFormat, $date) . '</span>' . "\n";
    332         $output .= '      <span class="cs-year">' . $date->format( 'Y' ) . '</span>' . "\n";
     295        $output .= '      <span class="cs-day">' . Cs_Date_Utilities::get_day_name_by_locale( $date ) . '</span>' . "\n";
     296        $output .= '      <span class="cs-date-number">' . Cs_Date_Utilities::get_day_number_by_locale( $date ) . '</span>' . "\n";
     297        $output .= '      <span class="cs-month">' . Cs_Date_Utilities::get_short_month_name_by_locale( $date ) . '</span>' . "\n";
     298        $output .= '      <span class="cs-year">' . Cs_Date_Utilities::get_year_by_locale( $date ) . '</span>' . "\n";
    333299        $output .= '    </div>';
    334300        // Output the start of the  div containing the details of the events on this date
  • cs-integration/trunk/public/shortcodes/class-cs-compact-event-view.php

    r3468771 r3470542  
    44
    55
     6require_once plugin_dir_path( __FILE__ ) . 'class-cs-date-utilities.php';
    67require_once plugin_dir_path( __FILE__ ) . 'class-churchsuite.php';
    78require_once plugin_dir_path( __FILE__ ) . 'class-cs-view.php';
    89require_once plugin_dir_path( __FILE__ ) . 'class-cs-event.php';
    910
     11use amb_dev\CSI\Cs_Date_Utilities;
    1012use amb_dev\CSI\ChurchSuite as ChurchSuite;
    1113use amb_dev\CSI\Cs_View as Cs_View;
     
    3234
    3335    /*
    34      * Constant values created to prevent unnecessary re-creation of values used in expressions
    35      * @since 1.0.0
    36      */
    37     protected \IntlDateFormatter $timeFormat;
    38 
    39     /*
    4036     * The event to be displayed, set via the constructor
    4137     * @since 1.0.0
     
    5753        parent::__construct( $cs );
    5854        $this->cs_event = $cs_event;
    59         $this->set_date_formatters();
    60     }
    61 
    62     /*
    63      * Set the 'constant' values used to remove repeated instance creation of the required date formatters.
    64      */
    65     private function set_date_formatters() {
    66         // Set the date formatters used to remove repeated instance creation
    67         $this->timeFormat = datefmt_create(
    68             \Locale::getDefault(),
    69             \IntlDateFormatter::NONE,
    70             \IntlDateFormatter::SHORT,
    71             null,
    72             \IntlDateFormatter::GREGORIAN
    73         );
    7455    }
    7556
     
    8970        // Display the event time and the end time if provided
    9071        if ( $this->cs_event->is_start_date() ) {
    91             $output .= '    <div class="cs-time"><span class="cs-start-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_start_date() ) . '</span>';
    92             $output .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="cs-end-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_end_date() ) . '</span>' : '';
     72            $output .= '    <div class="cs-time"><span class="cs-start-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_start_date() ) . '</span>';
     73            $output .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="cs-end-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_end_date() ) . '</span>' : '';
    9374            $output .= '</div>' . "\n";
    9475        }
  • cs-integration/trunk/public/shortcodes/class-cs-event-card-view.php

    r3468771 r3470542  
    44
    55
     6require_once plugin_dir_path( __FILE__ ) . 'class-cs-date-utilities.php';
    67require_once plugin_dir_path( __FILE__ ) . 'class-churchsuite.php';
    78require_once plugin_dir_path( __FILE__ ) . 'class-cs-view.php';
    89require_once plugin_dir_path( __FILE__ ) . 'class-cs-event.php';
    910
     11use amb_dev\CSI\Cs_Date_Utilities;
    1012use amb_dev\CSI\ChurchSuite as ChurchSuite;
    1113use amb_dev\CSI\Cs_View as Cs_View;
     
    3234
    3335    /*
    34      * Constant values created to prevent unnecessary re-creation of values used in expressions
    35      * @since   1.0.2
    36      * @access  protected
    37      * @var     \IntlDateFormatter $monthAndDateFormat  - a date formatter for month name and date
    38      * @var     \IntlDateFormatter $timeFormat          - a date formatter for a hour:min time
    39      */
    40     protected \IntlDateFormatter $monthAndDateFormat;
    41     protected \IntlDateFormatter $timeFormat;
    42 
    43     /*
    4436     * The event to be displayed, set via the constructor
    4537     * @since 1.0.0
     
    6153        parent::__construct( $cs );
    6254        $this->cs_event = $cs_event;
    63         $this->set_date_formatters();
    64     }
    65 
    66     /*
    67      * Set the 'constant' values used to remove repeated instance creation of the required date formatters.
    68      *
    69      * @since   1.0.7
    70      */
    71     private function set_date_formatters() {
    72         // Set the date formatters used to remove repeated instance creation
    73         $this->monthAndDateFormat = datefmt_create(
    74             \Locale::getDefault(),
    75             \IntlDateFormatter::MEDIUM,
    76             \IntlDateFormatter::NONE,
    77             null,
    78             \IntlDateFormatter::GREGORIAN
    79         );
    80         $this->timeFormat = datefmt_create(
    81             \Locale::getDefault(),
    82             \IntlDateFormatter::NONE,
    83             \IntlDateFormatter::SHORT,
    84             null,
    85             \IntlDateFormatter::GREGORIAN
    86         );
    8755    }
    8856
     
    11785        // Display the start and end times where they are provided
    11886        if ( $this->cs_event->is_start_date() ) {
    119             $output .= '    <div class="cs-date"><span class="cs-date-gliph">' . datefmt_format( $this->monthAndDateFormat, $this->cs_event->get_start_date() ) . '</span></div>' . "\n";
     87            $output .= '    <div class="cs-date"><span class="cs-date-gliph">' . Cs_Date_Utilities::get_site_formatted_date( $this->cs_event->get_start_date() ) . '</span></div>' . "\n";
    12088            $output .= '    <div class="cs-time">';
    121             $output .= '        <span class="cs-time-gliph cs-start-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_start_date() ) . '</span>';
    122             $output .= ( $this->cs_event->is_end_date() ) ? ' - <span class="cs-end-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_end_date() ) . '</span>' . "\n" : "\n";
     89            $output .= '        <span class="cs-time-gliph cs-start-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_start_date() ) . '</span>';
     90            $output .= ( $this->cs_event->is_end_date() ) ? ' - <span class="cs-end-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_end_date() ) . '</span>' . "\n" : "\n";
    12391            $output .= '    </div>' . "\n";
    12492        }
  • cs-integration/trunk/public/shortcodes/class-cs-event-list-shortcode.php

    r3468771 r3470542  
    44
    55
     6require_once plugin_dir_path( __FILE__ ) . 'class-cs-date-utilities.php';
    67require_once plugin_dir_path( __FILE__ ) . 'class-churchsuite.php';
    78require_once plugin_dir_path( __FILE__ ) . 'class-cs-shortcode.php';
     
    910require_once plugin_dir_path( __FILE__ ) . 'class-cs-compact-event-view.php';
    1011
     12use amb_dev\CSI\Cs_Date_Utilities;
    1113use amb_dev\CSI\ChurchSuite as ChurchSuite;
    1214use amb_dev\CSI\Cs_Shortcode as Cs_Shortcode;
     
    7577    protected function display_event_date( \DateTime $event_date ) : string {
    7678        $result = '<div class="cs-date">';
    77         $result .= '<span class="cs-day">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'EE' ), $event_date ) . '</span>';
    78         $result .= '<span class="cs-date-number">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'dd' ), $event_date ) . '</span>';
    79         $result .= '<span class="cs-month">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'MMM' ), $event_date ) . '</span>';
    80         $result .= '<span class="cs-year">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'yyyy' ), $event_date ) . '</span>';
     79        $result .= '<span class="cs-day">' . Cs_Date_Utilities::get_day_name_by_locale( $event_date ) . '</span>';
     80        $result .= '<span class="cs-date-number">' . Cs_Date_Utilities::get_day_number_by_locale( $event_date ) . '</span>';
     81        $result .= '<span class="cs-month">' . Cs_Date_Utilities::get_short_month_name_by_locale( $event_date ) . '</span>';
     82        $result .= '<span class="cs-year">' . Cs_Date_Utilities::get_year_by_locale( $event_date ) . '</span>';
    8183        $result .= '</div>';
    8284        return $result;
  • cs-integration/trunk/public/shortcodes/class-cs-group.php

    r3468771 r3470542  
    33namespace amb_dev\CSI;
    44
     5
     6require_once plugin_dir_path( __FILE__ ) . 'class-cs-date-utilities.php';
    57require_once plugin_dir_path( __FILE__ ) . 'class-churchsuite.php';
    68require_once plugin_dir_path( __FILE__ ) . 'class-cs-item.php';
    79
     10use amb_dev\CSI\Cs_Date_Utilities;
    811use amb_dev\CSI\ChurchSuite as ChurchSuite;
    912use amb_dev\CSI\Cs_Item as Cs_Item;
     
    147150    protected function fetch_time_of_meeting( \stdclass $group_obj ) : string {
    148151        return ( isset( $group_obj->time ) && ( $group_obj->time !== '' ) )
    149             ? datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT, null, \IntlDateFormatter::GREGORIAN ), date_create( $group_obj->time ) )
     152            ? Cs_Date_Utilities::get_site_formatted_time( date_create( $group_obj->time ) )
    150153            : '' ;
    151154    }
Note: See TracChangeset for help on using the changeset viewer.