[concurrency-interest] Re: SynchronizedLong vs. other locks

Dawid Kurzyniec dawidk at mathcs.emory.edu
Fri Jul 8 14:43:36 EDT 2005


Dawid Kurzyniec wrote:

> Aleksey Gureev wrote:
>
>> Dawid,
>>  
>>
>> :) You forget about the time zones.
>>  
>>
> Yes I did. How about:
>
> private static final TimeZone local = TimeZone.getDefault();
>
> private static long getTomorrowTime() {
>    long current = System.currentTimeMillis();
>    long offset = local.getOffset(current);
>    return (((current + offset + DAY)/DAY)*DAY - offset;
> }
>
I apologize for dragging this a bit off-topic thread, but I've found one 
more issue here. What the above code does, it returns the date 24h after 
last midnight. The problem is, however, that due to daylight savings 
time, some days are 23h, and some are 25h; so the returned date may not 
be a local midnight! It seems that the needed correction is:

private static long getTomorrowTime() {
   long current = System.currentTimeMillis();
   long offset1 = local.getOffset(current);
   long tomorrow = (((current + offset1 + DAY)/DAY)*DAY - offset1;
   long offset2 = local.getOffset(tomorrow);
   tomorrow += (offset1-offset2);
   return tomorrow;
}

I haven't tested it though.

Regards,
Dawid




More information about the Concurrency-interest mailing list