: Class Clock

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.dalsemi.system
Class Clock

    java.lang.Object
      |
      +--com.dalsemi.system.Clock

public class Clock
extends Object

This class provides access to the TINI Real-Time clock. The methods support setting and getting the clock values. The Real-Time clock on TINI is an 8 `byte` register that stores the year, month, date, day, hour, minute, second, and hundredth-second in BCD format.

### Usage

There are two basic ways to access TINI's Real-Time clock. The faster method is to directly use the values `year`, `month`, etc.

          ...
          com.dalsemi.system.Clock C = new com.dalsemi.system.Clock();
          C.getRTC();
          System.out.println("The date is : " + C.getDate() + "/" +
                              C.getMonth() + "/" + C.getYear());
          System.out.println("The time is : " + C.getHour() + ":" +
                             C.getMinute() + ":" + C.getSecond() +
                             "." + C.getHundredth() + C.getPm() ? " PM" : " AM"));
          ...

The other method is slower, but provides a mean to translate between the TINI Real-Time clock and the Java timekeeping methods which require a `long` value of milliseconds that have passed since January 1, 1970. This method is slower, since the `Clock` class must convert from its internal fields into an amount of milliseconds.

          ...
          com.dalsemi.system.Clock C = new com.dalsemi.system.Clock();
          long time = C.getTickCount();
          System.out.println(new java.util.Date(time));
          ...

This class also provides means to set the Real-Time Clock settings. The methods for setting `Clock` values are analogous to the methods for getting, except that after all fields have been set as desired, programs should call `setRTC()`. The following code sets the TINI Real-Time clock to October 4, 2000 at 1:43 in the afternoon.

          C.setYear(2000);
          C.setMonth(10);
          C.setDate(4);

          C.setHour(13);
          C.setPm(true);
          C.setMinute(43);

          C.setRTC();
          System.out.println(new java.util.Date(C.getTickCount()));

Note that the time printed will probably not be 1:43 PM. The time stored is for GMT. On a TINI with Central Standard Time as the default `TimeZone`, this program prints out:

`

        TINI /> java clockdemo.tini
        Wed Oct 4 08:43:59 CST 2000

`

which is correct because CST during Daylight Savings Time (CDT) is 5 hours behind GMT. Also note that `getRTC()` is not called in the above code example. It is called internally by `getTickCount()`. Any other 'get' accesses should call `getRTC()` first.

Field Summary
`protected int` | `date` Stores the day of the month.
`protected int` | `day` Stores the day of the week (1-7).
`protected int` | `hour` Stores the hour (1-12 or 0-23).
`protected int` | `hundredth` Stores the hundredth-second.
`protected boolean` | `is12Hour` This flag signifies if the value stored in `hour` is for a 1-12 hour clock that uses AM and PM settings or a 0-23 hour clock that does not use AM and PM settings.
`protected int` | `minute` Stores the minute.
`protected int` | `month` Stores the month (1-12).
`protected boolean` | `pm` Stores the AM/PM selection.
`protected int` | `second` Stores the second.
`protected int` | `year` Stores the year mod 100.

Constructor Summary
`Clock()` Creates a new `Clock` instance for accessing TINI's Real-Time clock.

