Page 2 of 2
Re: MinutesSinceLastRainTip
Posted: Sun 23 Feb 2014 10:35 am
by ace2
both produce the same results??
Re: MinutesSinceLastRainTip
Posted: Sun 23 Feb 2014 10:48 am
by mcrossley
steve wrote:Thanks, Mark, that's much more elegant than my effort would have been!
Actually not very elegant - now I have a keyboard! - more elegant would be to put it in a closure (=anonymous function - to avoid polluting/clashing with the global namespace) and cater for zero values...
Code: Select all
<script type="text/javascript">
(function(){
var days = Math.floor(<#MinutesSinceLastRainTip>/24/60);
var hrs = Math.floor(<#MinutesSinceLastRainTip>/60%24);
var mins = Math.floor(<#MinutesSinceLastRainTip>%60);
function plur(x){return x === 1 ? '' : 's'};
document.write(days + ' Day' + plur(days) + ' : ' + hrs + ' Hr' + plur(hrs) + ' : ' + mins + ' Min' + plur(mins));
}());
</script>
Edit: Added enclosing <script> tags.
Re: MinutesSinceLastRainTip
Posted: Sun 23 Feb 2014 10:52 am
by mcrossley
ace2 wrote:both produce the same results??
Not sure what you mean? Your home page still has Steve's original JS code in it?
Re: MinutesSinceLastRainTip
Posted: Sun 23 Feb 2014 11:06 am
by ace2
just wondering if the results would be the same, that's all. and yes I'm using Steve's code.
mcrossley code should have the same output result???
Re: MinutesSinceLastRainTip
Posted: Sun 23 Feb 2014 11:23 am
by steve
Mark's code adds the enhancement to display the singular form for day/hour/minute when the value is 1.
Re: MinutesSinceLastRainTip
Posted: Sun 23 Feb 2014 11:27 am
by ace2
steve wrote:Mark's code adds the enhancement to display the singular form for day/hour/minute when the value is 1.
mm, which one do I steal now??
Re: MinutesSinceLastRainTip
Posted: Mon 24 Feb 2014 12:46 am
by Alan
Hello Mark, Your code works beautifully.
Between when Steve supplied his code and when you supplied your more elegant version I had managed to modify Steve's code to return only that which has value (ie if only minutes value then only minutes displayed and of course if only minutes and hours value then only minutes and hours displayed and so on... somewhat akin to auto ranging on a measuring instrument). This was fine but of course it only had plural nomenclature.
However, no matter how much I try I can not replicate the same action in your code (post probably because your version is beyond me... many things in it that I don't understand at this stage). Do you have any suggestions as to how this could be achieved?
Regards
Alan
PS
Please delete reference to the above as I have now managed to cobble together the appropriate code.
In any event I wish to thank you for the code you supplied and for your time and effort.
All the best.
Alan