Skip to content

Commit

Permalink
Merge pull request cebix#8 from DrLex0/day_offset_prefs_item
Browse files Browse the repository at this point in the history
Add prefs item "dayofs" for finer-grained time offset
  • Loading branch information
kanjitalk755 authored Feb 10, 2019
2 parents e676dbf + 64e408c commit 2eed2f0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion BasiliskII/src/macos_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ uint32 TimeToMacTime(time_t t)
struct tm *local = localtime(&t);
const int TM_EPOCH_YEAR = 1900;
const int MAC_EPOCH_YEAR = 1904;
// Clip year and day offsets to prevent dates earlier than 1-Jan-1904
local->tm_year = std::max(MAC_EPOCH_YEAR - TM_EPOCH_YEAR, local->tm_year - PrefsFindInt32("yearofs"));
int a4 = ((local->tm_year + TM_EPOCH_YEAR) >> 2) - !(local->tm_year & 3);
int b4 = (MAC_EPOCH_YEAR >> 2) - !(MAC_EPOCH_YEAR & 3);
Expand All @@ -145,7 +146,10 @@ uint32 TimeToMacTime(time_t t)
int b400 = b100 >> 2;
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days;
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * days));
int32 dayofs = PrefsFindInt32("dayofs");
if(dayofs > 0 && dayofs > days)
dayofs = days;
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * (days - dayofs)));
}

/*
Expand Down
1 change: 1 addition & 0 deletions BasiliskII/src/prefs_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ prefs_desc common_prefs_items[] = {
{"scale_nearest",TYPE_BOOLEAN,false,"nearest neighbor scaling"},
{"scale_integer",TYPE_BOOLEAN,false,"integer scaling"},
{"yearofs", TYPE_INT32, 0, "year offset"},
{"dayofs", TYPE_INT32, 0, "day offset"},
{NULL, TYPE_END, false, NULL} // End of list
};

Expand Down
6 changes: 5 additions & 1 deletion SheepShaver/src/macos_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ uint32 TimeToMacTime(time_t t)
#endif
const int TM_EPOCH_YEAR = 1900;
const int MAC_EPOCH_YEAR = 1904;
// Clip year and day offsets to prevent dates earlier than 1-Jan-1904
local->tm_year = std::max(MAC_EPOCH_YEAR - TM_EPOCH_YEAR, local->tm_year - PrefsFindInt32("yearofs"));
int a4 = ((local->tm_year + TM_EPOCH_YEAR) >> 2) - !(local->tm_year & 3);
int b4 = (MAC_EPOCH_YEAR >> 2) - !(MAC_EPOCH_YEAR & 3);
Expand All @@ -344,7 +345,10 @@ uint32 TimeToMacTime(time_t t)
int b400 = b100 >> 2;
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days;
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * days));
int32 dayofs = PrefsFindInt32("dayofs");
if(dayofs > 0 && dayofs > days)
dayofs = days;
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * (days - dayofs)));
}


Expand Down
1 change: 1 addition & 0 deletions SheepShaver/src/prefs_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ prefs_desc common_prefs_items[] = {
{"scale_integer",TYPE_BOOLEAN,false,"integer scaling"},
{"cpuclock", TYPE_INT32, 0, "CPU clock [MHz] of system info"},
{"yearofs", TYPE_INT32, 0, "year offset"},
{"dayofs", TYPE_INT32, 0, "day offset"},
{NULL, TYPE_END, false, NULL} // End of list
};

Expand Down

0 comments on commit 2eed2f0

Please sign in to comment.