Debian Codegraph @

src/com/nwalsh/saxon/CVS.java

raw symbols SCIP
1 package com.nwalsh.saxon;
2
3 import java.io.*;
4 import java.util.Calendar;
5 import java.util.GregorianCalendar;
6 import java.util.Date;
7 import java.util.Locale;
8 import java.util.TimeZone;
9 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 5907 2006-04-27 08:26:47Z xmldoc $</p>
16 *
17 * <p>Copyright (C) 2000 Norman Walsh.</p>
18 *
19 * <p>This class provides a
20 * <a href="http://saxon.sourceforge.net/">Saxon</a>
21 * extension to turn the CVS date strings, which are UTC:</p>
22 *
23 * <pre>&#36;Date: 2000/11/09 02:34:20 &#36;</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:[email protected]">[email protected]</a>
39 *
40 * @version $Id: CVS.java 5907 2006-04-27 08:26:47Z xmldoc $
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 static String localTime (String cvsDate) {
60 // A cvsDate has the following form "$Date: 2006-04-27 17:26:47 +0900 (Thu, 27 Apr 2006) $"
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 }