Skip to content

Commit 129f06c

Browse files
committed
🐛 fix for issue #274
1 parent cdc3dfd commit 129f06c

File tree

5 files changed

+83
-133
lines changed

5 files changed

+83
-133
lines changed

api/src/main/java/com/microsoft/gctoolkit/io/GCLogFileSegment.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@ public String getSegmentName() {
7272
public double getStartTime() {
7373
try {
7474
ageOfJVMAtLogStart();
75-
if ( startTime.hasTimeStamp())
76-
return startTime.getTimeStamp();
77-
else if ( startTime.hasDateStamp())
78-
return startTime.toEpochInMillis();
79-
else
80-
return Double.MAX_VALUE;
75+
return startTime.getTimeStamp();
8176
} catch (NullPointerException ex) {
8277
return Double.MAX_VALUE;
8378
}
@@ -96,12 +91,7 @@ else if ( startTime.hasDateStamp())
9691
public double getEndTime() {
9792
try {
9893
ageOfJVMAtLogEnd();
99-
if ( endTime.hasTimeStamp())
100-
return endTime.getTimeStamp();
101-
else if ( endTime.hasDateStamp())
102-
return endTime.toEpochInMillis();
103-
else
104-
return Double.MAX_VALUE;
94+
return endTime.getTimeStamp();
10595
} catch (NullPointerException|IOException ex) {
10696
return Double.MIN_VALUE;
10797
}

api/src/main/java/com/microsoft/gctoolkit/time/DateTimeStamp.java

+19-60
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ public class DateTimeStamp implements Comparable<DateTimeStamp> {
4545
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
4646

4747
private static ZonedDateTime dateFromString(String iso8601DateTime) {
48-
if (iso8601DateTime != null) {
49-
TemporalAccessor temporalAccessor = formatter.parse(iso8601DateTime);
50-
return ZonedDateTime.from(temporalAccessor);
51-
}
52-
return null;
48+
if ( iso8601DateTime == null)
49+
return null;
50+
return ZonedDateTime.from(formatter.parse(iso8601DateTime));
5351
}
5452

5553
private static double ageFromString(String doubleFormat) {
@@ -151,6 +149,8 @@ public DateTimeStamp(ZonedDateTime dateTime, double timeStamp) {
151149
* @return The time stamp value, in decimal seconds.
152150
*/
153151
public double getTimeStamp() {
152+
if (! hasTimeStamp())
153+
return toEpochInMillis();
154154
return timeStamp;
155155
}
156156

@@ -179,14 +179,11 @@ public boolean hasTimeStamp() {
179179
public boolean equals(Object obj) {
180180
if (obj instanceof DateTimeStamp) {
181181
DateTimeStamp other = (DateTimeStamp) obj;
182-
boolean hasTimeStamp = hasTimeStamp() && other.hasTimeStamp();
183-
boolean hasDateStamp = hasDateStamp() && other.hasDateStamp();
184-
if (hasDateStamp && hasTimeStamp)
185-
return equals(other.getTimeStamp()) && getDateTime().equals(other.getDateTime());
186-
if (hasTimeStamp)
187-
return equals(other.getTimeStamp());
188-
if (hasDateStamp)
189-
return getDateTime().equals(other.getDateTime());
182+
if (this.hasDateStamp())
183+
return this.getDateTime().equals(other.getDateTime()) &&
184+
(this.getTimeStamp() == other.getTimeStamp());
185+
else
186+
return getTimeStamp() == other.getTimeStamp();
190187
}
191188
return false;
192189
}
@@ -202,47 +199,17 @@ public String toString() {
202199
if (hasDateStamp())
203200
buffer.append(getDateTime().toString());
204201
if (hasTimeStamp())
205-
buffer.append("@").append(String.format(Locale.US,"%.3f",timeStamp));
202+
buffer.append("@").append(String.format(Locale.US,"%.3f",getTimeStamp()));
206203
return buffer.toString();
207204
}
208205

209-
/**
210-
* Return {@code true} if this time stamp is less than the other.
211-
* @param other The other time stamp, in decimal seconds.
212-
* @return {@code true} if this time stamp is less than the other.
213-
*/
214-
public boolean before(double other) {
215-
if ( other < 0.000d || Double.isNaN(other)) return false;
216-
if ( Double.isNaN(getTimeStamp())) return false;
217-
return getTimeStamp() < other;
218-
}
219-
220-
/**
221-
* Return {@code true} if this time stamp is greater than the other.
222-
* @param other The other time stamp, in decimal seconds.
223-
* @return {@code true} if this time stamp is greater than the other.
224-
*/
225-
public boolean after(double other) {
226-
if ( other < 0.000d || Double.isNaN(other)) return false;
227-
if ( Double.isNaN(getTimeStamp())) return false;
228-
return getTimeStamp() > other;
229-
}
230-
231-
public boolean equals(double other) {
232-
if ( other < 0.000d || Double.isNaN(other)) return false;
233-
if ( Double.isNaN(getTimeStamp())) return false;
234-
return getTimeStamp() == other;
235-
}
236-
237206
/**
238207
* Return {@code true} if this DateTimeStamp comes before the other.
239208
* @param other The other DateTimeStamp.
240209
* @return {@code true} if this time stamp is less than the other.
241210
*/
242211
public boolean before(DateTimeStamp other) {
243-
return ( hasTimeStamp() && other.hasTimeStamp())
244-
? before(other.getTimeStamp())
245-
: compare(other.getDateTime()) < 0;
212+
return getTimeStamp() < other.getTimeStamp();
246213
}
247214

248215
/**
@@ -251,9 +218,7 @@ public boolean before(DateTimeStamp other) {
251218
* @return {@code true} if this time stamp is less than the other.
252219
*/
253220
public boolean after(DateTimeStamp other) {
254-
return ( hasTimeStamp() && other.hasTimeStamp())
255-
? after(other.getTimeStamp())
256-
: compare(other.getDateTime()) > 0;
221+
return getTimeStamp() > other.getTimeStamp();
257222
}
258223

259224
/**
@@ -284,26 +249,20 @@ public DateTimeStamp add(double offsetInDecimalSeconds) {
284249
if (Double.isNaN(offsetInDecimalSeconds))
285250
throw new IllegalArgumentException("Cannot add " + Double.NaN);
286251

287-
DateTimeStamp now;
288252
double adjustedTimeStamp = Double.NaN;
289-
if ( ! Double.isNaN(getTimeStamp())) {
253+
ZonedDateTime adjustedDateStamp = null;
254+
if ( hasTimeStamp()) {
290255
adjustedTimeStamp = getTimeStamp() + offsetInDecimalSeconds;
291256
}
292257

293-
// Need to scale the values from ZonedDateTime
294-
if (getDateTime() != null) {
258+
if (hasDateStamp()) {
295259
double offset = (Double.isNaN(offsetInDecimalSeconds)) ? 0.000d : offsetInDecimalSeconds;
296260
int seconds = (int) offset;
297261
long nanos = ((long) ((offset % 1) * 1_000L)) * 1_000_000L;
298-
ZonedDateTime adjustedDateStamp = dateTime.plusSeconds(seconds).plusNanos(nanos);
299-
if ( Double.isNaN(getTimeStamp()))
300-
now = new DateTimeStamp(adjustedDateStamp);
301-
else
302-
now = new DateTimeStamp(adjustedDateStamp, adjustedTimeStamp);
303-
} else
304-
now = new DateTimeStamp(adjustedTimeStamp);
262+
adjustedDateStamp = dateTime.plusSeconds(seconds).plusNanos(nanos);
263+
}
305264

306-
return now;
265+
return new DateTimeStamp(adjustedDateStamp,adjustedTimeStamp);
307266
}
308267

309268
/**

0 commit comments

Comments
 (0)