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.
18 * The toString() method takes negative values into consideration.
20 * @author Bernd Hufmann
22 public class TmfTimestampDelta
extends TmfTimestamp
{
24 // ------------------------------------------------------------------------
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
34 public TmfTimestampDelta() {
39 * Simple constructor (scale = precision = 0)
41 * @param value the timestamp value
44 public TmfTimestampDelta(long value
) {
49 * Simple constructor (precision = 0)
51 * @param value the timestamp value
52 * @param scale the timestamp scale
54 public TmfTimestampDelta(long value
, int scale
) {
62 * @param timestamp the timestamp to copy
64 public TmfTimestampDelta(ITmfTimestamp timestamp
) {
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
74 ITmfTimestamp nts
= super.normalize(offset
, scale
);
75 return new TmfTimestampDelta(nts
.getValue(), nts
.getScale());
79 public String
toString() {
80 return toString(TmfTimestampFormat
.getDefaulIntervalFormat());
84 public String
toString(TmfTimestampFormat format
) {
86 TmfTimestampDelta tmpTs
= new TmfTimestampDelta(-getValue(), getScale());
87 return "-" + tmpTs
.toString(format
); //$NON-NLS-1$
89 TmfTimestampFormat deltaFormat
= new TmfTimestampFormat(format
.toPattern());
90 deltaFormat
.setTimeZone(TimeZone
.getTimeZone("UTC")); //$NON-NLS-1$
91 return super.toString(deltaFormat
);