mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2025-08-15 14:27:39 +00:00
Incorporated fix from John Matthews for get/setPascalDate.
This commit is contained in:
@@ -28,7 +28,7 @@ import java.util.GregorianCalendar;
|
|||||||
* This class contains helper methods for dealing with Apple2 data.
|
* This class contains helper methods for dealing with Apple2 data.
|
||||||
* <p>
|
* <p>
|
||||||
* Date created: Oct 5, 2002 4:16:16 PM
|
* Date created: Oct 5, 2002 4:16:16 PM
|
||||||
* @author: Rob Greene
|
* @author Rob Greene
|
||||||
*/
|
*/
|
||||||
public class AppleUtil {
|
public class AppleUtil {
|
||||||
/**
|
/**
|
||||||
@@ -207,9 +207,9 @@ public class AppleUtil {
|
|||||||
*/
|
*/
|
||||||
public static Date getPascalDate(byte[] buffer, int offset) {
|
public static Date getPascalDate(byte[] buffer, int offset) {
|
||||||
int pascalDate = getWordValue(buffer, offset);
|
int pascalDate = getWordValue(buffer, offset);
|
||||||
int month = pascalDate & 0x000f;
|
int month = pascalDate & 0x000f - 1;
|
||||||
int day = (pascalDate & 0x00f0) >> 4;
|
int day = (pascalDate & 0x01f0) >> 4;
|
||||||
int year = (pascalDate & 0xff00) >> 8;
|
int year = (pascalDate & 0xfe00) >> 9;
|
||||||
if (year < 50) year+= 2000;
|
if (year < 50) year+= 2000;
|
||||||
if (year < 100) year+= 1900;
|
if (year < 100) year+= 1900;
|
||||||
GregorianCalendar gc = new GregorianCalendar(year, month, day);
|
GregorianCalendar gc = new GregorianCalendar(year, month, day);
|
||||||
@@ -225,12 +225,12 @@ public class AppleUtil {
|
|||||||
public static void setPascalDate(byte[] buffer, int offset, Date date) {
|
public static void setPascalDate(byte[] buffer, int offset, Date date) {
|
||||||
GregorianCalendar gc = new GregorianCalendar();
|
GregorianCalendar gc = new GregorianCalendar();
|
||||||
gc.setTime(date);
|
gc.setTime(date);
|
||||||
int month = gc.get(GregorianCalendar.MONTH);
|
int month = gc.get(GregorianCalendar.MONTH) + 1;
|
||||||
int day = gc.get(GregorianCalendar.DAY_OF_MONTH);
|
int day = gc.get(GregorianCalendar.DAY_OF_MONTH);
|
||||||
int year = gc.get(GregorianCalendar.YEAR) % 100;
|
int year = gc.get(GregorianCalendar.YEAR) % 100;
|
||||||
int pascalDate = (month & 0x000f)
|
int pascalDate = (month & 0x000f)
|
||||||
| ((day << 4) & 0x00f0)
|
| ((day << 4) & 0x01f0)
|
||||||
| ((year << 8) & 0xff00);
|
| ((year << 9) & 0xfe00);
|
||||||
setWordValue(buffer, offset, pascalDate);
|
setWordValue(buffer, offset, pascalDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user