Skip to main content
summaryrefslogtreecommitdiffstats
blob: 123b0ca60e987f865c453633bb598beae226127e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package org.eclipse.team.internal.ccvs.core.util;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
 * Does convertion beetween this timeformats:<br>
 * <ul>
 * <li> "18 Oct 2001 20:21:13 -0350"
 * <li> a long messuring the milliseconds after 1970
 * </ul>
 */
public class ServerDateFormat extends SimpleDateFormat {
	
	public static final String FORMAT = "dd MMM yyyy HH:mm:ss";//$NON-NLS-1$
	
	public ServerDateFormat() {
		super(FORMAT, Locale.US);
		setTimeZone(TimeZone.getTimeZone("GMT"));//$NON-NLS-1$
	}

	/**
	 * "18 Oct 2001 20:21:13 -0350" => long since 1970
	 */
	public Date toDate(String text) throws ParseException {
		// FIXME this cuts the timezone which we do not want
		if (text.indexOf("-") != -1) {//$NON-NLS-1$
			text = text.substring(0,text.indexOf("-"));//$NON-NLS-1$
		}
		return parse(text);
	}

	/**
	 * long since 1970 => "18 Oct 2001 20:21:13 -0350"
	 */	
	public String formatDate(Date date) {
		return format(date);
	}
		
}

Back to the top