Class TimeConverter

java.lang.Object
com.irurueta.units.TimeConverter

public class TimeConverter extends Object
Does time conversions to different units. To prevent loss of accuracy, conversion should only be done as a final step before displaying time measurements.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final double
    Number of seconds in 1 century.
    (package private) static final double
    Number of seconds in 1 day.
    (package private) static final double
    Number of seconds in 1 hour.
    (package private) static final double
    Number of seconds in 1 microsecond.
    (package private) static final double
    Number of seconds in 1 milliseconds.
    (package private) static final double
    Number of seconds in 1 minute.
    (package private) static final double
    Number of seconds in 1 month.
    (package private) static final double
    Number of seconds in 1 nanosecond.
    (package private) static final double
    Number of seconds in 1 week.
    (package private) static final double
    Number of seconds in 1 year.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    centuryToSecond(double century)
    Converts provided century value to seconds.
    static double
    convert(double input, TimeUnit inputUnit, TimeUnit outputUnit)
    Converts a time value from input unit to provided output unit.
    static void
    convert(Time input, Time output)
    Converts a time to provided output time unit.
    static void
    convert(Time time, TimeUnit outputUnit)
    Converts and updates a time to requested output unit.
    static void
    convert(Time input, TimeUnit outputUnit, Time result)
    Converts a time to requested output unit.
    static Number
    convert(Number input, TimeUnit inputUnit, TimeUnit outputUnit)
    Converts a time value from input unit to provided output unit.
    static Time
    convertAndReturnNew(Time input, TimeUnit outputUnit)
    Converts a time to requested output unit.
    static double
    dayToSecond(double day)
    Converts provided day value to seconds.
    static double
    hourToSecond(double hour)
    Converts provided hour value to seconds.
    static double
    microsecondToSecond(double microsecond)
    Converts provided microsecond value to seconds.
    static double
    millisecondToSecond(double millisecond)
    Converts provided millisecond value to seconds.
    static double
    minuteToSecond(double minute)
    Converts provided minute value to seconds.
    static double
    monthToSecond(double month)
    Converts provided month value to seconds.
    static double
    nanosecondToSecond(double nanosecond)
    Converts provided nanosecond value to seconds.
    static double
    secondToCentury(double second)
    Converts provided second value to century.
    static double
    secondToDay(double second)
    Converts provided second value to days.
    static double
    secondToHour(double second)
    Converts provided second value to hours.
    static double
    secondToMicrosecond(double second)
    Converts provided second value to microseconds.
    static double
    secondToMillisecond(double second)
    Converts provided second value to milliseconds.
    static double
    secondToMinute(double second)
    Converts provided second value to minutes.
    static double
    secondToMonth(double second)
    Converts provided second value to months.
    static double
    secondToNanosecond(double second)
    Converts provided second value to nanoseconds.
    static double
    secondToWeek(double second)
    Converts provided second value to weeks.
    static double
    secondToYear(double second)
    Converts provided second value to years.
    static double
    weekToSecond(double week)
    Converts provided week value to seconds.
    static double
    yearToSecond(double year)
    Converts provided year value to seconds.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SECONDS_PER_NANOSECOND

      static final double SECONDS_PER_NANOSECOND
      Number of seconds in 1 nanosecond.
      See Also:
    • SECONDS_PER_MICROSECOND

      static final double SECONDS_PER_MICROSECOND
      Number of seconds in 1 microsecond.
      See Also:
    • SECONDS_PER_MILLISECOND

      static final double SECONDS_PER_MILLISECOND
      Number of seconds in 1 milliseconds.
      See Also:
    • SECONDS_PER_MINUTE

      static final double SECONDS_PER_MINUTE
      Number of seconds in 1 minute.
      See Also:
    • SECONDS_PER_HOUR

      static final double SECONDS_PER_HOUR
      Number of seconds in 1 hour.
      See Also:
    • SECONDS_PER_DAY

      static final double SECONDS_PER_DAY
      Number of seconds in 1 day.
      See Also:
    • SECONDS_PER_WEEK

      static final double SECONDS_PER_WEEK
      Number of seconds in 1 week.
      See Also:
    • SECONDS_PER_MONTH

      static final double SECONDS_PER_MONTH
      Number of seconds in 1 month.
      See Also:
    • SECONDS_PER_YEAR

      static final double SECONDS_PER_YEAR
      Number of seconds in 1 year.
      See Also:
    • SECONDS_PER_CENTURY

      static final double SECONDS_PER_CENTURY
      Number of seconds in 1 century.
      See Also:
  • Constructor Details

    • TimeConverter

      private TimeConverter()
      Constructor. Prevents instantiation of helper class.
  • Method Details

    • convert

      public static void convert(Time input, Time output)
      Converts a time to provided output time unit.
      Parameters:
      input - input time to be converted.
      output - output time where result will be stored and containing output unit.
    • convertAndReturnNew

      public static Time convertAndReturnNew(Time input, TimeUnit outputUnit)
      Converts a time to requested output unit.
      Parameters:
      input - input time to be converted.
      outputUnit - requested output unit.
      Returns:
      converted time.
    • convert

      public static void convert(Time time, TimeUnit outputUnit)
      Converts and updates a time to requested output unit.
      Parameters:
      time - input time to be converted and updated.
      outputUnit - requested output unit.
    • convert

      public static void convert(Time input, TimeUnit outputUnit, Time result)
      Converts a time to requested output unit.
      Parameters:
      input - input time to be converted.
      outputUnit - requested output unit.
      result - time unit where result will be stored.
    • convert

      public static Number convert(Number input, TimeUnit inputUnit, TimeUnit outputUnit)
      Converts a time value from input unit to provided output unit.
      Parameters:
      input - time value.
      inputUnit - input time unit.
      outputUnit - output time unit.
      Returns:
      converted time value.
    • convert

      public static double convert(double input, TimeUnit inputUnit, TimeUnit outputUnit)
      Converts a time value from input unit to provided output unit.
      Parameters:
      input - time value.
      inputUnit - input time unit.
      outputUnit - output time unit.
      Returns:
      converted time value.
    • secondToNanosecond

      public static double secondToNanosecond(double second)
      Converts provided second value to nanoseconds.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to nanoseconds.
    • nanosecondToSecond

      public static double nanosecondToSecond(double nanosecond)
      Converts provided nanosecond value to seconds.
      Parameters:
      nanosecond - nanosecond value.
      Returns:
      same amount of time converted to seconds.
    • secondToMicrosecond

      public static double secondToMicrosecond(double second)
      Converts provided second value to microseconds.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to microseconds.
    • microsecondToSecond

      public static double microsecondToSecond(double microsecond)
      Converts provided microsecond value to seconds.
      Parameters:
      microsecond - microsecond value.
      Returns:
      same amount of time converted to seconds.
    • secondToMillisecond

      public static double secondToMillisecond(double second)
      Converts provided second value to milliseconds.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to milliseconds.
    • millisecondToSecond

      public static double millisecondToSecond(double millisecond)
      Converts provided millisecond value to seconds.
      Parameters:
      millisecond - millisecond value.
      Returns:
      same amount of time converted to seconds.
    • secondToMinute

      public static double secondToMinute(double second)
      Converts provided second value to minutes.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to minutes.
    • minuteToSecond

      public static double minuteToSecond(double minute)
      Converts provided minute value to seconds.
      Parameters:
      minute - minute value.
      Returns:
      same amount of time converted to seconds.
    • secondToHour

      public static double secondToHour(double second)
      Converts provided second value to hours.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to hours.
    • hourToSecond

      public static double hourToSecond(double hour)
      Converts provided hour value to seconds.
      Parameters:
      hour - hour value.
      Returns:
      same amount of time converted to seconds.
    • secondToDay

      public static double secondToDay(double second)
      Converts provided second value to days.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to days.
    • dayToSecond

      public static double dayToSecond(double day)
      Converts provided day value to seconds.
      Parameters:
      day - day value.
      Returns:
      same amount of time converted to seconds.
    • secondToWeek

      public static double secondToWeek(double second)
      Converts provided second value to weeks.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to weeks.
    • weekToSecond

      public static double weekToSecond(double week)
      Converts provided week value to seconds.
      Parameters:
      week - week value.
      Returns:
      same amount of time converted to seconds.
    • secondToMonth

      public static double secondToMonth(double second)
      Converts provided second value to months.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to months.
    • monthToSecond

      public static double monthToSecond(double month)
      Converts provided month value to seconds.
      Parameters:
      month - month value.
      Returns:
      same amount of time converted to seconds.
    • secondToYear

      public static double secondToYear(double second)
      Converts provided second value to years.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to years.
    • yearToSecond

      public static double yearToSecond(double year)
      Converts provided year value to seconds.
      Parameters:
      year - year value.
      Returns:
      same amount of time converted to seconds.
    • secondToCentury

      public static double secondToCentury(double second)
      Converts provided second value to century.
      Parameters:
      second - second value.
      Returns:
      same amount of time converted to centuries.
    • centuryToSecond

      public static double centuryToSecond(double century)
      Converts provided century value to seconds.
      Parameters:
      century - century value.
      Returns:
      same amount of time converted to seconds.