All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.webcodepro.shrinkit.TimeRec Maven / Gradle / Ivy

package com.webcodepro.shrinkit;

import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * Apple IIgs Toolbox TimeRec object.
 *  
 * @author [email protected]
 */
public class TimeRec {
	private static final int SECOND = 0;
	private static final int MINUTE = 1;
	private static final int HOUR = 2;
	private static final int YEAR = 3;
	private static final int DAY = 4;
	private static final int MONTH = 5;
	private static final int WEEKDAY = 7;
	private static final int LENGTH = 8;
	private byte[] data = null;
	
	/**
	 * Construct a TimeRec with the current date.
	 */
	public TimeRec() {
		this(new Date());
	}
	/**
	 * Construct a TimeRec with the specified date.  You may pass in a null for a null date (all 0x00's).
	 */
	public TimeRec(Date date) {
		setDate(date);
	}
	/**
	 * Construct a TimeRec from the given LENGTH byte array.
	 */
	public TimeRec(byte[] bytes, int offset) {
		if (bytes == null || bytes.length - offset < LENGTH) {
			throw new IllegalArgumentException("TimeRec requires a " + LENGTH + " byte array.");
		}
		//data = Arrays.copyOfRange(bytes, offset, LENGTH);
		data = new byte[LENGTH];
		System.arraycopy(bytes, offset, data, 0, LENGTH);
	}
	/**
	 * Construct a TimeRec from the InputStream.
	 */
	public TimeRec(InputStream inputStream) throws IOException {
		data = new byte[LENGTH];
		for (int i=0; iNuFX addendum
	 */
	public Date getDate() {
		int year = data[YEAR]+1900;
		if (year < 1940) year+= 100;
		GregorianCalendar gc = new GregorianCalendar(year, data[MONTH]+1, data[DAY], data[HOUR], data[MINUTE], data[SECOND]);
		return gc.getTime();
	}
	public byte[] getBytes() {
		return data;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy