Skip to content

Commit

Permalink
時間の指定ミスに対応 (#43)
Browse files Browse the repository at this point in the history
セットされていない値でエラーが起きないようにする
  • Loading branch information
fumikito authored Jun 20, 2023
2 parents 2e9a32e + 548b9b4 commit 9284007
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Kunoichi/GaCommunicator/Services/AbstractApiConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,22 @@ protected function get_date_range_condition( $condition ) {
foreach ( [ 'end', 'start' ] as $key ) {
if ( isset( $condition[ $key ] ) && preg_match( '/^\d{4}-\d{2}-\d{2}$/u', $condition[ $key ] ) ) {
// Valid date already set.
if ( 'end' === $key ) {
$end = $condition[ $key ];
}
continue;
}
switch ( $key ) {
case 'end':
$offset_days = $condition['offset_days'] ?? 0;
// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$end = current_time( 'timestamp' ) - 60 * 60 * 24 * $condition['offset_days'];
$end = current_time( 'timestamp' ) - 60 * 60 * 24 * $offset_days;
$condition['end'] = date_i18n( 'Y-m-d', $end );
break;
case 'start':
if ( $end ) {
$condition['start'] = date_i18n( 'Y-m-d', $end - 60 * 60 * 24 * $condition['days_before'] );
}
$days_before = $condition['days_before'] ?? 7;
$time = $end ?: time();
$condition['start'] = date_i18n( 'Y-m-d', $time - 60 * 60 * 24 * $days_before );
break;
}
}
Expand Down

0 comments on commit 9284007

Please sign in to comment.