Method Summary
`static int` | `bcdToInt(int bcdVal)` Converts a BCD integer byte to its binary integer value.
`static int` | `calculateDayOfWeek(int month, int date, int fullYear)` Calculates the correct day of the week given the month, day of the month, and year.
`boolean` | `get12Hour()` Get the 12/24 Hour mode for the Real-Time Clock.
`int` | `getDate()` Get the date (day of month) value for the Real-Time Clock.
`int` | `getDay()` Get the day of the week value for the Real-Time Clock.
`int` | `getHour()` Get the hour value for the Real-Time Clock.
`int` | `getHundredth()` Get the hundredth-second value for the Real-Time Clock.
`int` | `getMinute()` Get the minute value for the Real-Time Clock.
`int` | `getMonth()` Get the month value for the Real-Time Clock.
`boolean` | `getPm()` Get the AM/PM value for the Real Time Clock.
`void` | `getRTC()` Reads Real time clock values from hardware clock and places them into `Clock` instance fields.
`int` | `getSecond()` Get the second value for the Real-Time Clock.
`long` | `getTickCount()` Get the current time in milliseconds since midnight Jan 1, 1970, UTC.
`int` | `getYear()` Get the year value for the Real-Time Clock.
`static byte` | `intToBCD(int intVal)` Converts a binary integer byte to its BCD value.
`void` | `set12Hour(boolean is12Hour)` Sets the 12/24 hour mode of the Real-Time Clock.
`void` | `setDate(int date)` Sets the date (day of the month) value of the Real-Time Clock.
`void` | `setDay(int day)` Sets the day of the week value of the Real-Time Clock.
`void` | `setHour(int hour)` Sets the hour value of the Real-Time Clock.
`void` | `setHundredth(int hundredth)` Sets the hundredth-second value of the Real-Time Clock.
`void` | `setMinute(int minute)` Sets the minute value of the Real-Time Clock.
`void` | `setMonth(int month)` Sets the month value of the Real-Time Clock.
`void` | `setPm(boolean pm)` Sets the AM/PM value of the Real Time Clock.
`void` | `setRTC()` Reads the stored values `year`, `month`, `date`, etc.
`void` | `setSecond(int second)` Sets the second value of the Real-Time Clock.
`void` | `setTickCount(long millis)` Set the current time from a value in milliseconds since Jan 1, 1970, UTC.
`void` | `setYear(int year)` Sets the year value of the Real-Time Clock.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### year

    protected int year

  Stores the year mod 100. This field is set by `getRTC()` and used by the `setRTC()` method to set the Real-Time Clock. used by the `setRTC()` method to set the Real-Time Clock.
  See Also:
    `setYear(int)`, `getYear()`

### month

    protected int month

  Stores the month (1-12). This field is set by `getRTC()` and used by the `setRTC()` method to set the Real-Time Clock.
  See Also:
    `setMonth(int)`, `getMonth()`

### day

    protected int day

  Stores the day of the week (1-7). This field is set by `getRTC()` and used by the `setRTC()` method to set the Real-Time Clock.
  See Also:
    `setDay(int)`, `getDay()`

### date

    protected int date

  Stores the day of the month. This field is set by `getRTC()` and used by the `setRTC()` method to set the Real-Time Clock.
  See Also:
    `setDate(int)`, `getDate()`

### hour

    protected int hour

  Stores the hour (1-12 or 0-23). This field is set by `getRTC()` and used by the `setRTC()` method to set the Real-Time Clock.
  See Also:
    `setHour(int)`, `getHour()`

### minute

    protected int minute

  Stores the minute. This field is set by `getRTC()` and used by the `setRTC()` method to set the Real-Time Clock.
  See Also:
    `setMinute(int)`, `getMinute()`

### second

    protected int second

  Stores the second. This field is set by `getRTC()` and used by the `setRTC()` method to set the Real-Time Clock.
  See Also:
    `setSecond(int)`, `getSecond()`

### hundredth

    protected int hundredth

  Stores the hundredth-second. This field is set by `getRTC()` and used by the `setRTC()` method to set the Real-Time Clock.
  See Also:
    `setHundredth(int)`, `getHundredth()`

### pm

    protected boolean pm

  Stores the AM/PM selection. The hour is interpreted based on the value of this flag if the is12Hour flag is set.
  See Also:
    `setPm(boolean)`, `getPm()`

### is12Hour

    protected boolean is12Hour

  This flag signifies if the value stored in `hour` is for a 1-12 hour clock that uses AM and PM settings or a 0-23 hour clock that does not use AM and PM settings.
  See Also:
    `set12Hour(boolean)`, `get12Hour()`

Constructor Detail

### Clock

    public Clock()

  Creates a new `Clock` instance for accessing TINI's Real-Time clock. Also performs a call to `getRTC()` so the fields of this `Clock` object initially have valid values.
  See Also:
    `getRTC()`

Method Detail

### setYear

    public void setYear(int year)

  Sets the year value of the Real-Time Clock. The clock will only store the value of year mod 100. This only sets the instance variable for this object. A call to `setRTC()` should be performed to actually set the Real-Time Clock.
  Parameters:
    `year` - the year to be set
  See Also:
    `getYear()`, `setRTC()`

### getYear

    public int getYear()

  Get the year value for the Real-Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock.
  Returns:
    the year as reported by TINI's Real-Time Clock
  See Also:
    `getRTC()`, `setYear(int)`

### setMonth

    public void setMonth(int month)

  Sets the month value of the Real-Time Clock. This only sets the instance variable for this object. A call to `setRTC()` should be performed to actually set the Real-Time Clock.
  Parameters:
    `month` - the month to be set
  See Also:
    `getMonth()`, `setRTC()`

