Skip to content

Commit

Permalink
Merge pull request #25 from nexcess/fix/timezone-offset
Browse files Browse the repository at this point in the history
Ensure hourly intervals are calculated using 24hr time
  • Loading branch information
bswatson authored Apr 27, 2020
2 parents e0c022a + 47d3860 commit a34754b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OrderLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function get_interval_start() {
switch ( $interval ) {
case 'hourly':
// Start at the top of the current hour.
$start = $start->setTime( (int) $start->format( 'h' ), 0, 0 );
$start = $start->setTime( (int) $start->format( 'G' ), 0, 0 );
break;

case 'daily':
Expand Down
20 changes: 20 additions & 0 deletions tests/OrderLimiterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,26 @@ public function get_interval_start_for_hourly() {
);
}

/**
* @test
* @depends get_interval_start_for_hourly
* @group Intervals
* @ticket https://github.com/nexcess/limit-orders/issues/24
*/
public function get_interval_start_should_use_24hr_time() {
update_option( OrderLimiter::OPTION_KEY, [
'interval' => 'hourly',
] );

$now = new \DateTimeImmutable( '2020-04-27 18:05:00', wp_timezone() );
$start = new \DateTimeImmutable( '2020-04-27 18:00:00', wp_timezone() );

$this->assertSame(
$start->format( 'r' ),
( new OrderLimiter( $now ) )->get_interval_start()->format( 'r' )
);
}

/**
* @test
* @group Intervals
Expand Down

0 comments on commit a34754b

Please sign in to comment.