From e8bbea1fc6e94e14768509d322f6c624403ffb36 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sun, 22 Aug 2021 09:06:15 +1000 Subject: formats, osd, util: Started refactoring file I/O stuff. (#8456) Added more modern generic I/O interfaces with implementation backed by stdio, osd_file and core_file, replacing io_generic. Also replaced core_file's build-in zlib compression with a filter. unzip.cpp, un7z.cpp: Added option to supply abstract I/O interface rather than filename. Converted osd_file, core_file, archive_file, chd_file and device_image_interface to use std::error_condition rather than their own error enums. Allow mounting TI-99 RPK from inside archives. --- src/lib/util/timeconv.cpp | 69 ++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 34 deletions(-) (limited to 'src/lib/util/timeconv.cpp') diff --git a/src/lib/util/timeconv.cpp b/src/lib/util/timeconv.cpp index 99953712003..469b6b592a2 100644 --- a/src/lib/util/timeconv.cpp +++ b/src/lib/util/timeconv.cpp @@ -14,42 +14,10 @@ namespace util { -/*************************************************************************** - PROTOTYPES -***************************************************************************/ - -static std::chrono::system_clock::duration calculate_system_clock_adjustment(); - - -/*************************************************************************** - GLOBAL VARIABLES -***************************************************************************/ - -std::chrono::system_clock::duration system_clock_adjustment(calculate_system_clock_adjustment()); - - -/*************************************************************************** - IMPLEMENTATION -***************************************************************************/ - -arbitrary_datetime arbitrary_datetime::now() -{ - time_t sec; - time(&sec); - auto t = *localtime(&sec); - - arbitrary_datetime dt; - dt.year = t.tm_year + 1900; - dt.month = t.tm_mon + 1; - dt.day_of_month = t.tm_mday; - dt.hour = t.tm_hour; - dt.minute = t.tm_min; - dt.second = t.tm_sec; - return dt; -} +namespace { -static std::chrono::system_clock::duration calculate_system_clock_adjustment() +std::chrono::system_clock::duration calculate_system_clock_adjustment() { constexpr auto days_in_year(365); constexpr auto days_in_four_years((days_in_year * 4) + 1); @@ -84,6 +52,39 @@ static std::chrono::system_clock::duration calculate_system_clock_adjustment() return result - std::chrono::system_clock::from_time_t(0).time_since_epoch(); } +} // anonymous namespace + + + +/*************************************************************************** + GLOBAL VARIABLES +***************************************************************************/ + +std::chrono::system_clock::duration system_clock_adjustment(calculate_system_clock_adjustment()); + + + +/*************************************************************************** + IMPLEMENTATION +***************************************************************************/ + +arbitrary_datetime arbitrary_datetime::now() +{ + time_t sec; + time(&sec); + auto t = *localtime(&sec); + + arbitrary_datetime dt; + dt.year = t.tm_year + 1900; + dt.month = t.tm_mon + 1; + dt.day_of_month = t.tm_mday; + dt.hour = t.tm_hour; + dt.minute = t.tm_min; + dt.second = t.tm_sec; + + return dt; +} + // ------------------------------------------------- -- cgit v1.2.3-70-g09d2