### getMonth

    public int getMonth()

  Get the month value for the Real-Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock.
  Returns:
    the month as reported by TINI's Real-Time Clock
  See Also:
    `getRTC()`, `setMonth(int)`

### setDay

    public void setDay(int day)

  Sets the day of the week value of the Real-Time Clock. This only sets the instance variable for this object. A call to `setRTC()` should be performed to actually set the Real-Time Clock. To facilitate setting the correct day of the week, first call `calculateDayOfWeek` which calculates the day of the week depending on the year, month, and date.
  Parameters:
    `day` - the day of the week to be set
  See Also:
    `calculateDayOfWeek(int,int,int)`, `getDay()`, `setRTC()`

### getDay

    public int getDay()

  Get the day of the week value for the Real-Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock.
  Returns:
    the day of the week as reported by TINI's Real-Time Clock
  See Also:
    `getRTC()`, `setDay(int)`

### setDate

    public void setDate(int date)

  Sets the date (day of the month) value of the Real-Time Clock. This only sets the instance variable for this object. A call to `setRTC()` should be performed to actually set the Real-Time Clock.
  Parameters:
    `date` - the day of the month to be set
  See Also:
    `getDate()`, `setRTC()`

### getDate

    public int getDate()

  Get the date (day of month) value for the Real-Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock.
  Returns:
    the day of the month as reported by TINI's Real-Time Clock
  See Also:
    `getRTC()`, `setDate(int)`

### setHour

    public void setHour(int hour)

  Sets the hour value of the Real-Time Clock. This only sets the instance variable for this object. A call to `setRTC()` should be performed to actually set the Real-Time Clock. The value actually stored in TINI's Real-Time Clock is also determined by the `is12Hour` flag and the `pm` flag.
  Parameters:
    `hour` - the hour to be set
  See Also:
    `set12Hour(boolean)`, `setPm(boolean)`, `getHour()`, `setRTC()`

### getHour

    public int getHour()

  Get the hour value for the Real-Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock. The methods `get12Hour()` and `getPm()` should also be called to find the exact meaning of the `hour` value.
  Returns:
    the hour as reported by TINI's Real-Time Clock
  See Also:
    `getPm()`, `get12Hour()`, `getRTC()`, `setHour(int)`

### setMinute

    public void setMinute(int minute)

  Sets the minute value of the Real-Time Clock. This only sets the instance variable for this object. A call to `setRTC()` should be performed to actually set the Real-Time Clock.
  Parameters:
    `minute` - the minute to be set
  See Also:
    `getMinute()`, `setRTC()`

### getMinute

    public int getMinute()

  Get the minute value for the Real-Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock.
  Returns:
    the minute as reported by TINI's Real-Time Clock
  See Also:
    `getRTC()`, `setMinute(int)`

### setSecond

    public void setSecond(int second)

  Sets the second value of the Real-Time Clock. This only sets the instance variable for this object. A call to `setRTC()` should be performed to actually set the Real-Time Clock.
  Parameters:
    `second` - the second to be set
  See Also:
    `getSecond()`, `setRTC()`

### getSecond

    public int getSecond()

  Get the second value for the Real-Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock.
  Returns:
    the second as reported by TINI's Real-Time Clock
  See Also:
    `getRTC()`, `setSecond(int)`

### setHundredth

    public void setHundredth(int hundredth)

  Sets the hundredth-second value of the Real-Time Clock. This only sets the instance variable for this object. A call to `setRTC()` should be performed to actually set the Real-Time Clock.
  Parameters:
    `hundredth` - the hundredth-second to be set
  See Also:
    `getHundredth()`, `setRTC()`

### getHundredth

    public int getHundredth()

  Get the hundredth-second value for the Real-Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock.
  Returns:
    the hundredth-second as reported by TINI's Real-Time Clock
  See Also:
    `getRTC()`, `setHundredth(int)`

### setPm

    public void setPm(boolean pm)

  Sets the AM/PM value of the Real Time Clock. This only sets the instance variable for this object. A call to setRTC should be performed to actually set the real time clock. Note that the value pf `pm` only matters if `is12Hour` is `true`.
  Parameters:
    `pm` - `true` for PM, `false` for AM
  See Also:
    `getPm()`, `setRTC()`, `set12Hour(boolean)`

