On Fri, Apr 22, 2016 at 8:04 PM, Zefram <zef...@fysh.org> wrote:

> Bill Moseley wrote:
> >In other words, I'm trying to find the start and end times for the current
> >month based on a given timezone and then use those in my database query.
>
> You can perform a binary search on UT times, looking for the boundaries
> where the month changes in zone time.  For each month boundary, start
> with a range of the UT month boundary plus and minus 24 hours.  18 steps
> of binary search gets you down to the second, but actually modern zones
> are always on integral-minute offsets, so you could look only at integral
> minutes and take only 12 steps.  For each UT time you try, convert it
> to zone time and see which month it ends up in.


The page linked below has an implementation that finds the start of the day
using the approach Zefram described. It should be trivial to change to to
find the start of the month.
http://stackoverflow.com/a/21000824/589924
<http://stackoverflow.com/a/21000824/589924>

Reply via email to