1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.tmf
.core
.timestamp
;
14 import java
.util
.TimeZone
;
17 * A generic timestamp implementation for delta between timestamps. The
18 * toString() method takes negative values into consideration.
20 * @author Bernd Hufmann
22 public class TmfTimestampDelta
extends TmfTimestamp
{
24 // ------------------------------------------------------------------------
26 // ------------------------------------------------------------------------
28 private final long fValue
;
29 private final int fScale
;
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
37 public TmfTimestampDelta() {
38 this(0, ITmfTimestamp
.SECOND_SCALE
);
42 * Simple constructor (scale = precision = 0)
48 public TmfTimestampDelta(long value
) {
49 this(value
, ITmfTimestamp
.SECOND_SCALE
);
60 public TmfTimestampDelta(long value
, int scale
) {
69 * the timestamp to copy
71 public TmfTimestampDelta(ITmfTimestamp timestamp
) {
72 this(timestamp
.getValue(), timestamp
.getScale());
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
80 public long getValue() {
85 public int getScale() {
90 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
91 ITmfTimestamp nts
= super.normalize(offset
, scale
);
92 return new TmfTimestampDelta(nts
.getValue(), nts
.getScale());
96 public String
toString() {
97 return toString(TmfTimestampFormat
.getDefaulIntervalFormat());
101 public String
toString(TmfTimestampFormat format
) {
102 if (getValue() < 0) {
103 TmfTimestampDelta tmpTs
= new TmfTimestampDelta(-getValue(), getScale());
104 return "-" + tmpTs
.toString(format
); //$NON-NLS-1$
106 TmfTimestampFormat deltaFormat
= new TmfTimestampFormat(format
.toPattern());
107 deltaFormat
.setTimeZone(TimeZone
.getTimeZone("UTC")); //$NON-NLS-1$
108 return super.toString(deltaFormat
);