Java TimeUnit Convert toTimePrecision(final TimeUnit t)

Here you can find the source of toTimePrecision(final TimeUnit t)

Description

Convert from a TimeUnit to a influxDB timeunit String.

License

Apache License

Parameter

Parameter Description
t a parameter

Return

the String representation.

Declaration

public static String toTimePrecision(final TimeUnit t) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.EnumSet;
import java.util.concurrent.TimeUnit;

public class Main {
    /**/*from ww w  . ja va  2 s.com*/
     * Convert from a TimeUnit to a influxDB timeunit String.
     *
     * @param t
     * @return the String representation.
     */
    public static String toTimePrecision(final TimeUnit t) {
        switch (t) {
        case HOURS:
            return "h";
        case MINUTES:
            return "m";
        case SECONDS:
            return "s";
        case MILLISECONDS:
            return "ms";
        case MICROSECONDS:
            return "u";
        case NANOSECONDS:
            return "n";
        default:
            EnumSet<TimeUnit> allowedTimeunits = EnumSet.of(TimeUnit.HOURS, TimeUnit.MINUTES, TimeUnit.SECONDS,
                    TimeUnit.MILLISECONDS, TimeUnit.MICROSECONDS, TimeUnit.NANOSECONDS);
            throw new IllegalArgumentException("time precision must be one of:" + allowedTimeunits);
        }
    }
}

Related

  1. toSeconds(long value, TimeUnit unit)
  2. toSIAbbreviation(final TimeUnit timeUnit)
  3. toString(TimeUnit unit)
  4. toString(TimeUnit unit)
  5. toTime(final String value, final TimeUnit inputUnit, final TimeUnit outUnit)
  6. toTimeUnits(long time)