Skip to content

Commit

Permalink
Add a new {timezone} placeholder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stevegrunwell committed Apr 27, 2020
1 parent a34754b commit f6b3a92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ In any of these messages, you may also use the following variables:
<dd>An alias of <var>{next_interval}</var></dd>
<dt>{next_interval:time}</dt>
<dd>The time the next interval will begin.</dd>
<dt>{timezone}</dt>
<dd>The store's timezone, e.g. "PST", "EDT", etc. This will automatically update based on Daylight Saving Time.</dd>
</dl>

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.
Expand Down
1 change: 1 addition & 0 deletions src/OrderLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
];

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/OrderLimiterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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}'] );
}

/**
Expand Down

0 comments on commit f6b3a92

Please sign in to comment.