KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > DateUtil


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core;
12
13  
14 import java.text.ParseException JavaDoc;
15 import java.text.SimpleDateFormat JavaDoc;
16 import java.util.Date JavaDoc;
17 import java.util.Locale JavaDoc;
18 import java.util.TimeZone JavaDoc;
19
20 /**
21  * Utilities to handle time stamps in a cvs client.
22  */

23 public class DateUtil {
24
25     private static final String JavaDoc ENTRY_TIMESTAMP_FORMAT= "EEE MMM dd HH:mm:ss yyyy";//$NON-NLS-1$
26
private static final String JavaDoc ENTRY_TIMESTAMP_TIME_ZONE= "GMT";//$NON-NLS-1$
27
private static final Locale JavaDoc ENTRY_TIMESTAMP_LOCALE= Locale.US;
28     
29     private static final String JavaDoc MODTIME_TIMESTAMP_FORMAT= "dd MMM yyyy HH:mm:ss zz";//$NON-NLS-1$
30
private static final Locale JavaDoc MODTIME_TIMESTAMP_LOCALE= Locale.US;
31     
32     private static final String JavaDoc LOG_TIMESTAMP_FORMAT= "yyyy/MM/dd HH:mm:ss zzz";//$NON-NLS-1$
33
private static final Locale JavaDoc LOG_TIMESTAMP_LOCALE= Locale.US;
34     
35     private static final String JavaDoc HISTORY_TIMESTAMP_FORMAT= "yyyy-MM-dd HH:mm zzzz";//$NON-NLS-1$
36
private static final Locale JavaDoc HISTORY_TIMESTAMP_LOCALE= Locale.US;
37     
38     /**
39      * Converts a time stamp as sent from a cvs server for a "log" command into a
40      * <code>Date</code>.
41      */

42     public static Date JavaDoc convertFromLogTime(String JavaDoc modTime) {
43         SimpleDateFormat JavaDoc format= new SimpleDateFormat JavaDoc(LOG_TIMESTAMP_FORMAT,
44             LOG_TIMESTAMP_LOCALE);
45         try {
46             return format.parse(modTime);
47         } catch (ParseException JavaDoc e) {
48             // fallback is to return null
49
return null;
50         }
51     }
52     /**
53      * Converts a modifcation time stamp as send from a cvs server into a
54      * <code>Date</code>. The format of the modification time stamp is defined
55      * in the document CVS Client/Server for CVS 1.11 section 5.6 Dates
56      */

57     public static Date JavaDoc convertFromModTime(String JavaDoc modTime) {
58         SimpleDateFormat JavaDoc format= new SimpleDateFormat JavaDoc(MODTIME_TIMESTAMP_FORMAT,
59             MODTIME_TIMESTAMP_LOCALE);
60         try {
61             return format.parse(modTime);
62         } catch (ParseException JavaDoc e) {
63             // fallback is to return null
64
return null;
65         }
66     }
67     /**
68      * Converts a history time stamp as sent from a cvs server into a
69      * <code>Date</code>.
70      */

71     public static Date JavaDoc convertFromHistoryTime(String JavaDoc historyTime) {
72         SimpleDateFormat JavaDoc format= new SimpleDateFormat JavaDoc(HISTORY_TIMESTAMP_FORMAT,
73             HISTORY_TIMESTAMP_LOCALE);
74         try {
75             return format.parse(historyTime);
76         } catch (ParseException JavaDoc e) {
77             // fallback is to return null
78
return null;
79         }
80     }
81     /**
82      * Converts a date into an entry time format as specified in the document
83      * Version Management with CVS for CVS 1.10.6 page 14. Note that the
84      * time format is always in GMT also not specified in the document.
85      */

86     public static String JavaDoc toEntryFormat(Date JavaDoc date) {
87         SimpleDateFormat JavaDoc format= new SimpleDateFormat JavaDoc(ENTRY_TIMESTAMP_FORMAT,
88             ENTRY_TIMESTAMP_LOCALE);
89         format.setTimeZone(TimeZone.getTimeZone(ENTRY_TIMESTAMP_TIME_ZONE));
90         return format.format(date);
91     }
92 }
93
Popular Tags