1package com.nwalsh.xalan; 2 3import java.io.*; 4import java.util.Calendar; 5import java.util.GregorianCalendar; 6import java.util.Date; 7import java.util.Locale; 8import java.util.TimeZone; 9import java.text.DateFormat; 10import java.text.ParseException; 11 12/** 13 * <p>Xalan extension to convert CVS date strings into local time</p> 14 * 15 * <p>$Id: CVS.java,v 1.1 2006/05/04 13:23:51 nwalsh Exp $</p> 16 * 17 * <p>Copyright (C) 2000 Norman Walsh.</p> 18 * 19 * <p>This class provides a 20 * <a href="http://xml.apache.org/xalan-j/">Xalan</a> 21 * extension to turn the CVS date strings, which are UTC:</p> 22 * 23 * <pre>$Date: 2000/11/09 02:34:20 $</pre> 24 * 25 * <p>into legibly formatted local time:</p> 26 * 27 * <pre>Wed Nov 08 18:34:20 PST 2000</pre> 28 * 29 * <p>(I happened to be in California when I wrote this documentation.)</p> 30 31 * <p><b>Change Log:</b></p> 32 * <dl> 33 * <dt>1.0</dt> 34 * <dd><p>Initial release.</p></dd> 35 * </dl> 36 * 37 * @author Norman Walsh 38 * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a> 39 * 40 * @version $Id: CVS.java,v 1.1 2006/05/04 13:23:51 nwalsh Exp $ 41 * 42 */ 43public class CVS { 44 /** 45 * <p>Constructor for CVS</p> 46 * 47 * <p>All of the methods are static, so the constructor does nothing.</p> 48 */ 49 public CVS() { 50 } 51 52 /** 53 * <p>Convert a CVS date string into local time.</p> 54 * 55 * @param cvsDate The CVS date string. 56 * 57 * @return The date, converted to local time and reformatted. 58 */ 59 public String localTime (String cvsDate) { 60 // A cvsDate has the following form "$Date: 2006/05/04 13:23:51 $" 61 if (!cvsDate.startsWith("$Date: ")) { 62 return cvsDate; 63 } 64 65 String yrS = cvsDate.substring(7,11); 66 String moS = cvsDate.substring(12,14); 67 String daS = cvsDate.substring(15,17); 68 String hrS = cvsDate.substring(18,20); 69 String miS = cvsDate.substring(21,23); 70 String seS = cvsDate.substring(24,26); 71 72 TimeZone tz = TimeZone.getTimeZone("GMT+0"); 73 GregorianCalendar gmtCal = new GregorianCalendar(tz); 74 75 try { 76 gmtCal.set(Integer.parseInt(yrS), 77 Integer.parseInt(moS)-1, 78 Integer.parseInt(daS), 79 Integer.parseInt(hrS), 80 Integer.parseInt(miS), 81 Integer.parseInt(seS)); 82 } catch (NumberFormatException e) { 83 // nop 84 } 85 86 Date d = gmtCal.getTime(); 87 88 return d.toString(); 89 } 90} 91