User tests: Successful: Unsuccessful:
Allow parsing of input in suffixed format such as "128M", "1.2G", "340K", "1234.56 MB" for conversion.
Allow returning number of bytes without any unit suffix
Added support for suffixes EB, ZB, YB.
Apparently no straight-forward way to test within Joomla. Please write some code that uses the method JHtmlNumber::bytes()
A sample code is given below (Seeds are taken from Unit Test, you may want to use your own test data):
echo JHtml::_('number.bytes', 1, 'auto'). "\n";
echo JHtml::_('number.bytes', 1024, 'auto'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024, 'auto'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024, 'auto'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024, 'auto'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024, 'auto'). "\n";
echo JHtml::_('number.bytes', 0, 'auto'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'auto'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'YB'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'ZB'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'EB'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024, 'PB'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024, 'TB'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024, 'GB'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024, 'MB'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024, 'kB'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024, 'b'). "\n";
echo JHtml::_('number.bytes', 1024 * 1024 * 1024 * 1024 * 1024, ''). "\n";
echo JHtml::_('number.bytes', 1357, 'auto'). "\n";
echo JHtml::_('number.bytes', 1357, 'auto', 1). "\n";
echo JHtml::_('number.bytes', 1357, 'auto', 2). "\n";
echo JHtml::_('number.bytes', 1357, 'auto', 3). "\n";
echo JHtml::_('number.bytes', 1357, 'auto', 4). "\n";
echo JHtml::_('number.bytes', '1024K', 'auto'). "\n";
echo JHtml::_('number.bytes', '1 GB', 'MB'). "\n";
echo JHtml::_('number.bytes', '1.0752E+4 MB', 'GB'). "\n";
Expect the following output from above:
1 b
1 kB
1 MB
1 GB
1 TB
1 PB
0
1 YB
1 YB
1024 ZB
1048576 EB
1 PB
1024 TB
1048576 GB
1073741824 MB
1099511627776 kB
1.1258999068426E+15 b
1.1258999068426E+15
1.33 kB
1.3 kB
1.33 kB
1.325 kB
1.3252 kB
1 MB
1024 MB
10.5 GB
PS: There is probably a B/C break due to 'kb' changed to 'kB'. Please advise if that needs to be addressed.
Status | New | ⇒ | Pending |
Labels |
Added:
?
?
|
Category | ⇒ | Libraries |
Labels |
Category | Libraries | ⇒ | Libraries Unit Tests |
I have apply this sample code in my joomla-cms/components/com_content/views/article/tmpl/default.php file and see the result. It's works successfully.
Thanks.
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
Labels |
RTC - thanks
Labels |
Added:
?
|
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-08-14 15:50:09 |
Closed_By | ⇒ | rdeutz |
Labels |
Removed:
?
|
Dump question but shouldn't it be KiB, MiB, and so on to reflect the correct SI Binary prefix?
@HLeithner not a dumb question but its not standard behaviour to use SI for this
@brianteeman that depends ;-) The ISO/IEC 80000-13:2008 tells us that the standard is to use it ;-)
I know that most people don't use it, I don't use it always but try to. But thats not the point. The question is should Joomla should use the/a "official standard"
No we have to use the "real world standard"
I agree with @brianteeman on this. However, we can add another method in the same class that is IEC aware or simply add another parameter to the same method like $iec = false
@izharaazmi sounds good
@brianteeman I like that ;-) and just wanted to notice.
Please no more options
i gues @izharaazmi means on code not in the UI
No point having an option in the code if you have to hack the core to use
it ;)
No point having an option in the code if you have to hack the core to use it
That's exactly what parameters on method calls are for. Not every option has to be something managed via the UI, it could be an option used by developers in their code to change a behavior.
In this case it would be even better to have a option in the ui to switch the complete site from one version to the other and not only a part of the site ;-)
I have added the support for IEC Binary prefixes. It is supposed to be fully B/C. Please test and review.
I have tested this item✅ successfully on 3870104
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11026.