in reply to Re^2: Round time to nearest 15 or 30 minutes
in thread Round time to nearest 15 or 30 minutes
If you want the nearest 15 minute boundary, then the code is wrong. It will give you the previous 15 minute boundary.
You need to:
- add $interval/2 minutes to the time;
- subtract the remainder you'd get when dividing by $interval minutes.
Note that the modulus operator % only works with integers. In practice, you can probably ignore the fraction of a minute that gets thrown away. If you can't, then you'll need to write your own remainder function.
In Section
Seekers of Perl Wisdom