Skip to content

Commit

Permalink
Fix date calculation and broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heaths committed Jan 2, 2018
1 parent 469ccf6 commit 0952074
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/vswhere.lib/Formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,46 +94,46 @@ wstring Formatter::FormatDateISO8601(_In_ const FILETIME& value)

wstring Formatter::FormatDate(_In_ const FILETIME& value)
{
FILETIME local = {};
SYSTEMTIME st = {};
SYSTEMTIME stUniversal = {};
SYSTEMTIME stLocal = {};
wstring date;
wstring time;

if (!::FileTimeToLocalFileTime(&value, &local))
if (!::FileTimeToSystemTime(&value, &stUniversal))
{
throw win32_error();
}

if (!::FileTimeToSystemTime(&local, &st))
if (!::SystemTimeToTzSpecificLocalTime(NULL, &stUniversal, &stLocal))
{
throw win32_error();
}

// Format date
auto cch = ::GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, NULL, 0);
auto cch = ::GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stLocal, NULL, NULL, 0);
if (!cch)
{
throw win32_error();
}

date.reserve(cch);
date.resize(cch - 1);
cch = ::GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, const_cast<LPWSTR>(date.c_str()), cch);
cch = ::GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stLocal, NULL, const_cast<LPWSTR>(date.c_str()), cch);
if (!cch)
{
throw win32_error();
}

// Format time
cch = ::GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, NULL, 0);
cch = ::GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &stLocal, NULL, NULL, 0);
if (!cch)
{
throw win32_error();
}

time.reserve(cch);
time.resize(cch - 1);
cch = ::GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, const_cast<LPWSTR>(time.c_str()), cch);
cch = ::GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &stLocal, NULL, const_cast<LPWSTR>(time.c_str()), cch);
if (!cch)
{
throw win32_error();
Expand Down
4 changes: 2 additions & 2 deletions test/vswhere.test/TextFormatterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ TEST_CLASS(TextFormatterTests)

auto expected =
L"instanceId: a1b2c3\n"
L"installDate: 2/22/2017 6:22:35 PM\n"
L"installDate: 2/22/2017 5:22:35 PM\n"
L"installationName: test\n"
L"properties_campaignId: abcd1234\n"
L"properties_nickname: test\n";
Expand Down Expand Up @@ -392,7 +392,7 @@ TEST_CLASS(TextFormatterTests)

auto expected =
L"instanceId: a1b2c3\n"
L"installDate: 2/22/2017 6:22:35 PM\n"
L"installDate: 2/22/2017 5:22:35 PM\n"
L"installationName: test\n"
L"isPrerelease: 0\n"
L"catalog_productLineVersion: 2017\n"
Expand Down
4 changes: 2 additions & 2 deletions test/vswhere.test/ValueFormatterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ TEST_CLASS(ValueFormatterTests)

auto expected =
L"a1b2c3\n"
L"2/22/2017 6:22:35 PM\n"
L"2/22/2017 5:22:35 PM\n"
L"test\n"
L"abcd1234\n"
L"test\n";
Expand Down Expand Up @@ -365,7 +365,7 @@ TEST_CLASS(ValueFormatterTests)

auto expected =
L"a1b2c3\n"
L"2/22/2017 6:22:35 PM\n"
L"2/22/2017 5:22:35 PM\n"
L"test\n"
L"0\n"
L"2017\n"
Expand Down

0 comments on commit 0952074

Please sign in to comment.