Skip to content

Commit

Permalink
Use gmdate() to fix PHPCS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Apr 24, 2020
1 parent 69f0d5e commit 34e23d9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
36 changes: 18 additions & 18 deletions includes/class-solrpower-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,26 +288,26 @@ function build_document(
$doc->setField( 'displaymodified', $post_info->post_modified );

$post_time = strtotime( $post_info->post_date );
$doc->setField( 'year_i', date( 'Y', $post_time ) );
$doc->setField( 'month_i', date( 'm', $post_time ) );
$doc->setField( 'day_i', date( 'd', $post_time ) );
$doc->setField( 'week_i', date( 'W', $post_time ) );
$doc->setField( 'dayofweek_i', ( date( 'w', $post_time ) + 1 ) );
$doc->setField( 'dayofweek_iso_i', date( 'w', $post_time ) );
$doc->setField( 'hour_i', date( 'H', $post_time ) );
$doc->setField( 'minute_i', date( 'i', $post_time ) );
$doc->setField( 'second_i', date( 's', $post_time ) );
$doc->setField( 'year_i', gmdate( 'Y', $post_time ) );
$doc->setField( 'month_i', gmdate( 'm', $post_time ) );
$doc->setField( 'day_i', gmdate( 'd', $post_time ) );
$doc->setField( 'week_i', gmdate( 'W', $post_time ) );
$doc->setField( 'dayofweek_i', ( gmdate( 'w', $post_time ) + 1 ) );
$doc->setField( 'dayofweek_iso_i', gmdate( 'w', $post_time ) );
$doc->setField( 'hour_i', gmdate( 'H', $post_time ) );
$doc->setField( 'minute_i', gmdate( 'i', $post_time ) );
$doc->setField( 'second_i', gmdate( 's', $post_time ) );

$post_time = strtotime( $post_info->post_modified );
$doc->setField( 'post_modified_year_i', date( 'Y', $post_time ) );
$doc->setField( 'post_modified_month_i', date( 'm', $post_time ) );
$doc->setField( 'post_modified_day_i', date( 'd', $post_time ) );
$doc->setField( 'post_modified_week_i', date( 'W', $post_time ) );
$doc->setField( 'post_modified_dayofweek_i', ( date( 'w', $post_time ) + 1 ) );
$doc->setField( 'post_modified_dayofweek_iso_i', date( 'w', $post_time ) );
$doc->setField( 'post_modified_hour_i', date( 'H', $post_time ) );
$doc->setField( 'post_modified_minute_i', date( 'i', $post_time ) );
$doc->setField( 'post_modified_second_i', date( 's', $post_time ) );
$doc->setField( 'post_modified_year_i', gmdate( 'Y', $post_time ) );
$doc->setField( 'post_modified_month_i', gmdate( 'm', $post_time ) );
$doc->setField( 'post_modified_day_i', gmdate( 'd', $post_time ) );
$doc->setField( 'post_modified_week_i', gmdate( 'W', $post_time ) );
$doc->setField( 'post_modified_dayofweek_i', ( gmdate( 'w', $post_time ) + 1 ) );
$doc->setField( 'post_modified_dayofweek_iso_i', gmdate( 'w', $post_time ) );
$doc->setField( 'post_modified_hour_i', gmdate( 'H', $post_time ) );
$doc->setField( 'post_modified_minute_i', gmdate( 'i', $post_time ) );
$doc->setField( 'post_modified_second_i', gmdate( 's', $post_time ) );

$doc->setField( 'post_status', $post_info->post_status );
$doc->setField( 'post_parent', $post_info->post_parent );
Expand Down
20 changes: 10 additions & 10 deletions includes/class-solrpower-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ function parse_date_query( $date_query ) {
} else {
$the_date = strtotime( $the_date );
$the_date = ( ( isset( $dq['inclusive'] ) && $dq['inclusive'] ) || $inclusive ) ? $the_date : strtotime( '-1 second', $the_date );
$the_date = date( 'Y-m-d H:i:s', $the_date );
$the_date = gmdate( 'Y-m-d H:i:s', $the_date );
$the_date = SolrPower_Sync::get_instance()->format_date( $the_date );
$column = ( isset( $dq['column'] ) ) ? $dq['column'] : 'post_date';

Expand All @@ -990,7 +990,7 @@ function parse_date_query( $date_query ) {

$the_date = strtotime( $the_date );
$the_date = ( ( isset( $dq['inclusive'] ) && $dq['inclusive'] ) || $inclusive ) ? $the_date : strtotime( '+1 second', $the_date );
$the_date = date( 'Y-m-d H:i:s', $the_date );
$the_date = gmdate( 'Y-m-d H:i:s', $the_date );
$the_date = SolrPower_Sync::get_instance()->format_date( $the_date );
$column = ( isset( $dq['column'] ) ) ? $dq['column'] : 'post_date';

Expand Down Expand Up @@ -1026,7 +1026,7 @@ function date_query( $dq, $inclusive = false, $type = false ) {
&& array_key_exists( 'day', $dq ) )
) {

$the_date = date( 'Y-m-d', strtotime( $dq['year'] . '-' . $dq['month'] . '-' . $dq['day'] ) );
$the_date = gmdate( 'Y-m-d', strtotime( $dq['year'] . '-' . $dq['month'] . '-' . $dq['day'] ) );

switch ( $type ) {
case 'before':
Expand All @@ -1052,11 +1052,11 @@ function date_query( $dq, $inclusive = false, $type = false ) {
return '(year_i:[* TO ' . $year . '])';
}
if ( ! isset( $dq['day'] ) ) {
$the_date = date( 'Y-m-d', strtotime( $dq['year'] . '-' . $dq['month'] . '-01' ) );
$the_date = gmdate( 'Y-m-d', strtotime( $dq['year'] . '-' . $dq['month'] . '-01' ) );
if ( ( isset( $dq['inclusive'] ) && true === $dq['inclusive'] )
|| true === $inclusive
) {
$the_date = date( 'Y-m-t', strtotime( $dq['year'] . '-' . $dq['month'] . '-01' ) );
$the_date = gmdate( 'Y-m-t', strtotime( $dq['year'] . '-' . $dq['month'] . '-01' ) );
}

return '(' . $column . ':' . '[* TO ' . $the_date . 'T00:00:00Z])';
Expand All @@ -1071,19 +1071,19 @@ function date_query( $dq, $inclusive = false, $type = false ) {
return '(year_i:[' . $year . ' TO *])';
}
if ( ! isset( $dq['day'] ) ) {
$the_date = date( 'Y-m-d', strtotime( $dq['year'] . '-' . $dq['month'] . '-01' ) );
$the_date = gmdate( 'Y-m-d', strtotime( $dq['year'] . '-' . $dq['month'] . '-01' ) );
if ( ( isset( $dq['inclusive'] ) && false === $dq['inclusive'] )
|| false === $inclusive
) {
$the_date = date( 'Y-m-t', strtotime( $dq['year'] . '-' . $dq['month'] . '-01' ) );
$the_date = date( 'Y-m-d', strtotime( '+1 Day', strtotime( $the_date ) ) );
$the_date = gmdate( 'Y-m-t', strtotime( $dq['year'] . '-' . $dq['month'] . '-01' ) );
$the_date = gmdate( 'Y-m-d', strtotime( '+1 Day', strtotime( $the_date ) ) );
}

return '(' . $column . ':' . '[' . $the_date . 'T00:00:00Z TO *])';
} else {
$the_date = date( 'Y-m-t', strtotime( $dq['year'] . '-' . $dq['month'] . '-' . $dq['day'] ) );
$the_date = gmdate( 'Y-m-t', strtotime( $dq['year'] . '-' . $dq['month'] . '-' . $dq['day'] ) );
if ( ( isset( $dq['inclusive'] ) && $dq['inclusive'] ) || $inclusive ) {
$the_date = date( 'Y-m-d', strtotime( '+1 Day', strtotime( $the_date ) ) );
$the_date = gmdate( 'Y-m-d', strtotime( '+1 Day', strtotime( $the_date ) ) );
}

return '(' . $column . ':' . '[' . $the_date . 'T00:00:00Z TO *])';
Expand Down
2 changes: 1 addition & 1 deletion template/s4w_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
$result['authorlink'],
$result['author'],
get_the_category_list( ', ', '', $result['id'] ),
date( 'm/d/Y', strtotime( $result['date'] ) ),
gmdate( 'm/d/Y', strtotime( $result['date'] ) ),
$result['comment_link'],
$result['numcomments']
);
Expand Down
2 changes: 1 addition & 1 deletion template/s4wp_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
$result['authorlink'],
$result['author'],
get_the_category_list( ', ', '', $result['id'] ),
date( 'm/d/Y', strtotime( $result['date'] ) ),
gmdate( 'm/d/Y', strtotime( $result['date'] ) ),
$result['comment_link'],
$result['numcomments']
);
Expand Down

0 comments on commit 34e23d9

Please sign in to comment.