Commit cf663d17 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

shlwapi: Implement SHFormatDateTimeA/SHFormatDateTimeW with tests.

parent 5d74e575
......@@ -4661,7 +4661,7 @@ HRESULT WINAPI SHGetViewStatePropertyBag(LPCITEMIDLIST pidl, LPWSTR bag_name,
* fileTime [I] Pointer to FILETIME structure specifying the time
* flags [I] Flags specifying the desired output
* buf [O] Pointer to buffer for output
* bufSize [I] Number of characters that can be contained in buffer
* size [I] Number of characters that can be contained in buffer
*
* RETURNS
* success: number of characters written to the buffer
......@@ -4669,10 +4669,65 @@ HRESULT WINAPI SHGetViewStatePropertyBag(LPCITEMIDLIST pidl, LPWSTR bag_name,
*
*/
INT WINAPI SHFormatDateTimeW(const FILETIME UNALIGNED *fileTime, DWORD *flags,
LPWSTR buf, UINT bufSize)
LPWSTR buf, UINT size)
{
FIXME("%p %p %s %d STUB\n", fileTime, flags, debugstr_w(buf), bufSize);
return 0;
#define SHFORMATDT_UNSUPPORTED_FLAGS (FDTF_RELATIVE | FDTF_LTRDATE | FDTF_RTLDATE | FDTF_NOAUTOREADINGORDER)
DWORD fmt_flags = flags ? *flags : FDTF_DEFAULT;
SYSTEMTIME st;
FILETIME ft;
INT ret = 0;
TRACE("%p %p %p %u\n", fileTime, flags, buf, size);
if (!buf || !size)
return 0;
if (fmt_flags & SHFORMATDT_UNSUPPORTED_FLAGS)
FIXME("ignoring some flags - 0x%08x\n", fmt_flags & SHFORMATDT_UNSUPPORTED_FLAGS);
FileTimeToLocalFileTime(fileTime, &ft);
FileTimeToSystemTime(&ft, &st);
/* first of all date */
if (fmt_flags & (FDTF_LONGDATE | FDTF_SHORTDATE))
{
static const WCHAR sep1[] = {',',' ',0};
static const WCHAR sep2[] = {' ',0};
DWORD date = fmt_flags & FDTF_LONGDATE ? DATE_LONGDATE : DATE_SHORTDATE;
ret = GetDateFormatW(LOCALE_USER_DEFAULT, date, &st, NULL, buf, size);
if (ret >= size) return ret;
/* add separator */
if (ret < size && (fmt_flags & (FDTF_LONGTIME | FDTF_SHORTTIME)))
{
if ((fmt_flags & FDTF_LONGDATE) && (ret < size + 2))
{
if (ret < size + 2)
{
lstrcatW(&buf[ret-1], sep1);
ret += 2;
}
}
else
{
lstrcatW(&buf[ret-1], sep2);
ret++;
}
}
}
/* time part */
if (fmt_flags & (FDTF_LONGTIME | FDTF_SHORTTIME))
{
DWORD time = fmt_flags & FDTF_LONGTIME ? 0 : TIME_NOSECONDS;
if (ret) ret--;
ret += GetTimeFormatW(LOCALE_USER_DEFAULT, time, &st, NULL, &buf[ret], size - ret);
}
return ret;
#undef SHFORMATDT_UNSUPPORTED_FLAGS
}
/***********************************************************************
......@@ -4682,21 +4737,19 @@ INT WINAPI SHFormatDateTimeW(const FILETIME UNALIGNED *fileTime, DWORD *flags,
*
*/
INT WINAPI SHFormatDateTimeA(const FILETIME UNALIGNED *fileTime, DWORD *flags,
LPCSTR buf, UINT bufSize)
LPSTR buf, UINT size)
{
WCHAR *bufW;
DWORD buflenW, convlen;
INT retval;
if (!buf || !bufSize)
if (!buf || !size)
return 0;
buflenW = bufSize;
bufW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * buflenW);
retval = SHFormatDateTimeW(fileTime, flags, bufW, buflenW);
bufW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
retval = SHFormatDateTimeW(fileTime, flags, bufW, size);
if (retval != 0)
convlen = WideCharToMultiByte(CP_ACP, 0, bufW, -1, (LPSTR) buf, bufSize, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, size, NULL, NULL);
HeapFree(GetProcessHeap(), 0, bufW);
return retval;
......
......@@ -1074,6 +1074,17 @@ BOOL WINAPI IsOS(DWORD);
#define TPS_EXECUTEIO 0x00000001
#define TPS_LONGEXECTIME 0x00000008
/* SHFormatDateTimeA/SHFormatDateTimeW flags */
#define FDTF_SHORTTIME 0x00000001
#define FDTF_SHORTDATE 0x00000002
#define FDTF_DEFAULT (FDTF_SHORTDATE | FDTF_SHORTTIME)
#define FDTF_LONGDATE 0x00000004
#define FDTF_LONGTIME 0x00000008
#define FDTF_RELATIVE 0x00000010
#define FDTF_LTRDATE 0x00000100
#define FDTF_RTLDATE 0x00000200
#define FDTF_NOAUTOREADINGORDER 0x00000400
#include <poppack.h>
#ifdef __cplusplus
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment