Plugin Directory

Changeset 3470303


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

Refactored the Locale code to use the wordpress site locale rather than

the server locale, and to use the wordpress admin settings for full
date or time output. This means the time and date output should always
be sympathetic with the Wordpress site settings. Also moved all the
time and date string creation to a new module so it can be easily
modified without having to update many files.

Location:
blocks-for-churchsuite/trunk
Files:
2 added
23 edited

Legend:

Unmodified
Added
Removed
  • blocks-for-churchsuite/trunk/blocks-for-churchsuite.php

    r3468626 r3470303  
    44 * Plugin URI:        https://github.com/AlwynBarry/blocks-for-churchsuite
    55 * Description:       Gutenberg blocks to display Data for Events and SmallGroups from ChurchSuite
    6  * Version:           1.0.2
     6 * Version:           1.0.3
    77 * Requires at least: 6.7
    88 * Requires PHP:      8.0
  • blocks-for-churchsuite/trunk/blocks/build/blocks-manifest.php

    r3468626 r3470303  
    66        'apiVersion' => 3,
    77        'name' => 'b4cs/cs-calendar',
    8         'version' => '1.0.2',
     8        'version' => '1.0.3',
    99        'title' => 'Calendar for ChurchSuite',
    1010        'category' => 'widgets',
     
    7373        'apiVersion' => 3,
    7474        'name' => 'b4cs/cs-event-cards',
    75         'version' => '1.0.2',
     75        'version' => '1.0.3',
    7676        'title' => 'Event Cards for ChurchSuite',
    7777        'category' => 'widgets',
     
    164164        'apiVersion' => 3,
    165165        'name' => 'b4cs/cs-event-list',
    166         'version' => '1.0.2',
     166        'version' => '1.0.3',
    167167        'title' => 'Event List for ChurchSuite',
    168168        'category' => 'widgets',
     
    255255        'apiVersion' => 3,
    256256        'name' => 'b4cs/cs-smallgroups',
    257         'version' => '1.0.2',
     257        'version' => '1.0.3',
    258258        'title' => 'Small Groups for ChurchSuite',
    259259        'category' => 'widgets',
  • blocks-for-churchsuite/trunk/blocks/build/cs-calendar/block.json

    r3468626 r3470303  
    33  "apiVersion": 3,
    44  "name": "b4cs/cs-calendar",
    5   "version": "1.0.2",
     5  "version": "1.0.3",
    66  "title": "Calendar for ChurchSuite",
    77  "category": "widgets",
  • blocks-for-churchsuite/trunk/blocks/build/cs-event-cards/block.json

    r3468626 r3470303  
    33  "apiVersion": 3,
    44  "name": "b4cs/cs-event-cards",
    5   "version": "1.0.2",
     5  "version": "1.0.3",
    66  "title": "Event Cards for ChurchSuite",
    77  "category": "widgets",
  • blocks-for-churchsuite/trunk/blocks/build/cs-event-list/block.json

    r3468626 r3470303  
    33  "apiVersion": 3,
    44  "name": "b4cs/cs-event-list",
    5   "version": "1.0.2",
     5  "version": "1.0.3",
    66  "title": "Event List for ChurchSuite",
    77  "category": "widgets",
  • blocks-for-churchsuite/trunk/blocks/build/cs-smallgroups/block.json

    r3468626 r3470303  
    33  "apiVersion": 3,
    44  "name": "b4cs/cs-smallgroups",
    5   "version": "1.0.2",
     5  "version": "1.0.3",
    66  "title": "Small Groups for ChurchSuite",
    77  "category": "widgets",
  • blocks-for-churchsuite/trunk/blocks/build/inc/class-cs-calendar-event-view.php

    r3388993 r3470303  
    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\b4cs\Cs_Date_Utilities;
    1012use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1113use amb_dev\b4cs\Cs_View as Cs_View;
     
    8183        $event_time = '';
    8284        if ( $this->cs_event->is_start_date() ) {
    83             $event_time .= '    <div class="b4cs-time"><span class="b4cs-start-time">' . date_format( $this->cs_event->get_start_date(), 'g:ia' ) . '</span>';
    84             $event_time .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="b4cs-end-time">' . date_format( $this->cs_event->get_end_date(), 'g:ia' ) . '</span>' : '';
     85            $event_time .= '    <div class="b4cs-time"><span class="b4cs-start-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_start_date() ) . '</span>';
     86            $event_time .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="b4cs-end-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_end_date() ) . '</span>' : '';
    8587            $event_time .= '</div>' . "\n";
    8688        }
  • blocks-for-churchsuite/trunk/blocks/build/inc/class-cs-calendar-renderer.php

    r3468626 r3470303  
    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-renderer.php';
     
    910require_once plugin_dir_path( __FILE__ ) . 'class-cs-calendar-event-view.php';
    1011
     12use amb_dev\b4cs\Cs_Date_Utilities;
    1113use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1214use amb_dev\b4cs\Cs_Renderer as Cs_Renderer;
     
    5153     * Constant values created to prevent unnecessary re-creation of values used in expressions
    5254     */
    53     protected \IntlDateFormatter $shortDayFormat;
    54     protected \IntlDateFormatter $shortMonthFormat;
    55     protected \IntlDateFormatter $longMonthFormat;
    5655    protected readonly \DateInterval $one_day;
    5756    protected readonly \DateInterval $one_week;
    5857    protected readonly \DateInterval $one_month;
    5958    protected readonly string $page_url;
     59   
    6060    protected \DateTime $today;
    6161    protected \DateTime $requested_date;
     
    7676     */
    7777    public function __construct( $atts ) {
    78         // Set the date formatters used to remove repeated instance creation
    79         // TEST: \Locale::setDefault('de-DE');
    80         $this->shortDayFormat = datefmt_create(
    81             \Locale::getDefault(),
    82             \IntlDateFormatter::FULL,
    83             \IntlDateFormatter::NONE,
    84             null,
    85             \IntlDateFormatter::GREGORIAN,
    86             'EEE'
    87         );
    88         $this->shortMonthFormat = datefmt_create(
    89             \Locale::getDefault(),
    90             \IntlDateFormatter::FULL,
    91             \IntlDateFormatter::NONE,
    92             null,
    93             \IntlDateFormatter::GREGORIAN,
    94             'MMM'
    95         );
    96         $this->longMonthFormat = datefmt_create(
    97             \Locale::getDefault(),
    98             \IntlDateFormatter::FULL,
    99             \IntlDateFormatter::NONE,
    100             null,
    101             \IntlDateFormatter::GREGORIAN,
    102             'MMMM'
    103         );
    10478
    10579        // Set the date constants used to remove repeated instance creation
     
    258232            . '    <div class="b4cs-calendar-month-header">' . "\n"
    259233            . '      <div class="b4cs-calendar-month-title">' . "\n"
    260             . '        ' . datefmt_format($this->longMonthFormat, $date) .  ' ' . $date->format( 'Y' ) . "\n"   /* . '        ' .  $date->format( 'F' ) . ' ' .  $date->format( 'Y' ) . "\n" */
     234            . '        ' . Cs_Date_Utilities::get_month_name_by_locale( $date ) .  ' ' . Cs_Date_Utilities::get_year_by_locale( $date ) . "\n"
    261235            . '      </div>' . "\n"
    262236            . '      <div class="b4cs-calendar-month-nav">' . "\n"
     
    279253        $period = new \DatePeriod( $sunday_date, $this->one_day, $saturday_date );
    280254        foreach ( $period as $day ) {
    281             /* $output .= '        <div class="b4cs-calendar-day-name-cell">' . $day->format( 'D' ) . '</div>' . "\n"; */
    282             $output .= '        <div class="b4cs-calendar-day-name-cell">' . datefmt_format($this->shortDayFormat, $day) . '</div>' . "\n";
     255            $output .= '        <div class="b4cs-calendar-day-name-cell">' . Cs_Date_Utilities::get_short_day_name_by_locale( $day ) . '</div>' . "\n";
    283256        }
    284257
     
    320293        $day = (int) $date->format( 'j' );
    321294        $output .= '    <div class="b4cs-date' . ( ( $day === 1 ) ? ' b4cs-first-day' : '' ) . '">' . "\n";
    322         $output .= '      <span class="b4cs-day">' . $date->format( 'D' ) . '</span>' . "\n";
    323         $output .= '      <span class="b4cs-date-number">' . $day . '</span>' . "\n";
    324         $output .= '      <span class="b4cs-month">' . datefmt_format($this->shortMonthFormat, $date) . '</span>' . "\n";   
    325         /* $output .= '      <span class="b4cs-month">' . $date->format( 'F' ) . '</span>' . "\n"; */
    326         $output .= '      <span class="b4cs-year">' . $date->format( 'Y' ) . '</span>' . "\n";
     295        $output .= '      <span class="b4cs-day">' . Cs_Date_Utilities::get_day_name_by_locale( $date ) . '</span>' . "\n";
     296        $output .= '      <span class="b4cs-date-number">' . Cs_Date_Utilities::get_day_number_by_locale( $date ) . '</span>' . "\n";
     297        $output .= '      <span class="b4cs-month">' . Cs_Date_Utilities::get_short_month_name_by_locale( $date ) . '</span>' . "\n";   
     298        $output .= '      <span class="b4cs-year">' . Cs_Date_Utilities::get_year_by_locale( $date ) . '</span>' . "\n";
    327299        $output .= '    </div>';
    328300        // Output the start of the  div containing the details of the events on this date
  • blocks-for-churchsuite/trunk/blocks/build/inc/class-cs-compact-event-view.php

    r3468626 r3470303  
    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\b4cs\Cs_Date_Utilities;
    1012use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1113use amb_dev\b4cs\Cs_View as Cs_View;
     
    3234
    3335    /*
    34      * Constant values created to prevent unnecessary re-creation of values used in expressions
    35      */
    36     protected \IntlDateFormatter $timeFormat;
    37 
    38     /*
    3936     * The event to be displayed, set via the constructor
    4037     * @since 1.0.0
     
    5653        parent::__construct( $cs );
    5754        $this->cs_event = $cs_event;
    58         $this->set_date_formatters();
    59     }
    60 
    61     /*
    62      * Set the 'constant' values used to remove repeated instance creation of the required date formatters.
    63      */
    64     private function set_date_formatters() {
    65         // Set the date formatters used to remove repeated instance creation
    66         $this->timeFormat = datefmt_create(
    67             \Locale::getDefault(),
    68             \IntlDateFormatter::NONE,
    69             \IntlDateFormatter::SHORT,
    70             null,
    71             \IntlDateFormatter::GREGORIAN
    72         );
    7355    }
    7456
     
    8870        // Display the event time and the end time if provided
    8971        if ( $this->cs_event->is_start_date() ) {
    90             $output .= '    <div class="b4cs-time"><span class="b4cs-start-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_start_date() ) . '</span>';
    91             $output .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="b4cs-end-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_end_date() ) . '</span>' : '';
     72            $output .= '    <div class="b4cs-time"><span class="b4cs-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="b4cs-end-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_end_date() ) . '</span>' : '';
    9274            $output .= '</div>' . "\n";
    9375        }
  • blocks-for-churchsuite/trunk/blocks/build/inc/class-cs-event-card-view.php

    r3468626 r3470303  
    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\b4cs\Cs_Date_Utilities;
    1012use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1113use amb_dev\b4cs\Cs_View as Cs_View;
     
    3234
    3335    /*
    34      * Constant values created to prevent unnecessary re-creation of values used in expressions
    35      */
    36     protected \IntlDateFormatter $monthAndDateFormat;
    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         // Set the constant values for the date formatters needed
    60         $this->set_date_formatters();
    61     }
    62 
    63     /*
    64      * Set the 'constant' values used to remove repeated instance creation of the required date formatters.
    65      */
    66     private function set_date_formatters() {
    67         // Set the date formatters used to remove repeated instance creation
    68         // TEST: \Locale::setDefault('de-DE');
    69         $this->monthAndDateFormat = datefmt_create(
    70             \Locale::getDefault(),
    71             \IntlDateFormatter::MEDIUM,
    72             \IntlDateFormatter::NONE,
    73             null,
    74             \IntlDateFormatter::GREGORIAN
    75         );
    76         $this->timeFormat = datefmt_create(
    77             \Locale::getDefault(),
    78             \IntlDateFormatter::NONE,
    79             \IntlDateFormatter::SHORT,
    80             null,
    81             \IntlDateFormatter::GREGORIAN
    82         );
    8355    }
    8456
     
    11385        // Display the start and end times where they are provided
    11486        if ( $this->cs_event->is_start_date() ) {
    115             $output .= '    <div class="b4cs-date"><span class="b4cs-date-gliph">' . datefmt_format( $this->monthAndDateFormat, $this->cs_event->get_start_date() ) . '</span></div>' . "\n";
     87            $output .= '    <div class="b4cs-date"><span class="b4cs-date-gliph">' . Cs_Date_Utilities::get_site_formatted_date( $this->cs_event->get_start_date() ) . '</span></div>' . "\n";
    11688            $output .= '    <div class="b4cs-time">';
    117             $output .= '        <span class="b4cs-time-gliph b4cs-start-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_start_date() ) . '</span>';
    118             $output .= ( $this->cs_event->is_end_date() ) ? ' - <span class="b4cs-end-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_end_date() ) . '</span>' . "\n" : "\n";
     89            $output .= '        <span class="b4cs-time-gliph b4cs-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="b4cs-end-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_end_date() ) . '</span>' . "\n" : "\n";
    11991            $output .= '    </div>' . "\n";
    12092        }
  • blocks-for-churchsuite/trunk/blocks/build/inc/class-cs-event-list-renderer.php

    r3468626 r3470303  
    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-renderer.php';
     
    1011require_once plugin_dir_path( __FILE__ ) . 'class-cs-compact-event-view.php';
    1112
     13use amb_dev\b4cs\Cs_Date_Utilities;
    1214use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1315use amb_dev\b4cs\Cs_Renderer as Cs_Renderer;
     
    8284    protected function display_event_date( \DateTime $event_date ) : string {
    8385        $result = '<div class="b4cs-date">';
    84         $result .= '<span class="b4cs-day">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'EE' ), $event_date ) . '</span>';
    85         $result .= '<span class="b4cs-date-number">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'dd' ), $event_date ) . '</span>';
    86         $result .= '<span class="b4cs-month">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'MMM' ), $event_date ) . '</span>';
    87         $result .= '<span class="b4cs-year">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'yyyy' ), $event_date ) . '</span>';
     86        $result .= '<span class="b4cs-day">' . Cs_Date_Utilities::get_day_name_by_locale( $event_date ) . '</span>';
     87        $result .= '<span class="b4cs-date-number">' . Cs_Date_Utilities::get_day_number_by_locale( $event_date ) . '</span>';
     88        $result .= '<span class="b4cs-month">' . Cs_Date_Utilities::get_month_name_by_locale( $event_date ) . '</span>';
     89        $result .= '<span class="b4cs-year">' . Cs_Date_Utilities::get_year_by_locale( $event_date ) . '</span>';
    8890        $result .= '</div>';
    8991        return $result;
  • blocks-for-churchsuite/trunk/blocks/build/inc/class-cs-group.php

    r3468626 r3470303  
    33namespace amb_dev\b4cs;
    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\b4cs\Cs_Date_Utilities;
    811use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    912use amb_dev\b4cs\Cs_Item as Cs_Item;
     
    129132            $day_of_week_numeric = (int) $group_obj->day;
    130133            if ( ( $day_of_week_numeric >= 0 ) && ( $day_of_week_numeric <= 6 ) ) {
    131                 $output .= " on " . $dow_text = gmdate( 'l', strtotime( "Sunday +{$day_of_week_numeric} days" ) );
     134                $output .= __(' on ', 'blocks-for-churchsuite' ) . $dow_text = gmdate( 'l', strtotime( "Sunday +{$day_of_week_numeric} days" ) );
    132135            }
    133136        }
     
    146149     */
    147150    protected function fetch_time_of_meeting( \stdclass $group_obj ) : string {
    148         // TEST: \Locale::setDefault('de-DE');
    149         $timeFormat = datefmt_create(
    150             \Locale::getDefault(),
    151             \IntlDateFormatter::NONE,
    152             \IntlDateFormatter::SHORT,
    153             null,
    154             \IntlDateFormatter::GREGORIAN
    155         );
    156151        return ( isset( $group_obj->time ) && ( $group_obj->time !== '' ) )
    157             ? datefmt_format( $timeFormat, date_create( $group_obj->time ) )
     152            ? Cs_Date_Utilities::get_site_formatted_time( date_create( $group_obj->time ) )
    158153            : '' ;
    159     }
     154    }
    160155
    161156
  • blocks-for-churchsuite/trunk/blocks/src/cs-calendar/block.json

    r3468626 r3470303  
    33    "apiVersion": 3,
    44    "name": "b4cs/cs-calendar",
    5     "version": "1.0.2",
     5    "version": "1.0.3",
    66    "title": "Calendar for ChurchSuite",
    77    "category": "widgets",
  • blocks-for-churchsuite/trunk/blocks/src/cs-event-cards/block.json

    r3468626 r3470303  
    33    "apiVersion": 3,
    44    "name": "b4cs/cs-event-cards",
    5     "version": "1.0.2",
     5    "version": "1.0.3",
    66    "title": "Event Cards for ChurchSuite",
    77    "category": "widgets",
  • blocks-for-churchsuite/trunk/blocks/src/cs-event-list/block.json

    r3468626 r3470303  
    33    "apiVersion": 3,
    44    "name": "b4cs/cs-event-list",
    5     "version": "1.0.2",
     5    "version": "1.0.3",
    66    "title": "Event List for ChurchSuite",
    77    "category": "widgets",
  • blocks-for-churchsuite/trunk/blocks/src/cs-smallgroups/block.json

    r3468626 r3470303  
    33    "apiVersion": 3,
    44    "name": "b4cs/cs-smallgroups",
    5     "version": "1.0.2",
     5    "version": "1.0.3",
    66    "title": "Small Groups for ChurchSuite",
    77    "category": "widgets",
  • blocks-for-churchsuite/trunk/blocks/src/inc/class-cs-calendar-event-view.php

    r3388993 r3470303  
    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\b4cs\Cs_Date_Utilities;
    1012use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1113use amb_dev\b4cs\Cs_View as Cs_View;
     
    8183        $event_time = '';
    8284        if ( $this->cs_event->is_start_date() ) {
    83             $event_time .= '    <div class="b4cs-time"><span class="b4cs-start-time">' . date_format( $this->cs_event->get_start_date(), 'g:ia' ) . '</span>';
    84             $event_time .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="b4cs-end-time">' . date_format( $this->cs_event->get_end_date(), 'g:ia' ) . '</span>' : '';
     85            $event_time .= '    <div class="b4cs-time"><span class="b4cs-start-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_start_date() ) . '</span>';
     86            $event_time .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="b4cs-end-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_end_date() ) . '</span>' : '';
    8587            $event_time .= '</div>' . "\n";
    8688        }
  • blocks-for-churchsuite/trunk/blocks/src/inc/class-cs-calendar-renderer.php

    r3468626 r3470303  
    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-renderer.php';
     
    910require_once plugin_dir_path( __FILE__ ) . 'class-cs-calendar-event-view.php';
    1011
     12use amb_dev\b4cs\Cs_Date_Utilities;
    1113use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1214use amb_dev\b4cs\Cs_Renderer as Cs_Renderer;
     
    5153     * Constant values created to prevent unnecessary re-creation of values used in expressions
    5254     */
    53     protected \IntlDateFormatter $shortDayFormat;
    54     protected \IntlDateFormatter $shortMonthFormat;
    55     protected \IntlDateFormatter $longMonthFormat;
    5655    protected readonly \DateInterval $one_day;
    5756    protected readonly \DateInterval $one_week;
    5857    protected readonly \DateInterval $one_month;
    5958    protected readonly string $page_url;
     59   
    6060    protected \DateTime $today;
    6161    protected \DateTime $requested_date;
     
    7676     */
    7777    public function __construct( $atts ) {
    78         // Set the date formatters used to remove repeated instance creation
    79         // TEST: \Locale::setDefault('de-DE');
    80         $this->shortDayFormat = datefmt_create(
    81             \Locale::getDefault(),
    82             \IntlDateFormatter::FULL,
    83             \IntlDateFormatter::NONE,
    84             null,
    85             \IntlDateFormatter::GREGORIAN,
    86             'EEE'
    87         );
    88         $this->shortMonthFormat = datefmt_create(
    89             \Locale::getDefault(),
    90             \IntlDateFormatter::FULL,
    91             \IntlDateFormatter::NONE,
    92             null,
    93             \IntlDateFormatter::GREGORIAN,
    94             'MMM'
    95         );
    96         $this->longMonthFormat = datefmt_create(
    97             \Locale::getDefault(),
    98             \IntlDateFormatter::FULL,
    99             \IntlDateFormatter::NONE,
    100             null,
    101             \IntlDateFormatter::GREGORIAN,
    102             'MMMM'
    103         );
    10478
    10579        // Set the date constants used to remove repeated instance creation
     
    258232            . '    <div class="b4cs-calendar-month-header">' . "\n"
    259233            . '      <div class="b4cs-calendar-month-title">' . "\n"
    260             . '        ' . datefmt_format($this->longMonthFormat, $date) .  ' ' . $date->format( 'Y' ) . "\n"   /* . '        ' .  $date->format( 'F' ) . ' ' .  $date->format( 'Y' ) . "\n" */
     234            . '        ' . Cs_Date_Utilities::get_month_name_by_locale( $date ) .  ' ' . Cs_Date_Utilities::get_year_by_locale( $date ) . "\n"
    261235            . '      </div>' . "\n"
    262236            . '      <div class="b4cs-calendar-month-nav">' . "\n"
     
    279253        $period = new \DatePeriod( $sunday_date, $this->one_day, $saturday_date );
    280254        foreach ( $period as $day ) {
    281             /* $output .= '        <div class="b4cs-calendar-day-name-cell">' . $day->format( 'D' ) . '</div>' . "\n"; */
    282             $output .= '        <div class="b4cs-calendar-day-name-cell">' . datefmt_format($this->shortDayFormat, $day) . '</div>' . "\n";
     255            $output .= '        <div class="b4cs-calendar-day-name-cell">' . Cs_Date_Utilities::get_short_day_name_by_locale( $day ) . '</div>' . "\n";
    283256        }
    284257
     
    320293        $day = (int) $date->format( 'j' );
    321294        $output .= '    <div class="b4cs-date' . ( ( $day === 1 ) ? ' b4cs-first-day' : '' ) . '">' . "\n";
    322         $output .= '      <span class="b4cs-day">' . $date->format( 'D' ) . '</span>' . "\n";
    323         $output .= '      <span class="b4cs-date-number">' . $day . '</span>' . "\n";
    324         $output .= '      <span class="b4cs-month">' . datefmt_format($this->shortMonthFormat, $date) . '</span>' . "\n";   
    325         /* $output .= '      <span class="b4cs-month">' . $date->format( 'F' ) . '</span>' . "\n"; */
    326         $output .= '      <span class="b4cs-year">' . $date->format( 'Y' ) . '</span>' . "\n";
     295        $output .= '      <span class="b4cs-day">' . Cs_Date_Utilities::get_day_name_by_locale( $date ) . '</span>' . "\n";
     296        $output .= '      <span class="b4cs-date-number">' . Cs_Date_Utilities::get_day_number_by_locale( $date ) . '</span>' . "\n";
     297        $output .= '      <span class="b4cs-month">' . Cs_Date_Utilities::get_short_month_name_by_locale( $date ) . '</span>' . "\n";   
     298        $output .= '      <span class="b4cs-year">' . Cs_Date_Utilities::get_year_by_locale( $date ) . '</span>' . "\n";
    327299        $output .= '    </div>';
    328300        // Output the start of the  div containing the details of the events on this date
  • blocks-for-churchsuite/trunk/blocks/src/inc/class-cs-compact-event-view.php

    r3468626 r3470303  
    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\b4cs\Cs_Date_Utilities;
    1012use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1113use amb_dev\b4cs\Cs_View as Cs_View;
     
    3234
    3335    /*
    34      * Constant values created to prevent unnecessary re-creation of values used in expressions
    35      */
    36     protected \IntlDateFormatter $timeFormat;
    37 
    38     /*
    3936     * The event to be displayed, set via the constructor
    4037     * @since 1.0.0
     
    5653        parent::__construct( $cs );
    5754        $this->cs_event = $cs_event;
    58         $this->set_date_formatters();
    59     }
    60 
    61     /*
    62      * Set the 'constant' values used to remove repeated instance creation of the required date formatters.
    63      */
    64     private function set_date_formatters() {
    65         // Set the date formatters used to remove repeated instance creation
    66         $this->timeFormat = datefmt_create(
    67             \Locale::getDefault(),
    68             \IntlDateFormatter::NONE,
    69             \IntlDateFormatter::SHORT,
    70             null,
    71             \IntlDateFormatter::GREGORIAN
    72         );
    7355    }
    7456
     
    8870        // Display the event time and the end time if provided
    8971        if ( $this->cs_event->is_start_date() ) {
    90             $output .= '    <div class="b4cs-time"><span class="b4cs-start-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_start_date() ) . '</span>';
    91             $output .= ( $this->cs_event->is_end_date() ) ? '-' . '<span class="b4cs-end-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_end_date() ) . '</span>' : '';
     72            $output .= '    <div class="b4cs-time"><span class="b4cs-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="b4cs-end-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_end_date() ) . '</span>' : '';
    9274            $output .= '</div>' . "\n";
    9375        }
  • blocks-for-churchsuite/trunk/blocks/src/inc/class-cs-event-card-view.php

    r3468626 r3470303  
    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\b4cs\Cs_Date_Utilities;
    1012use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1113use amb_dev\b4cs\Cs_View as Cs_View;
     
    3234
    3335    /*
    34      * Constant values created to prevent unnecessary re-creation of values used in expressions
    35      */
    36     protected \IntlDateFormatter $monthAndDateFormat;
    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         // Set the constant values for the date formatters needed
    60         $this->set_date_formatters();
    61     }
    62 
    63     /*
    64      * Set the 'constant' values used to remove repeated instance creation of the required date formatters.
    65      */
    66     private function set_date_formatters() {
    67         // Set the date formatters used to remove repeated instance creation
    68         // TEST: \Locale::setDefault('de-DE');
    69         $this->monthAndDateFormat = datefmt_create(
    70             \Locale::getDefault(),
    71             \IntlDateFormatter::MEDIUM,
    72             \IntlDateFormatter::NONE,
    73             null,
    74             \IntlDateFormatter::GREGORIAN
    75         );
    76         $this->timeFormat = datefmt_create(
    77             \Locale::getDefault(),
    78             \IntlDateFormatter::NONE,
    79             \IntlDateFormatter::SHORT,
    80             null,
    81             \IntlDateFormatter::GREGORIAN
    82         );
    8355    }
    8456
     
    11385        // Display the start and end times where they are provided
    11486        if ( $this->cs_event->is_start_date() ) {
    115             $output .= '    <div class="b4cs-date"><span class="b4cs-date-gliph">' . datefmt_format( $this->monthAndDateFormat, $this->cs_event->get_start_date() ) . '</span></div>' . "\n";
     87            $output .= '    <div class="b4cs-date"><span class="b4cs-date-gliph">' . Cs_Date_Utilities::get_site_formatted_date( $this->cs_event->get_start_date() ) . '</span></div>' . "\n";
    11688            $output .= '    <div class="b4cs-time">';
    117             $output .= '        <span class="b4cs-time-gliph b4cs-start-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_start_date() ) . '</span>';
    118             $output .= ( $this->cs_event->is_end_date() ) ? ' - <span class="b4cs-end-time">' . datefmt_format( $this->timeFormat, $this->cs_event->get_end_date() ) . '</span>' . "\n" : "\n";
     89            $output .= '        <span class="b4cs-time-gliph b4cs-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="b4cs-end-time">' . Cs_Date_Utilities::get_site_formatted_time( $this->cs_event->get_end_date() ) . '</span>' . "\n" : "\n";
    11991            $output .= '    </div>' . "\n";
    12092        }
  • blocks-for-churchsuite/trunk/blocks/src/inc/class-cs-event-list-renderer.php

    r3468626 r3470303  
    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-renderer.php';
     
    1011require_once plugin_dir_path( __FILE__ ) . 'class-cs-compact-event-view.php';
    1112
     13use amb_dev\b4cs\Cs_Date_Utilities;
    1214use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    1315use amb_dev\b4cs\Cs_Renderer as Cs_Renderer;
     
    8284    protected function display_event_date( \DateTime $event_date ) : string {
    8385        $result = '<div class="b4cs-date">';
    84         $result .= '<span class="b4cs-day">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'EE' ), $event_date ) . '</span>';
    85         $result .= '<span class="b4cs-date-number">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'dd' ), $event_date ) . '</span>';
    86         $result .= '<span class="b4cs-month">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'MMM' ), $event_date ) . '</span>';
    87         $result .= '<span class="b4cs-year">' . datefmt_format( datefmt_create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN, 'yyyy' ), $event_date ) . '</span>';
     86        $result .= '<span class="b4cs-day">' . Cs_Date_Utilities::get_day_name_by_locale( $event_date ) . '</span>';
     87        $result .= '<span class="b4cs-date-number">' . Cs_Date_Utilities::get_day_number_by_locale( $event_date ) . '</span>';
     88        $result .= '<span class="b4cs-month">' . Cs_Date_Utilities::get_month_name_by_locale( $event_date ) . '</span>';
     89        $result .= '<span class="b4cs-year">' . Cs_Date_Utilities::get_year_by_locale( $event_date ) . '</span>';
    8890        $result .= '</div>';
    8991        return $result;
  • blocks-for-churchsuite/trunk/blocks/src/inc/class-cs-group.php

    r3468626 r3470303  
    33namespace amb_dev\b4cs;
    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\b4cs\Cs_Date_Utilities;
    811use amb_dev\b4cs\ChurchSuite as ChurchSuite;
    912use amb_dev\b4cs\Cs_Item as Cs_Item;
     
    129132            $day_of_week_numeric = (int) $group_obj->day;
    130133            if ( ( $day_of_week_numeric >= 0 ) && ( $day_of_week_numeric <= 6 ) ) {
    131                 $output .= " on " . $dow_text = gmdate( 'l', strtotime( "Sunday +{$day_of_week_numeric} days" ) );
     134                $output .= __(' on ', 'blocks-for-churchsuite' ) . $dow_text = gmdate( 'l', strtotime( "Sunday +{$day_of_week_numeric} days" ) );
    132135            }
    133136        }
     
    146149     */
    147150    protected function fetch_time_of_meeting( \stdclass $group_obj ) : string {
    148         // TEST: \Locale::setDefault('de-DE');
    149         $timeFormat = datefmt_create(
    150             \Locale::getDefault(),
    151             \IntlDateFormatter::NONE,
    152             \IntlDateFormatter::SHORT,
    153             null,
    154             \IntlDateFormatter::GREGORIAN
    155         );
    156151        return ( isset( $group_obj->time ) && ( $group_obj->time !== '' ) )
    157             ? datefmt_format( $timeFormat, date_create( $group_obj->time ) )
     152            ? Cs_Date_Utilities::get_site_formatted_time( date_create( $group_obj->time ) )
    158153            : '' ;
    159     }
     154    }
    160155
    161156
  • blocks-for-churchsuite/trunk/readme.txt

    r3468626 r3470303  
    44* Requires at least: 6.7
    55* Tested up to: 6.9.1
    6 * Stable tag: 1.0.2
     6* Stable tag: 1.0.3
    77* License: GPLv2 or later
    88
     
    265265
    266266
     267= 1.0.3 =
     268
     269**2026-02-26**
     270* Refactored the Locale code to use the wordpress site locale rather than
     271  the server locale, and to use the wordpress admin settings for full
     272  date or time output.  This means the time and date output should always
     273  be sympathetic with the Wordpress site settings.  Also moved all the
     274  time and date string creation to a new module so it can be easily
     275  modified without having to update many files.
     276* Version bump to 1.0.3
     277
     278
    267279= 1.0.2 =
    268280
Note: See TracChangeset for help on using the changeset viewer.