made wxFileName::Set/GetTimes() work under Win32

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12225 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2001-10-31 02:42:50 +00:00
parent 7de3c4699f
commit d56e2b972f
2 changed files with 73 additions and 7 deletions

View File

@ -43,7 +43,7 @@
//#define TEST_ARRAYS
//#define TEST_CHARSET
#define TEST_CMDLINE
//#define TEST_CMDLINE
//#define TEST_DATETIME
//#define TEST_DIR
//#define TEST_DLLLOADER
@ -52,6 +52,7 @@
//#define TEST_FILE
//#define TEST_FILECONF
//#define TEST_FILENAME
#define TEST_FILETIME
//#define TEST_FTP
//#define TEST_HASH
//#define TEST_INFO_FUNCTIONS
@ -64,7 +65,7 @@
//#define TEST_REGCONF
//#define TEST_REGEX
//#define TEST_REGISTRY
#define TEST_SNGLINST
//#define TEST_SNGLINST
//#define TEST_SOCKETS
//#define TEST_STREAMS
//#define TEST_STRINGS
@ -788,6 +789,48 @@ static void TestFileNameCwd()
#endif // TEST_FILENAME
// ----------------------------------------------------------------------------
// wxFileName time functions
// ----------------------------------------------------------------------------
#ifdef TEST_FILETIME
#include <wx/filename.h>
#include <wx/datetime.h>
static void TestFileGetTimes()
{
wxFileName fn(_T("testdata.fc"));
wxDateTime dtAccess, dtMod, dtChange;
if ( !fn.GetTimes(&dtAccess, &dtMod, &dtChange) )
{
wxPrintf(_T("ERROR: GetTimes() failed.\n"));
}
else
{
static const wxChar *fmt = _T("%Y-%b-%d %H:%M:%S");
wxPrintf(_T("File times for '%s':\n"), fn.GetFullPath().c_str());
wxPrintf(_T("Access: \t%s\n"), dtAccess.Format(fmt).c_str());
wxPrintf(_T("Mod/creation:\t%s\n"), dtMod.Format(fmt).c_str());
wxPrintf(_T("Change: \t%s\n"), dtChange.Format(fmt).c_str());
}
}
static void TestFileSetTimes()
{
wxFileName fn(_T("testdata.fc"));
wxDateTime dtAccess, dtMod, dtChange;
if ( !fn.Touch() )
{
wxPrintf(_T("ERROR: Touch() failed.\n"));
}
}
#endif // TEST_FILETIME
// ----------------------------------------------------------------------------
// wxHashTable
// ----------------------------------------------------------------------------
@ -5078,6 +5121,11 @@ int main(int argc, char **argv)
}
#endif // TEST_FILENAME
#ifdef TEST_FILETIME
TestFileGetTimes();
TestFileSetTimes();
#endif // TEST_FILETIME
#ifdef TEST_FTP
wxLog::AddTraceMask(FTP_TRACE_MASK);
if ( TestFtpConnect() )

View File

@ -120,14 +120,32 @@ private:
// convert between wxDateTime and FILETIME which is a 64-bit value representing
// the number of 100-nanosecond intervals since January 1, 1601.
static void ConvertWxToFileTime(FILETIME *ft, const wxDateTime& dt)
{
// TODO
}
// the number of milliseconds between the Unix Epoch (January 1, 1970) and the
// FILETIME reference point (January 1, 1601)
static const wxLongLong FILETIME_EPOCH_OFFSET = wxLongLong(0xa97, 0x30b66800);
static void ConvertFileTimeToWx(wxDateTime *dt, const FILETIME &ft)
{
// TODO
wxLongLong ll(ft.dwHighDateTime, ft.dwLowDateTime);
// convert 100ns to ms
ll /= 10000;
// move it to our Epoch
ll -= FILETIME_EPOCH_OFFSET;
*dt = wxDateTime(ll);
}
static void ConvertWxToFileTime(FILETIME *ft, const wxDateTime& dt)
{
// do the reverse of ConvertFileTimeToWx()
wxLongLong ll = dt.GetValue();
ll *= 10000;
ll += FILETIME_EPOCH_OFFSET;
ft->dwHighDateTime = ll.GetHi();
ft->dwLowDateTime = ll.GetLo();
}
#endif // __WIN32__