1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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
.linuxtools
.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
23 public class TmfTimestampDelta
extends TmfTimestamp
{
25 // ------------------------------------------------------------------------
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
35 public TmfTimestampDelta() {
40 * Simple constructor (scale = precision = 0)
42 * @param value the timestamp value
45 public TmfTimestampDelta(long value
) {
50 * Simple constructor (precision = 0)
52 * @param value the timestamp value
53 * @param scale the timestamp scale
55 public TmfTimestampDelta(long value
, int scale
) {
63 * @param timestamp the timestamp to copy
65 public TmfTimestampDelta(ITmfTimestamp timestamp
) {
72 * @param value the timestamp value
73 * @param scale the timestamp scale
74 * @param precision the timestamp precision
76 public TmfTimestampDelta(long value
, int scale
, int precision
) {
77 super(value
, scale
, precision
);
80 // ------------------------------------------------------------------------
82 // ------------------------------------------------------------------------
85 public ITmfTimestamp
normalize(final long offset
, final int scale
) {
86 ITmfTimestamp nts
= super.normalize(offset
, scale
);
87 return new TmfTimestampDelta(nts
.getValue(), nts
.getScale(), nts
.getPrecision());
91 public String
toString() {
92 return toString(TmfTimestampFormat
.getDefaulIntervalFormat());
96 public String
toString(TmfTimestampFormat format
) {
98 TmfTimestampDelta tmpTs
= new TmfTimestampDelta(-getValue(), getScale(), getPrecision());
99 return "-" + tmpTs
.toString(format
); //$NON-NLS-1$
101 TmfTimestampFormat deltaFormat
= new TmfTimestampFormat(format
.toPattern());
102 deltaFormat
.setTimeZone(TimeZone
.getTimeZone("UTC")); //$NON-NLS-1$
103 return super.toString(deltaFormat
);