? ? Success

User tests: Successful: Unsuccessful:

avatar izharaazmi
izharaazmi
5 Jul 2016

Summary of Changes

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.

Testing Instructions

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.

avatar izharaazmi izharaazmi - open - 5 Jul 2016
avatar izharaazmi izharaazmi - change - 5 Jul 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 5 Jul 2016
Labels Added: ? ?
avatar izharaazmi izharaazmi - change - 5 Jul 2016
The description was changed
avatar brianteeman brianteeman - change - 5 Jul 2016
Category Libraries
avatar brianteeman brianteeman - change - 5 Jul 2016
Labels
avatar brianteeman brianteeman - change - 12 Jul 2016
Category Libraries Libraries Unit Tests
avatar pritalpatel pritalpatel - test_item - 18 Jul 2016 - Tested successfully
avatar pritalpatel
pritalpatel - comment - 18 Jul 2016

I have tested this item successfully on 3870104


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11026.

avatar pritalpatel
pritalpatel - comment - 18 Jul 2016

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.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11026.

avatar bertmert bertmert - test_item - 23 Jul 2016 - Tested successfully
avatar bertmert
bertmert - comment - 23 Jul 2016

I have tested this item successfully on 3870104


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11026.

avatar brianteeman brianteeman - change - 23 Jul 2016
Status Pending Ready to Commit
Labels
avatar brianteeman
brianteeman - comment - 23 Jul 2016

RTC - thanks


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11026.

avatar joomla-cms-bot joomla-cms-bot - change - 23 Jul 2016
Labels Added: ?
avatar rdeutz rdeutz - change - 14 Aug 2016
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
avatar brianteeman brianteeman - change - 18 Aug 2016
Labels Removed: ?
avatar HLeithner
HLeithner - comment - 25 Aug 2016

Dump question but shouldn't it be KiB, MiB, and so on to reflect the correct SI Binary prefix?

avatar brianteeman
brianteeman - comment - 25 Aug 2016

@HLeithner not a dumb question but its not standard behaviour to use SI for this

avatar HLeithner
HLeithner - comment - 25 Aug 2016

@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"

avatar brianteeman
brianteeman - comment - 25 Aug 2016

No we have to use the "real world standard"

avatar izharaazmi
izharaazmi - comment - 25 Aug 2016

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

avatar HLeithner
HLeithner - comment - 25 Aug 2016

@izharaazmi sounds good
@brianteeman I like that ;-) and just wanted to notice.

avatar brianteeman
brianteeman - comment - 25 Aug 2016

Please no more options

avatar zero-24
zero-24 - comment - 25 Aug 2016

i gues @izharaazmi means on code not in the UI ?

avatar brianteeman
brianteeman - comment - 25 Aug 2016

No point having an option in the code if you have to hack the core to use
it ;)

avatar mbabker
mbabker - comment - 25 Aug 2016

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.

avatar HLeithner
HLeithner - comment - 25 Aug 2016

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 ;-)

avatar izharaazmi
izharaazmi - comment - 26 Aug 2016

I have added the support for IEC Binary prefixes. It is supposed to be fully B/C. Please test and review.

Add a Comment

Login with GitHub to post a comment