3
* ====================================================================
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
20
* ====================================================================
24
package org.apache.subversion.javahl.types;
26
import java.text.DateFormat;
27
import java.text.ParseException;
28
import java.text.SimpleDateFormat;
29
import java.util.Calendar;
30
import java.util.Date;
31
import java.util.TimeZone;
34
* Holds date for a log message. This class maintains
35
* the time to the microsecond and is not lossy.
37
public class LogDate implements java.io.Serializable
39
private static final long serialVersionUID = 1L;
40
private static final DateFormat formatter = new SimpleDateFormat(
41
"yyyy-MM-dd'T'HH:mm:ss.SSS z");
42
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
44
private final long timeMicros;
45
private final String cachedString;
46
private final Calendar cachedDate;
48
public LogDate(String datestr) throws ParseException
50
if (datestr == null || datestr.length() != 27 || datestr.charAt(26) != 'Z')
52
throw new ParseException("String is not a valid Subversion date", 0);
54
Date date = formatter.parse(datestr.substring(0, 23) + " UTC");
55
this.cachedString = datestr;
56
cachedDate = Calendar.getInstance(UTC);
57
cachedDate.setTime(date);
58
timeMicros = cachedDate.getTimeInMillis() * 1000
59
+ Integer.parseInt(datestr.substring(23, 26));
63
* Returns the time of the commit in microseconds
64
* @return the time of the commit measured in the number of
65
* microseconds since 00:00:00 January 1, 1970 UTC
67
public long getTimeMicros()
73
* Returns the time of the commit in milliseconds
74
* @return the time of the commit measured in the number of
75
* milliseconds since 00:00:00 January 1, 1970 UTC
77
public long getTimeMillis()
79
return cachedDate.getTimeInMillis();
83
* Returns the time of the commit as Calendar
84
* @return the time of the commit as java.util.Calendar
86
public Calendar getCalender()
92
* Returns the date of the commit
93
* @return the time of the commit as java.util.Date
97
return cachedDate.getTime();
100
public String toString()
105
public int hashCode()
107
final int prime = 31;
109
result = prime * result + (int) (timeMicros ^ (timeMicros >>> 32));
113
public boolean equals(Object obj)
119
if (getClass() != obj.getClass())
121
final LogDate other = (LogDate) obj;
122
if (timeMicros != other.getTimeMicros())