package com.nwalsh.saxon; import java.io.*; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import java.text.DateFormat; import java.text.ParseException; /** *

Saxon extension to convert CVS date strings into local time

* *

$Id: CVS.java 5907 2006-04-27 08:26:47Z xmldoc $

* *

Copyright (C) 2000 Norman Walsh.

* *

This class provides a * Saxon * extension to turn the CVS date strings, which are UTC:

* *
$Date: 2000/11/09 02:34:20 $
* *

into legibly formatted local time:

* *
Wed Nov 08 18:34:20 PST 2000
* *

(I happened to be in California when I wrote this documentation.)

*

Change Log:

*
*
1.0
*

Initial release.

*
* * @author Norman Walsh * ndw@nwalsh.com * * @version $Id: CVS.java 5907 2006-04-27 08:26:47Z xmldoc $ * */ public class CVS { /** *

Constructor for CVS

* *

All of the methods are static, so the constructor does nothing.

*/ public CVS() { } /** *

Convert a CVS date string into local time.

* * @param cvsDate The CVS date string. * * @return The date, converted to local time and reformatted. */ public static String localTime (String cvsDate) { // A cvsDate has the following form "$Date: 2006-04-27 17:26:47 +0900 (Thu, 27 Apr 2006) $" if (!cvsDate.startsWith("$Date: ")) { return cvsDate; } String yrS = cvsDate.substring(7,11); String moS = cvsDate.substring(12,14); String daS = cvsDate.substring(15,17); String hrS = cvsDate.substring(18,20); String miS = cvsDate.substring(21,23); String seS = cvsDate.substring(24,26); TimeZone tz = TimeZone.getTimeZone("GMT+0"); GregorianCalendar gmtCal = new GregorianCalendar(tz); try { gmtCal.set(Integer.parseInt(yrS), Integer.parseInt(moS)-1, Integer.parseInt(daS), Integer.parseInt(hrS), Integer.parseInt(miS), Integer.parseInt(seS)); } catch (NumberFormatException e) { // nop } Date d = gmtCal.getTime(); return d.toString(); } }