[jcifs] timezone problems

Julian Reschke julian.reschke at gmx.de
Mon Mar 8 16:42:28 GMT 2004


Hi,

I was looking for the reason of the behaviour reported on a mail in 
early February ([1]) and came across the following code in 
ServerMessageBlock.java:

	static long readTime( byte[] src, int srcIndex ) {
		int low = readInt4( src, srcIndex );
		int hi = readInt4( src, srcIndex + 4 );
		long t = ((long)hi << 32 ) | ( (long)low & 0xFFFFFFFFL );
		t = ( t / 10000L - MILLISECONDS_BETWEEN_1970_AND_1601 );

		synchronized( TZ ) {
			if( TZ.inDaylightTime( new Date() )) {
				// in DST
				if( TZ.inDaylightTime( new Date( t ))) {
					// t also in DST so no correction
					return t;
				}
				// t not in DST so add 1 hour
				return t + 3600000;
			} else {
				// not in DST
				if( TZ.inDaylightTime( new Date( t ))) {
					// t is in DST so subtract 1 hour
					return t - 3600000;
				}
				// t isn't in DST either
				return t;
			}
		}
	}

I'm not sure why JCifs is trying to compensate for DST differences here. 
Anyway, this seems to the reason why java.io.File and SmbFile report 
different times for the same file on my machine, if the timestamp falls 
into a DST month.

(reproduced for jdk 1.4.2, JCifs 0.8.1, Windows 2000 Prof.)

Regards, Julian



[1] <http://lists.samba.org/archive/jcifs/2004-February/002942.html>

-- 
<green/>bytes GmbH -- http://www.greenbytes.de -- tel:+492512807760


More information about the jcifs mailing list