18 May 2003 ade   » (Journeyer)

vivekv: I think I have a clearer idea what's going on with AdvogatoPoster. Firstly we have to accept that anything to do with Date, Calendar or TimeZone in the standard Java libraries will be a mess. Then everything makes sense.

The essential problem seems to be how do we compare dates in two different timezones? We can't use plain unix time because the epoch was a different amount of time ago depending on which time zone you're in. Therefore we pick a timezone and do all comparisons in there. Since Advogato is based in Berkeley (or at least that's what traceroute says) then we just do all date comparisons in Berkeley time.

	private static long convertToBerkeleyTime(Date date) {
		Calendar local = new GregorianCalendar();
		local.setTime(date);
		
		Calendar la = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
		la.clear();
		
		la.set(Calendar.YEAR, local.get(Calendar.YEAR));
		la.set(Calendar.MONTH, local.get(Calendar.MONTH));
		la.set(Calendar.DAY_OF_MONTH, local.get(Calendar.DAY_OF_MONTH));
		la.set(Calendar.HOUR_OF_DAY, local.get(Calendar.HOUR_OF_DAY));
		la.set(Calendar.MINUTE, local.get(Calendar.MINUTE));
		la.set(Calendar.SECOND, local.get(Calendar.SECOND));
		la.set(Calendar.MILLISECOND, local.get(Calendar.MILLISECOND));
		
		return la.getTimeInMillis();
	}

The above code gives us a long which can be meaningfully compared to the timestamp on a local file.

Latest blog entries     Older blog entries

New Advogato Features

FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!