Java TimeUnit Calculate getParentUnit(TimeUnit unit)

Here you can find the source of getParentUnit(TimeUnit unit)

Description

get Parent Unit

License

Open Source License

Declaration

public static TimeUnit getParentUnit(TimeUnit unit) 

Method Source Code

//package com.java2s;
/**//  w ww.j  a  v a  2 s.co  m
* Copyright (c) Acroquest Technology Co, Ltd. All Rights Reserved.
* Please read the associated COPYRIGHTS file for more details.
*
* THE SOFTWARE IS PROVIDED BY Acroquest Technolog Co., Ltd.,
* WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDER BE LIABLE FOR ANY
* CLAIM, DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/

import java.util.concurrent.TimeUnit;

public class Main {

    public static TimeUnit getParentUnit(TimeUnit unit) {
        TimeUnit result = null;

        switch (unit) {
        case HOURS:
            result = TimeUnit.DAYS;
            break;
        case MINUTES:
            result = TimeUnit.HOURS;
            break;
        case SECONDS:
            result = TimeUnit.MINUTES;
            break;
        case MILLISECONDS:
            result = TimeUnit.SECONDS;
            break;
        case MICROSECONDS:
            result = TimeUnit.MILLISECONDS;
            break;
        case NANOSECONDS:
            result = TimeUnit.MICROSECONDS;
            break;
        default:
            break;
        }

        return result;
    }
}

Related

  1. getFutureDate(long delay, TimeUnit timeUnit)
  2. getInterval(final Date startDate, final Date endDate, final TimeUnit timeUnit)
  3. getIntervalInfo(long intervalDuration, TimeUnit unit)
  4. getMilliseconds(int interval, TimeUnit unit)
  5. getNowTimeUnit(TimeUnit timeUnit)
  6. getProperUnitName(TimeUnit unit, long amount)
  7. getRandomTimeRound(int _duration, TimeUnit _unit)
  8. getTimeBucket(TimeUnit unit, long timestamp, int bucketSizeInSeconds)
  9. getTimeInMillis(TimeUnit unit)