Skip to content

Commit

Permalink
Update tests, clarify a function comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Feb 28, 2024
1 parent 8e3d012 commit e57c6a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/includes/date-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function mc_recur_date( $ts ) {
*
* @param int|boolean $timestamp timestamp + offset or false if now.
*
* @return array day and month
* @return array day and integer representing the month offset. -1 for previous month, 0 for current month.
*/
function mc_first_day_of_week( $timestamp = false ) {
$start_of_week = ( get_option( 'start_of_week' ) === '1' || get_option( 'start_of_week' ) === '0' ) ? absint( get_option( 'start_of_week' ) ) : 0;
Expand Down
16 changes: 8 additions & 8 deletions tests/test-date-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public function test_mc_dateclass() {
$now = mc_dateclass( strtotime( 'now' ) );
$future = mc_dateclass( strtotime( '+1 day' ) );

$this->assertSame( $past, 'past-day past-date', 'Past date does not generate past date classes.' );
$this->assertSame( $now, 'current-day', 'Current date does not generate current date class.' );
$this->assertSame( $future, 'future-day', 'Future date does not generate future date class.' );
$this->assertStringContainsString( 'past-day past-date', $past, 'Past date does not generate past date classes.' );
$this->assertStringContainsString( 'current-day', $now, 'Current date does not generate current date class.' );
$this->assertStringContainsString( 'future-day', $future, 'Future date does not generate future date class.' );
}

/**
Expand Down Expand Up @@ -102,7 +102,7 @@ public function test_mc_checkdate() {

$this->assertSame( $valid, '2024-02-28', 'Valid Y-m-d dates should return the same information passed.' );
$this->assertSame( $string, '2024-02-28', 'Valid string dates should return a Y-m-d equivalent.' );
$this->assertSame( $invalid, false, 'Invalid dates should return false.' );
$this->assertSame( $invalid, gmdate( 'Y-m-d' ), 'Invalid dates should return today.' );
$this->assertSame( $notdate, '1970-01-01', 'Dates that are not valid in any way should return Unix epoch.' );
}

Expand All @@ -121,7 +121,7 @@ public function test_mc_recur_date() {
'day' => 'Thursday',
);
$second_week_expected = array(
'num' => 1,
'num' => 2,
'day' => 'Thursday',
);
$third_week_expected = array(
Expand Down Expand Up @@ -150,10 +150,10 @@ public function test_mc_first_day_of_week() {
$start_of_week = get_option( 'start_of_week' );
update_option( 'start_of_week', '0' );
$start_of_week_is_sunday = mc_first_day_of_week( strtotime( '2024-04-04' ) );
$sunday_expected = array( '31', 'March' );
$sunday_expected = array( '31', -1 );
update_option( 'start_of_week', '1' );
$start_of_week_is_monday = mc_first_day_of_week( strtotime( '2024-04-04' ) );
$monday_expected = array( '1', 'April' );
$monday_expected = array( '1', 0 );
update_option( 'start_of_week', '2' );
$start_of_week_is_other = mc_first_day_of_week( strtotime( '2024-04-04' ) );
update_option( 'start_of_week', $start_of_week ); // Reset to original setting.
Expand All @@ -169,7 +169,7 @@ public function test_mc_first_day_of_week() {
public function test_mc_date() {
$offset = get_option( 'gmt_offset' );
update_option( 'gmt_offset', '6' );
$timestamp = mc_date();
$timestamp = mc_date( '', false, false );
$includes_offset = mc_date( 'Y-m-d H:i:s', strtotime( '2024-02-28 00:00:00' ) );
$without_offset = mc_date( 'Y-m-d H:i:s', strtotime( '2024-02-28 00:00:00' ), false );
update_option( 'gmt_offset', $offset ); // Reset to original setting.
Expand Down

0 comments on commit e57c6a0

Please sign in to comment.