diff options
| author | 2017-04-05 21:39:00 -0400 | |
|---|---|---|
| committer | 2017-04-06 11:39:00 +1000 | |
| commit | f809f0e08d451c7fa05116c9c7b147f499ea82d7 (patch) | |
| tree | 8a97a329d1be1014fb51bd36b400c4dee4d2153f /src/tools | |
| parent | ee19701c2cd582c17c8a3b855386cd1b79856560 (diff) | |
Introduced an 'util::arbitrary_clock' template class, to represent a clock that "knows" when the epoch starts (#2010)
* Introduced an 'util::arbitrary_clock' template class, to represent a clock that "knows" when the epoch starts
Also:
- Converted the NTFS filetime code to use util::arbitrary_clock
- Converted the Mac datetime code to use util::atribrary_clock
This is in preparation for a bigger change to Imgtool where I eliminate usage of time_t
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/imgtool/modules/macutil.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/tools/imgtool/modules/macutil.cpp b/src/tools/imgtool/modules/macutil.cpp index 3765f976319..1bab14487cd 100644 --- a/src/tools/imgtool/modules/macutil.cpp +++ b/src/tools/imgtool/modules/macutil.cpp @@ -2,7 +2,7 @@ // copyright-holders:Raphael Nabet /**************************************************************************** - macutil.c + macutil.cpp Imgtool Utility code for manipulating certain Apple/Mac data structures and conventions @@ -10,20 +10,25 @@ *****************************************************************************/ #include "macutil.h" +#include "timeconv.h" +typedef util::arbitrary_clock<std::uint32_t, 1904, 1, 1, 0, 0, 0, std::ratio<1, 1> > classic_mac_clock; + time_t mac_crack_time(uint32_t t) { - /* not sure if this is correct... */ - return t - (((1970 - 1904) * 365) + 17) * 24 * 60 * 60; + classic_mac_clock::duration d(t); + std::chrono::time_point<std::chrono::system_clock> tp = classic_mac_clock::to_system_clock(std::chrono::time_point<classic_mac_clock>(d)); + return std::chrono::system_clock::to_time_t(tp); } uint32_t mac_setup_time(time_t t) { - /* not sure if this is correct... */ - return t + (((1970 - 1904) * 365) + 17) * 24 * 60 * 60; + auto system_time_point = std::chrono::system_clock::from_time_t(t); + auto mac_time_point = classic_mac_clock::from_system_clock(system_time_point); + return mac_time_point.time_since_epoch().count(); } |
