Ticket #8083: 8083.patch
| File 8083.patch, 5.0 KB (added by , 5 years ago) |
|---|
-
src/bp-core/bp-core-functions.php
diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php index 592f5b155..96121e07c 100644
function bp_core_time_since( $older_date, $newer_date = false ) { 1357 1357 return apply_filters( 'bp_core_time_since', $output, $older_date, $newer_date ); 1358 1358 } 1359 1359 1360 /** 1361 * Returns an age to display according to the birth date. 1362 * 1363 * @since 8.0.0 1364 * 1365 * @param int|string $birth_date A timestamp or a MySQL formatted date. 1366 * @return string The age to display. 1367 */ 1368 function bp_core_time_old( $birth_date ) { 1369 if ( ! is_numeric( $birth_date ) ) { 1370 $birth_date = mysql2date( 'U', $birth_date, false ); 1371 } 1372 1373 $date = (int) date_i18n( 'Y', $birth_date, false ); 1374 $now = (int) date_i18n( 'Y', bp_core_current_time( true, 'timestamp' ), false ); 1375 $age = $now - $date; 1376 1377 if ( 0 > $age ) { 1378 $age = 0; 1379 } 1380 1381 /** 1382 * Filters the value to use to display the age. 1383 * 1384 * @since 8.0.0 1385 * 1386 * @param string $value String representing the time since the older date. 1387 * @param int $age The age. 1388 */ 1389 $age_text = apply_filters( 1390 'bp_core_time_old', 1391 /* translators: %d: the age in years. */ 1392 _n( '%d year old', '%d years old', $age, 'buddypress' ), 1393 $age 1394 ); 1395 1396 return sprintf( $age_text, $age ); 1397 } 1398 1360 1399 /** 1361 1400 * Output an ISO-8601 date from a date string. 1362 1401 * -
src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php
diff --git src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php index 276253005..45d082280 100644
class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 479 479 <div class="bp-date-format-option"> 480 480 <label for="date-format-elapsed"> 481 481 <input type="radio" name="field-settings[date_format]" id="date-format-elapsed" <?php checked( 'elapsed', $settings['date_format'] ); ?> value="elapsed" aria-describedby="date-format-elapsed-setting" /> 482 <span class="date-format-label" id="date-format-elapsed-setting"><?php esc_html_e( 'Time elapsed', 'buddypress' ); ?></span> <?php _e( '<code>4 years ago</code>, <code>4 years from now</code>', 'buddypress' ); ?> 482 <span class="date-format-label" id="date-format-elapsed-setting"><?php esc_html_e( 'Time elapsed', 'buddypress' ); ?></span> <?php printf( '<code>%1$s</code>, <code>%2$s</code>', esc_html__( '4 years ago', 'buddypress' ), esc_html__( '4 years from now', 'buddypress' ) ); ?> 483 </label> 484 </div> 485 486 <div class="bp-date-format-option"> 487 <label for="date-format-age"> 488 <input type="radio" name="field-settings[date_format]" id="date-format-age" <?php checked( 'age', $settings['date_format'] ); ?> value="age" aria-describedby="date-format-age-setting" /> 489 <span class="date-format-label" id="date-format-age-setting"><?php esc_html_e( 'Age', 'buddypress' ); ?></span> <?php printf( '<code>%s</code>', esc_html__( '20 years old', 'buddypress' ) ); ?> 483 490 </label> 484 491 </div> 485 492 … … class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 601 608 $formatted = bp_core_time_since( $field_value ); 602 609 break; 603 610 611 case 'age' : 612 $formatted = bp_core_time_old( $field_value ); 613 break; 614 604 615 case 'custom' : 605 616 $formatted = date_i18n( $settings['date_format_custom'], $field_value ); 606 617 break; -
tests/phpunit/testcases/core/functions.php
diff --git tests/phpunit/testcases/core/functions.php tests/phpunit/testcases/core/functions.php index f3c20c1d8..0575ead4d 100644
class BP_Tests_Core_Functions extends BP_UnitTestCase { 187 187 $this->assertEquals( 'sometime ago', bp_core_time_since( $then, $now ) ); 188 188 } 189 189 190 /** 191 * @group bp_core_time_old 192 */ 193 public function test_bp_core_time_old_timestamp() { 194 $then = time() - 473040000; 195 $this->assertEquals( '15 years old', bp_core_time_old( $then ) ); 196 } 197 198 /** 199 * @group bp_core_time_old 200 */ 201 public function test_bp_core_time_old_mysql() { 202 $then = gmdate( 'Y-m-d h:i:s', time() - 473040000 ); 203 $this->assertEquals( '15 years old', bp_core_time_old( $then ) ); 204 } 205 206 /** 207 * @group bp_core_time_old 208 */ 209 public function test_bp_core_time_old_one() { 210 $then = time() - 31536000; 211 $this->assertEquals( '1 year old', bp_core_time_old( $then ) ); 212 } 213 214 /** 215 * @group bp_core_time_old 216 */ 217 public function test_bp_core_time_old_zero() { 218 $now = time(); 219 $this->assertEquals( '0 years old', bp_core_time_old( $now ) ); 220 } 221 222 /** 223 * @group bp_core_time_old 224 */ 225 public function test_bp_core_time_old_future() { 226 $then = time() + 31536000; 227 $this->assertEquals( '0 years old', bp_core_time_old( $then ) ); 228 } 229 230 /** 231 * @group bp_core_time_old 232 */ 233 public function test_bp_core_time_old_decimals() { 234 $then = time() - 15768000; 235 $this->assertEquals( '1 year old', bp_core_time_old( $then ) ); 236 } 237 190 238 /** 191 239 * @group bp_format_time 192 240 */