001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)JBITimeUtil.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.ui.common;
030:
031: /**
032: * This object provides utility methods to convert a (long)timestamp value into
033: * String values.
034: *
035: * @author Sun Microsystems, Inc.
036: */
037: public class JBITimeUtil {
038: /* Constants */
039: public static final long DAY_BASE = 24 * 60 * 60 * 1000;
040: public static final long HOUR_BASE = 60 * 60 * 1000;
041: public static final long MIN_BASE = 60 * 1000;
042: public static final double SEC_BASE = 1000f;
043:
044: /* Private members */
045: private int mDays = 0;
046: private int mHours = 0;
047: private int mMins = 0;
048: private double mSecs = 0;
049:
050: /*
051: * public default constructor
052: */
053: public JBITimeUtil() {
054: }
055:
056: /*
057: * public constructor
058: */
059: public JBITimeUtil(long milliseconds) {
060: setTime(milliseconds);
061: }
062:
063: /**
064: * Will set the values for the Days, Hours, Minutes and Seconds, given
065: * the timestamp (milliseconds).
066: * @param milliseconds the number of milliseconds
067: */
068:
069: public void setTime(long milliseconds) {
070: mDays = (int) (milliseconds / DAY_BASE);
071: mHours = (int) ((milliseconds - mDays * DAY_BASE) / HOUR_BASE);
072: mMins = (int) ((milliseconds - mDays * DAY_BASE - mHours
073: * HOUR_BASE) / MIN_BASE);
074: mSecs = ((milliseconds - mDays * DAY_BASE - mHours * HOUR_BASE - mMins
075: * MIN_BASE) / SEC_BASE);
076: }
077:
078: /**
079: * Get the days portion
080: * @return the number of days
081: */
082: public int getDays() {
083: return mDays;
084: }
085:
086: /**
087: * Get the hours portion
088: * @return the number of hours
089: */
090: public int getHours() {
091: return mHours;
092: }
093:
094: /**
095: * Get the minutes portion
096: * @return the number of minutes
097: */
098: public int getMinutes() {
099: return mMins;
100: }
101:
102: /**
103: * Get the seconds, truncated, no milliseconds
104: * @return the seconds only
105: */
106: public int getSecondsOnly() {
107: int seconds = (int) (mSecs / 1000);
108: return seconds;
109: }
110:
111: /**
112: * Get the seconds with millsecconds portion
113: * @return the seconds (including milliseconds)
114: */
115: public double getSeconds() {
116: return mSecs;
117: }
118:
119: }
|