Changeset 52955
- Timestamp:
- 03/18/2022 08:46:17 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-constants.php
r52610 r52955 23 23 * 24 24 * @since 4.4.0 25 * @since 6.0.0 `PB_IN_BYTES`, `EB_IN_BYTES`, `ZB_IN_BYTES`, and `YB_IN_BYTES` were added. 25 26 */ 26 27 define( 'KB_IN_BYTES', 1024 ); … … 28 29 define( 'GB_IN_BYTES', 1024 * MB_IN_BYTES ); 29 30 define( 'TB_IN_BYTES', 1024 * GB_IN_BYTES ); 31 define( 'PB_IN_BYTES', 1024 * TB_IN_BYTES ); 32 define( 'EB_IN_BYTES', 1024 * PB_IN_BYTES ); 33 define( 'ZB_IN_BYTES', 1024 * EB_IN_BYTES ); 34 define( 'YB_IN_BYTES', 1024 * ZB_IN_BYTES ); 30 35 /**#@-*/ 31 36 -
trunk/src/wp-includes/functions.php
r52933 r52955 442 442 443 443 /** 444 * Convert number of bytes largest unitbytes will fit into.444 * Converts a number of bytes to the largest unit the bytes will fit into. 445 445 * 446 446 * It is easier to read 1 KB than 1024 bytes and 1 MB than 1048576 bytes. Converts 447 447 * number of bytes to human readable number by taking the number of that unit 448 * that the bytes will go into it. Supports TB value.448 * that the bytes will go into it. Supports YB value. 449 449 * 450 450 * Please note that integers in PHP are limited to 32 bits, unless they are on … … 456 456 * 457 457 * @since 2.3.0 458 * @since 6.0.0 Support for PB, EB, ZB, and YB was added. 458 459 * 459 460 * @param int|string $bytes Number of bytes. Note max integer size for integers. … … 463 464 function size_format( $bytes, $decimals = 0 ) { 464 465 $quant = array( 466 /* translators: Unit symbol for yottabyte. */ 467 _x( 'YB', 'unit symbol' ) => YB_IN_BYTES, 468 /* translators: Unit symbol for zettabyte. */ 469 _x( 'ZB', 'unit symbol' ) => ZB_IN_BYTES, 470 /* translators: Unit symbol for exabyte. */ 471 _x( 'EB', 'unit symbol' ) => EB_IN_BYTES, 472 /* translators: Unit symbol for petabyte. */ 473 _x( 'PB', 'unit symbol' ) => PB_IN_BYTES, 465 474 /* translators: Unit symbol for terabyte. */ 466 475 _x( 'TB', 'unit symbol' ) => TB_IN_BYTES, -
trunk/tests/phpunit/tests/functions/sizeFormat.php
r49006 r52955 4 4 * Tests for size_format() 5 5 * 6 * @ticket 22405 6 7 * @ticket 36635 8 * @ticket 40875 7 9 * 8 10 * @group functions.php … … 13 15 public function _data_size_format() { 14 16 return array( 17 // Invalid values 15 18 array( array(), 0, false ), 16 19 array( 'baba', 0, false ), … … 18 21 array( '-1', 0, false ), 19 22 array( -1, 0, false ), 23 // Bytes 20 24 array( 0, 0, '0 B' ), 21 25 array( 1, 0, '1 B' ), 22 26 array( 1023, 0, '1,023 B' ), 27 // Kilobytes 23 28 array( KB_IN_BYTES, 0, '1 KB' ), 24 29 array( KB_IN_BYTES, 2, '1.00 KB' ), … … 26 31 array( 2.5 * KB_IN_BYTES, 2, '2.50 KB' ), 27 32 array( 10 * KB_IN_BYTES, 0, '10 KB' ), 33 // Megabytes 28 34 array( (string) 1024 * KB_IN_BYTES, 2, '1.00 MB' ), 29 35 array( MB_IN_BYTES, 0, '1 MB' ), 30 36 array( 2.5 * MB_IN_BYTES, 0, '3 MB' ), 31 37 array( 2.5 * MB_IN_BYTES, 2, '2.50 MB' ), 38 // Gigabytes 32 39 array( (string) 1024 * MB_IN_BYTES, 2, '1.00 GB' ), 33 40 array( GB_IN_BYTES, 0, '1 GB' ), 34 41 array( 2.5 * GB_IN_BYTES, 0, '3 GB' ), 35 42 array( 2.5 * GB_IN_BYTES, 2, '2.50 GB' ), 43 // Terabytes 36 44 array( (string) 1024 * GB_IN_BYTES, 2, '1.00 TB' ), 37 45 array( TB_IN_BYTES, 0, '1 TB' ), 38 46 array( 2.5 * TB_IN_BYTES, 0, '3 TB' ), 39 47 array( 2.5 * TB_IN_BYTES, 2, '2.50 TB' ), 48 // Petabytes 49 array( (string) 1024 * TB_IN_BYTES, 2, '1.00 PB' ), 50 array( PB_IN_BYTES, 0, '1 PB' ), 51 array( 2.5 * PB_IN_BYTES, 0, '3 PB' ), 52 array( 2.5 * PB_IN_BYTES, 2, '2.50 PB' ), 53 // Exabytes 54 array( (string) 1024 * PB_IN_BYTES, 2, '1.00 EB' ), 55 array( EB_IN_BYTES, 0, '1 EB' ), 56 array( 2.5 * EB_IN_BYTES, 0, '3 EB' ), 57 array( 2.5 * EB_IN_BYTES, 2, '2.50 EB' ), 58 // Zettabytes 59 array( (string) 1024 * EB_IN_BYTES, 2, '1.00 ZB' ), 60 array( ZB_IN_BYTES, 0, '1 ZB' ), 61 array( 2.5 * ZB_IN_BYTES, 0, '3 ZB' ), 62 array( 2.5 * ZB_IN_BYTES, 2, '2.50 ZB' ), 63 // Yottabytes 64 array( (string) 1024 * ZB_IN_BYTES, 2, '1.00 YB' ), 65 array( YB_IN_BYTES, 0, '1 YB' ), 66 array( 2.5 * YB_IN_BYTES, 0, '3 YB' ), 67 array( 2.5 * YB_IN_BYTES, 2, '2.50 YB' ), 68 // Edge values 40 69 array( TB_IN_BYTES + ( TB_IN_BYTES / 2 ) + MB_IN_BYTES, 1, '1.5 TB' ), 41 70 array( TB_IN_BYTES - MB_IN_BYTES - KB_IN_BYTES, 3, '1,023.999 GB' ),
Note: See TracChangeset
for help on using the changeset viewer.