Skip to content

Improve JHtmlNumber::bytes#11026

Merged
rdeutz merged 2 commits intojoomla:stagingfrom
izharaazmi:jhtml-number-bytes
Aug 14, 2016
Merged

Improve JHtmlNumber::bytes#11026
rdeutz merged 2 commits intojoomla:stagingfrom
izharaazmi:jhtml-number-bytes

Conversation

@izharaazmi
Copy link
Copy Markdown
Contributor

@izharaazmi izharaazmi commented Jul 5, 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.

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.

No B/C break hopefully.
…nce this is a JHtml method and not a conversion function we probably can afford little loss of significance.
@izharaazmi izharaazmi force-pushed the jhtml-number-bytes branch from ac35546 to 3870104 Compare July 5, 2016 13:18
@pritalpatel
Copy link
Copy Markdown

I have tested this item ✅ successfully on 3870104


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

@pritalpatel
Copy link
Copy Markdown

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.

@ghost
Copy link
Copy Markdown

ghost commented Jul 23, 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.

@brianteeman
Copy link
Copy Markdown
Contributor

RTC - thanks


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jul 23, 2016
@rdeutz rdeutz merged commit 71c7651 into joomla:staging Aug 14, 2016
@rdeutz rdeutz added this to the Joomla 3.6.3 milestone Aug 14, 2016
@brianteeman brianteeman removed the RTC This Pull Request is Ready To Commit label Aug 18, 2016
ggppdk pushed a commit to ggppdk/joomla-cms that referenced this pull request Aug 19, 2016
* Improve JHtmlNumber::bytes

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.

No B/C break hopefully.

* Fix unit test failure, the failure is due to float comparison, but since this is a JHtml method and not a conversion function we probably can afford little loss of significance.
@izharaazmi izharaazmi deleted the jhtml-number-bytes branch August 23, 2016 06:23
@HLeithner
Copy link
Copy Markdown
Member

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

@brianteeman
Copy link
Copy Markdown
Contributor

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

@HLeithner
Copy link
Copy Markdown
Member

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

@brianteeman
Copy link
Copy Markdown
Contributor

No we have to use the "real world standard"

@izharaazmi
Copy link
Copy Markdown
Contributor Author

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

@HLeithner
Copy link
Copy Markdown
Member

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

@brianteeman
Copy link
Copy Markdown
Contributor

Please no more options

@zero-24
Copy link
Copy Markdown
Contributor

zero-24 commented Aug 25, 2016

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

@brianteeman
Copy link
Copy Markdown
Contributor

brianteeman commented Aug 25, 2016 via email

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented Aug 25, 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.

@HLeithner
Copy link
Copy Markdown
Member

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

@izharaazmi
Copy link
Copy Markdown
Contributor Author

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

roland-d pushed a commit to roland-d/joomla-cms that referenced this pull request Sep 11, 2016
* Improve JHtmlNumber::bytes

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.

No B/C break hopefully.

* Fix unit test failure, the failure is due to float comparison, but since this is a JHtml method and not a conversion function we probably can afford little loss of significance.
rdeutz pushed a commit that referenced this pull request Oct 11, 2016
…dency #11026) (#11255)

* Show configured upload limit when uploading installer package. Otherwise when uploading a larger file than the configured limit, the page reloads without any information about what went wrong.

* Reduce amount of information displayed.

* Show upload limits for file input everywhere. Refactor the calculation part to JUtility class.
rdeutz added a commit that referenced this pull request Oct 11, 2016
rdeutz added a commit that referenced this pull request Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants