01: package com.nwalsh.xalan;
02:
03: import java.io.*;
04: import java.util.Calendar;
05: import java.util.GregorianCalendar;
06: import java.util.Date;
07: import java.util.Locale;
08: import java.util.TimeZone;
09: import java.text.DateFormat;
10: import java.text.ParseException;
11:
12: /**
13: * <p>Saxon extension to convert CVS date strings into local time</p>
14: *
15: * <p>$Id: CVS.java,v 1.1 2006/05/31 17:21:20 mbatchelor Exp $</p>
16: *
17: * <p>Copyright (C) 2000 Norman Walsh.</p>
18: *
19: * <p>This class provides a
20: * <a href="http://users.iclway.co.uk/mhkay/saxon/">Saxon</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/31 17:21:20 mbatchelor Exp $
41: *
42: */
43: public 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/31 17:21:20 $"
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, Integer.parseInt(daS),
78: Integer.parseInt(hrS), Integer.parseInt(miS),
79: Integer.parseInt(seS));
80: } catch (NumberFormatException e) {
81: // nop
82: }
83:
84: Date d = gmtCal.getTime();
85:
86: return d.toString();
87: }
88: }
|