Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/clock/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ static std::string format_iso8601(const std::tm& time) {
return std::string(buffer);
}

// Helper function to format time into SOS set_time string
static std::string format_sos(const std::tm& time) {
char buffer[30];
// Format: YYYYMMDD0HHMMSS000 - raw time, no timezone info supported.
// ref SOS Reference Manual: https://archive.org/details/apple-iii-sos-reference-manual-volume-2/page/94/mode/2up
std::strftime(buffer, sizeof(buffer), "%Y%m%d0%H%M%S000", &time);
return std::string(buffer);
}

std::string Clock::get_current_time_iso(const std::string& posixTimeZone) {
set_timezone_env("TZ", posixTimeZone);
std::time_t now = std::time(nullptr);
Expand Down Expand Up @@ -102,4 +111,16 @@ std::vector<uint8_t> Clock::get_current_time_apetime(const std::string& posixTim
// Debug_printf("apetime: %s, %s\r\n", dstring.c_str(), posixTimeZone.c_str());

return apeTime;
}

std::string Clock::get_current_time_sos(const std::string& posixTimeZone) {
set_timezone_env("TZ", posixTimeZone);
std::time_t now = std::time(nullptr);
std::tm* localTime = std::localtime(&now);

// Format the time into Apple /// SOS set_time format YYYYMMDD0HHMMSS000
std::string sosString = format_sos(*localTime);
//Debug_printf("SOS set_time format time: %s\r\n", sosString.c_str());

return sosString;
}
3 changes: 3 additions & 0 deletions lib/clock/Clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Clock {
// current local time in ApeTime format
static std::vector<uint8_t> get_current_time_apetime(const std::string& posixTimeZone);

// current local time in SOS set_time format
static std::string get_current_time_sos(const std::string& posixTimeZone);

};

#endif // CLASS_CLOCK_H
10 changes: 9 additions & 1 deletion lib/device/iwm/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ void iwmClock::iwm_status(iwm_decoded_cmd_t cmd)
break;
}
case 'S': {
// Date and time, ASCII string in ISO format - This is a change from the original format: YYYYMMDDxHHMMSSxxx with 0 for every 'x' value, which was not TZ friendly, and I found no references to
// Date and time, ASCII string in Apple /// SOS format: YYYYMMDD0HHMMSS000
std::string sosTime = Clock::get_current_time_sos(Config.get_general_timezone());
std::copy(sosTime.begin(), sosTime.end(), data_buffer);
data_buffer[sosTime.size()] = '\0'; // this is a string in a buffer, we will null terminate it (this is also a change to the original that sent the char bytes without a null)
data_len = sosTime.size() + 1; // and ensure the size reflects the null terminator
break;
}
case 'I': {
// Date and time, ASCII string in ISO format
std::string utcTime = Clock::get_current_time_iso(Config.get_general_timezone());
std::copy(utcTime.begin(), utcTime.end(), data_buffer);
data_buffer[utcTime.size()] = '\0'; // this is a string in a buffer, we will null terminate it (this is also a change to the original that sent the char bytes without a null)
Expand Down
Loading