diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2023-01-28 17:38:32 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2023-01-28 17:38:32 +0100 |
commit | c2354e7397f44998691dfe8241e49c5a65f66dcc (patch) | |
tree | 5e910758e81742b37bf0a2ef3be15eed5941dead | |
parent | 9355261bfe664f181bd8b6c4fe23a2949e06769e (diff) | |
download | gigologadmin-c2354e7397f44998691dfe8241e49c5a65f66dcc.tar.gz gigologadmin-c2354e7397f44998691dfe8241e49c5a65f66dcc.tar.bz2 gigologadmin-c2354e7397f44998691dfe8241e49c5a65f66dcc.zip |
Use DateTimeImmutable for concert date/time.
-rw-r--r-- | includes/class-giglogadmin-concert.php | 12 | ||||
-rw-r--r-- | includes/giglogadmin-export-ical-handler.php | 11 | ||||
-rw-r--r-- | includes/view-helpers/class-giglogadmin-concertform.php | 2 | ||||
-rw-r--r-- | includes/view-helpers/class-giglogadmin-concertstable.php | 2 |
4 files changed, 10 insertions, 17 deletions
diff --git a/includes/class-giglogadmin-concert.php b/includes/class-giglogadmin-concert.php index 6c7c4da..f669c03 100644 --- a/includes/class-giglogadmin-concert.php +++ b/includes/class-giglogadmin-concert.php @@ -21,7 +21,7 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { private ?int $id; private ?string $cname; private ?GiglogAdmin_Venue $venue; - private ?string $cdate; + private DateTimeImmutable $cdate; private ?string $tickets; private ?string $eventlink; private ?int $status; @@ -50,7 +50,7 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { public function __construct( object $attrs ) { $this->id = isset( $attrs->id ) ? $attrs->id : null; $this->cname = isset( $attrs->wpgconcert_name ) ? $attrs->wpgconcert_name : null; - $this->cdate = isset( $attrs->wpgconcert_date ) ? $attrs->wpgconcert_date : null; + $this->cdate = new DateTimeImmutable( $attrs->wpgconcert_date ?? 'now' ); $this->tickets = isset( $attrs->wpgconcert_tickets ) ? $attrs->wpgconcert_tickets : null; $this->eventlink = isset( $attrs->wpgconcert_event ) ? $attrs->wpgconcert_event : null; $this->status = isset( $attrs->wpgconcert_status ) ? $attrs->wpgconcert_status : 0; @@ -141,7 +141,7 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { } if ( isset( $attrs->wpgconcert_date ) && $attrs->wpgconcert_date != $this->cdate ) { - $this->cdate = $attrs->wpgconcert_date; + $this->cdate = new DateTimeImmutable( $attrs->wpgconcert_date ); $need_update = true; } @@ -305,7 +305,7 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { $columns = array( 'wpgconcert_name' => $this->cname, 'venue' => $this->venue->id(), - 'wpgconcert_date' => $this->cdate, + 'wpgconcert_date' => $this->cdate->format( 'c' ), 'wpgconcert_tickets' => $this->tickets, 'wpgconcert_event' => $this->eventlink, 'wpgconcert_status' => $this->status, @@ -349,8 +349,8 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { /** * Return the date of the concert. */ - public function cdate() { - return $this->cdate ? $this->cdate : ''; + public function cdate() : DateTimeImmutable { + return $this->cdate; } /** diff --git a/includes/giglogadmin-export-ical-handler.php b/includes/giglogadmin-export-ical-handler.php index 44afbea..c230638 100644 --- a/includes/giglogadmin-export-ical-handler.php +++ b/includes/giglogadmin-export-ical-handler.php @@ -30,11 +30,9 @@ if ( ! function_exists( 'giglogadmin_export_ical_handler' ) ) { $cfullname = $concert->cname() . ' live at ' . $concert->venue()->name() . ', ' . $concert->venue()->city(); $cshortname = substr( $cfullname, 0, 20 ); - $fdate = strtotime( $concert->cdate() ); - $newformat = date( 'Ymd', $fdate ); $filename = sanitize_file_name( - "Concert-{$concert->venue()->name()}-{$newformat}-" + "Concert-{$concert->venue()->name()}-{$concert->cdate()->format( 'Ymd' )}-" . substr( $concert->cname(), 0, 30 ) ); @@ -58,12 +56,7 @@ if ( ! function_exists( 'giglogadmin_export_ical_handler' ) ) { // place the event ->setLocation( "{$concert->venue()->name()}, {$concert->venue()->city()}" ) // set the time - ->setDtstart( - new DateTime( - $newformat . 'T190000', - new DateTimezone( 'Europe/Oslo' ) - ) - ) + ->setDtstart( $concert->cdate() ) ->setDuration( 'PT4H' ); header( 'Content-Type: text/calendar' ); diff --git a/includes/view-helpers/class-giglogadmin-concertform.php b/includes/view-helpers/class-giglogadmin-concertform.php index 5cc3a47..cf7a466 100644 --- a/includes/view-helpers/class-giglogadmin-concertform.php +++ b/includes/view-helpers/class-giglogadmin-concertform.php @@ -66,7 +66,7 @@ if ( ! class_exists( 'GiglogAdmin_ConcertForm' ) ) { . '<label for="venue">Venue:</label>' . $this->get_venue_selector( $c->venue() ) . '<br>' // date has to be formatted else it is not red in the date field of html form . '<label for="cdate">Date:</label>' - . '<input type="date" id="cdate" name="cdate" value="' . esc_attr( date( 'Y-m-d', strtotime( $c->cdate() ?? '' ) ) ) . '"><br>' + . '<input type="date" id="cdate" name="cdate" value="' . esc_attr( $c->cdate()->format( 'Y-m-d' ) ?? '' ) . '"><br>' . '<label for="ticket">Tickets:</label>' . '<input type="text" id="ticket" name="ticket" value="' . esc_url( $c->tickets() ) . '"><br>' . '<label for="eventurl">Event link:</label>' diff --git a/includes/view-helpers/class-giglogadmin-concertstable.php b/includes/view-helpers/class-giglogadmin-concertstable.php index 1288cbd..9bf848c 100644 --- a/includes/view-helpers/class-giglogadmin-concertstable.php +++ b/includes/view-helpers/class-giglogadmin-concertstable.php @@ -291,7 +291,7 @@ if ( ! class_exists( 'GiglogAdmin_ConcertsTable' ) ) { $content .= '</td>'; $content .= - '<td>' . date( 'd.M.Y', strtotime( $concert->cdate() ) ) . '</td>' + '<td>' . $concert->cdate()->format( 'd.m.Y' ) . '</td>' . '<td>' . strtoupper( esc_html( $concert->cname() ) ) . '</td>' . '<td>' . esc_html( $concert->venue()->name() ) . '</td>'; |