From f6b3a92be7079bce3ff046c1d5f37b68da8dc5b4 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Mon, 27 Apr 2020 20:44:41 +0000 Subject: [PATCH] Add a new {timezone} placeholder This commit adds a `{timezone}` placeholder, which works by calling `$next_interval_start->format('T')`, giving us the abbreviated version (e.g. "EST", "MDT", etc.) while also accounting for daylight saving time. For future reference, we're using the *next* interval's start time as this placeholder is more likely to be used for when orders will be accepted again rather than when the current interval started. This avoids embarassing situations like "Please check back on $date at $time EST" when `$date` is in EDT. Fixes #22. --- CHANGELOG.md | 4 +++- README.md | 2 ++ src/OrderLimiter.php | 1 + tests/OrderLimiterTest.php | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7654519..9d4542c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added * Added "hourly" as a default interval for stores ([#20]). -* Added new placeholders to user-facing messaging ([#20]): +* Added new placeholders to user-facing messaging ([#20], [#26]): - `{current_interval:date}` (alias of `{current_interval}`) - `{current_interval:time}` - `{next_interval:date}` (alias of `{next_interval}`) - `{next_interval:time}` + - `{timezone}` * Added documentation for adding custom intervals, placeholders ([#23]). ### Updated @@ -62,3 +63,4 @@ Initial plugin release. [#13]: https://github.com/nexcess/limit-orders/pull/13 [#20]: https://github.com/nexcess/limit-orders/pull/20 [#23]: https://github.com/nexcess/limit-orders/pull/23 +[#26]: https://github.com/nexcess/limit-orders/pull/26 diff --git a/README.md b/README.md index 088d135..a3465d8 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ In any of these messages, you may also use the following variables:
An alias of {next_interval}
{next_interval:time}
The time the next interval will begin.
+
{timezone}
+
The store's timezone, e.g. "PST", "EDT", etc. This will automatically update based on Daylight Saving Time.
Dates and times will be formatted [according to the "date format" and "time format" settings for your store](https://wordpress.org/support/article/settings-general-screen/#date-format), respectively. diff --git a/src/OrderLimiter.php b/src/OrderLimiter.php index 330b269..06869e3 100644 --- a/src/OrderLimiter.php +++ b/src/OrderLimiter.php @@ -136,6 +136,7 @@ public function get_placeholders( $setting = '', $message = '' ) { '{next_interval}' => $next->format( $date_format ), '{next_interval:date}' => $next->format( $date_format ), '{next_interval:time}' => $next->format( $time_format ), + '{timezone}' => $next->format( 'T' ), ]; /** diff --git a/tests/OrderLimiterTest.php b/tests/OrderLimiterTest.php index 0142fc3..0cae878 100644 --- a/tests/OrderLimiterTest.php +++ b/tests/OrderLimiterTest.php @@ -224,6 +224,8 @@ public function get_message_should_replace_next_interval_time_placeholder() { /** * @test * @group Placeholders + * @ticket https://github.com/nexcess/limit-orders/issues/18 + * @ticket https://github.com/nexcess/limit-orders/issues/22 */ public function get_placeholders_should_return_an_array_of_default_placeholders() { update_option( 'date_format', 'F j, Y' ); @@ -243,6 +245,7 @@ public function get_placeholders_should_return_an_array_of_default_placeholders( $this->assertSame( $next->format( 'F j, Y' ), $placeholders['{next_interval}'] ); $this->assertSame( $next->format( 'F j, Y' ), $placeholders['{next_interval:date}'] ); $this->assertSame( $next->format( 'g:ia' ), $placeholders['{next_interval:time}'] ); + $this->assertSame( $next->format( 'T' ), $placeholders['{timezone}'] ); } /**