### getPm

    public boolean getPm()

  Get the AM/PM value for the Real Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock. The value of the pm flag is only relevant if the is12Hour flag is set. If the is12Hour flag is not set, the value for `hour` will range between 0 and 23, and the pm flag is irrelevant.
  Returns:
    `true` for PM, `false` for AM
  See Also:
    `getRTC()`, `setPm(boolean)`, `get12Hour()`, `getHour()`

### set12Hour

    public void set12Hour(boolean is12Hour)

  Sets the 12/24 hour mode of the Real-Time Clock. This only sets the instance variable for this object. A call to setRTC should be performed to actually set the real time clock. If the argument is `true`, then the value of the flag `pm` matters when `setRTC()` is called.
  Parameters:
    `is12Hour` - `true` for 12 hour clock, `false` for 24 hour clock
  See Also:
    `setRTC()`, `get12Hour()`, `#setPm()`

### get12Hour

    public boolean get12Hour()

  Get the 12/24 Hour mode for the Real-Time Clock. To get the latest value, `getRTC()` should be called before this method to refresh the value from TINI's Real-Time Clock. If the `is12Hour` flag is not set, the value for `hour` will range between 0 and 23, and the `pm` flag is irrelevant. If the `is12Hour` flag is set, the value for `hour` will range between 1 and 12, and the `pm` flag will be relevant.
  Returns:
    `true` for 12 hour clock, `false` for 24 hour clock
  See Also:
    `getRTC()`, `getPm()`, `set12Hour(boolean)`, `getHour()`

### getRTC

    public void getRTC()

  Reads Real time clock values from hardware clock and places them into `Clock` instance fields. This method should be called to refresh the `Clock` instance fields, and before any 'get' methods are called.
  See Also:
    `setRTC()`

### getTickCount

    public long getTickCount()

  Get the current time in milliseconds since midnight Jan 1, 1970, UTC. This method calls `getRTC()`, so it is unnecessary for callers to do so. The value returned is suitable to be used in calls to Java classes such as `java.util.Date` and `java.util.Calendar`.

  Note: This method assumes the current year is the year 2000 or later. Since the Real-Time Clock only stores the 2 least significant digits of the year, this method assumes that the clock represents a time after midnight, January 1, 2000.

  Returns:
    number of milliseconds since midnight, Jan 1, 1970 UTC
  See Also:
    `setTickCount(long)`

### setTickCount

    public void setTickCount(long millis)

  Set the current time from a value in milliseconds since Jan 1, 1970, UTC. This method calls `setRTC()` before exiting. This method must parse the millisecond value into fields for the year, month, date, and so on. This is more time consuming than setting the fields individually.

  This method is not written to handle negative values for `millis`. Also note that this method will only store the 2 least significant digits of the year. Subsequent calls to `getTickCount()` will add these 2 digits to the year 2000 to come up with the current year. If you call `setTickCount()` with a value for a date in 1999, then `getTickCount()` will return you a value for a date in 2099.

  Parameters:
    `millis` - number of milliseconds since midnight, Jan 1, 1970 UTC
  See Also:
    `getTickCount()`

### setRTC

    public void setRTC()

  Reads the stored values `year`, `month`, `date`, etc. and stores them in TINI's Real-Time Clock. This method performs bounds checking on all values, however it does not ensure that invalid dates (February 30) or days of the week (Friday for October 5 2000) have been entered.
  See Also:
    `getRTC()`

### calculateDayOfWeek

    public static int calculateDayOfWeek(int month,
                                         int date,
                                         int fullYear)

  Calculates the correct day of the week given the month, day of the month, and year. This method will not work for dates before 1900 or after the year 3000.
  Parameters:
    `month` - the month (1-12)
    `date` - the day of the month
    `fullYear` - the year (not mod 100)
  Returns:
    The day of the week (1-7). 1 is Saturday, 2 is Sunday, etc.

### bcdToInt

    public static int bcdToInt(int bcdVal)

  Converts a BCD integer byte to its binary integer value.
  Parameters:
    `bcdVal` - the BCD integer to convert to a decimal integer
  Returns:
    the converted decimal integer
  See Also:
    `intToBCD(int)`

### intToBCD

    public static byte intToBCD(int intVal)

  Converts a binary integer byte to its BCD value.
  Parameters:
    `intVal` - decimal value to convert to BCD
  Returns:
    the converted BCD integer
  See Also:
    `bcdToInt(int)`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD