Package util

Class Time


  • public class Time
    extends java.lang.Object
    Objects of this class supply methods that may be used for telling time and parsing String representations of time in dd:hh:mm:ss or hh:mm:ss or hh:mm formats and translating them into seconds formats.The reverse is also possible:i.e translating time in seconds into dd:hh:mm:ss format. When combined with Timer objects,objects of this class can help in creating timing utilities for software.
    Author:
    GBENRO JIBOYE
    • Constructor Summary

      Constructors 
      Constructor Description
      Time()
      No-argument constructor for creating objects of class Time.sets all the numerical properties of the object to 0
      Time​(int seconds)  
      Time​(int minutes, int seconds)  
      Time​(int hours, int minutes, int seconds)  
      Time​(long days, int hours, int minutes, int seconds)  
      Time​(java.lang.String time)
      This constructor creates objects of class Time and determines the values of various properties of the created based on the input time.
    • Constructor Detail

      • Time

        public Time()
        No-argument constructor for creating objects of class Time.sets all the numerical properties of the object to 0
      • Time

        public Time​(java.lang.String time)
        This constructor creates objects of class Time and determines the values of various properties of the created based on the input time.
        Parameters:
        time - the time property of the created object
      • Time

        public Time​(long days,
                    int hours,
                    int minutes,
                    int seconds)
        Parameters:
        days - The days attribute.
        hours - The hours attribute.
        minutes - The minutes attribute.
        seconds - The seconds attribute.
      • Time

        public Time​(int hours,
                    int minutes,
                    int seconds)
        Parameters:
        hours - The hours attribute.
        minutes - The minutes attribute.
        seconds - The seconds attribute.
      • Time

        public Time​(int minutes,
                    int seconds)
        Parameters:
        minutes - The minutes attribute.
        seconds - The seconds attribute.
      • Time

        public Time​(int seconds)
        Parameters:
        seconds - The seconds attribute.
    • Method Detail

      • format$ValidateTime

        public void format$ValidateTime​(java.lang.String time)
        This method determines the values associated with various properties of objects of this class dependent on the input time. It accomplishes this by parsing and validating the input time, and from there assigns values to various properties of the Time object based on the results of the parsing and validating. The time is entered in the format "dd:hh:mm:ss" or "hh:mm:ss" or hh:mm
        Parameters:
        time - the time property of the created object
      • timeDiff

        public Time timeDiff​(Time t1)
        Parameters:
        t1 - The Time object to combine subtractively with this one.
        Returns:
        a Time object that represents the absolute difference between both Time objects.
      • timeAddition

        public Time timeAddition​(Time t1)
        Parameters:
        t1 - The Time object to combine additively with this one.
        Returns:
        a time object that represents the absolute difference between both Time objects.
      • getTime

        public java.lang.String getTime()
        Returns:
        the current value of the time. The returned time is not the current system time.To get the current system time, make a call to method timeGetter()
      • setTime

        public void setTime​(java.lang.String time)
        Parameters:
        time - the value that we wish to change the time to manipulate to.
      • getDays

        public long getDays()
      • setDays

        public void setDays​(long days)
      • getHours

        public int getHours()
      • setHours

        public void setHours​(int hours)
      • getMinutes

        public int getMinutes()
      • setMinutes

        public void setMinutes​(int minutes)
      • getSeconds

        public int getSeconds()
      • setSeconds

        public void setSeconds​(int seconds)
      • isAhead

        public boolean isAhead​(Time t2)
        Parameters:
        t2 - The other Time object to compare with this one.
        Returns:
        true if this Time object is ahead of the other one.
      • isBehind

        public boolean isBehind​(Time t2)
        Parameters:
        t2 - The other Time object to compare with this one.
        Returns:
        true if this Time object is behind the other one.
      • isSimilarTo

        public boolean isSimilarTo​(Time t2)
        Parameters:
        t2 - The other Time object to compare with this one.
        Returns:
        true if this Time object represents a time similar to this one.
      • timeToSeconds

        public long timeToSeconds()
        Returns:
        the seconds format of the input time. e.g 00:01:00:00 becomes 3600
      • timeString

        public java.lang.String timeString()
        Returns:
        a String object representing this Time object in dd:hh:mm:ss format.
      • timeGetter

        public static java.lang.String timeGetter()
        Returns:
        the system time and writes it in the hh:mm:ss format
      • convertSecondsToTime

        public static java.lang.String convertSecondsToTime​(long seconds)
        Parameters:
        seconds - the time in seconds.
        Returns:
        the time in the dd:hh:mm:ss format.
      • isBehindSystemTime

        public boolean isBehindSystemTime()
      • isSimilarToSystemTime

        public boolean isSimilarToSystemTime()
      • isAheadOfSystemTime

        public boolean isAheadOfSystemTime()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)