#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_STORAGE_SOURCE 1 #include "../../../Source/FileSystem/Windows/DateHelper.h" #include #if defined(NUCLEX_STORAGE_WIN32) namespace Nuclex { namespace Storage { namespace FileSystem { namespace Windows { // ------------------------------------------------------------------------------------------- // TEST(DateHelperTest, CanConvertFiletimeToPosixTime) { // The posix epoch begins on January 1st,1970, so this should be zero std::uint64_t filetime_1970_01_01 = 116444736000000000ULL; EXPECT_EQ(DateHelper::PosixTimeFromFileTime(filetime_1970_01_01), 0); // Try ten years later. This includes two leap years. // I let Wolfram alpha calculate the number of days inbetwen, it's 3652 days. std::uint64_t filetime_1980_01_01 = 119600064000000000ULL; EXPECT_EQ(DateHelper::PosixTimeFromFileTime(filetime_1980_01_01), (3652U * 86400ULL)); // Example value: https://docs.microsoft.com/en-us/powerquery-m/datetime-fromfiletime // I let Wolfram alpha calculate the number of days from 1970 till this date, // dealing with leap years and everything. It's 15,545 days. std::uint64_t fileTime_2012_07_24_14_50_52_984 = 129876150529840000ULL; std::time_t posixTime_2012_07_24_14_50_53 = std::time_t( (15545 * 86400ULL) + (14 * 3600) + (50 * 60) + (53) ); EXPECT_EQ( DateHelper::PosixTimeFromFileTime(fileTime_2012_07_24_14_50_52_984), posixTime_2012_07_24_14_50_53 ); } // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::Windows #endif // defined(NUCLEX_STORAGE_WIN32)