using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Vanara.PInvoke
{
public static partial class Kernel32
{
/// Flags specifying time format options.
[Flags]
public enum TIME_FORMAT : uint
{
/// Do not use minutes or seconds.
TIME_NOMINUTESORSECONDS = 1,
/// Do not use seconds.
TIME_NOSECONDS = 2,
/// Do not use a time marker.
TIME_NOTIMEMARKER = 4,
/// Always use a 24-hour time format.
TIME_FORCE24HOURFORMAT = 8,
///
/// Windows Me/98, Windows 2000: System default Windows ANSI code page (ACP) instead of the locale code page used for string
/// translation. See Code Page Identifiers for a list of ANSI and other code pages.
///
LOCAL_USE_CP_ACP = 0x40000000,
///
/// No user override. In several functions, for example, GetLocaleInfo and GetLocaleInfoEx, this constant causes the function to
/// bypass any user override and use the system default value for any other constant specified in the function call. The
/// information is retrieved from the locale database, even if the identifier indicates the current locale and the user has
/// changed some of the values using the Control Panel, or if an application has changed these values by using SetLocaleInfo. If
/// this constant is not specified, any values that the user has configured from the Control Panel or that an application has
/// configured using SetLocaleInfo take precedence over the database settings for the current system default locale.
///
LOCALE_NOUSEROVERRIDE = 0x80000000
}
///
/// Formats a date as a date string for a locale specified by the locale identifier. The function formats either a specified date or
/// the local system date.
///
///
/// Locale identifier that specifies the locale this function formats the date string for. You can use the MAKELCID macro to
/// create a locale identifier or use one of the following predefined values.
///
/// Flags specifying date format options. For detailed definitions, see the dwFlags parameter of GetDateFormatEx.
///
/// Pointer to a SYSTEMTIME structure that contains the date information to format. The application sets this parameter to
/// NULL if the function is to use the current local system date.
///
///
///
/// Pointer to a format picture string that is used to form the date. Possible values for the format picture string are defined in
/// Day, Month, Year, and Era Format Pictures.
///
///
/// The function uses the specified locale only for information not specified in the format picture string, for example, the day and
/// month names for the locale. The application can set this parameter to NULL to format the string according to the date
/// format for the specified locale.
///
///
/// Pointer to a buffer in which this function retrieves the formatted date string.
///
/// Size, in characters, of the lpDateStr buffer. The application can set this parameter to 0 to return the buffer size required to
/// hold the formatted date string. In this case, the buffer indicated by lpDateStr is not used.
///
///
///
/// Returns the number of characters written to the lpDateStr buffer if successful. If the cchDate parameter is set to 0, the
/// function returns the number of characters required to hold the formatted date string, including the terminating null character.
///
///
/// The function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError,
/// which can return one of the following error codes:
///
///
// int GetDateFormat( _In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_ LPCTSTR lpFormat, _Out_opt_
// LPTSTR lpDateStr, _In_ int cchDate); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318086(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("Datetimeapi.h", MSDNShortId = "dd318086")]
public static extern int GetDateFormat(uint Locale, DATE_FORMAT dwFlags, in SYSTEMTIME lpDate, string lpFormat, StringBuilder lpDateStr, int cchDate);
///
/// Formats a date as a date string for a locale specified by name. The function formats either a specified date or the local system date.
///
/// Pointer to a locale name, or one of the following predefined values.
///
///
/// Flags specifying various function options that can be set if lpFormat is set to NULL. The application can specify a
/// combination of the following values and LOCALE_USE_CP_ACP or LOCALE_NOUSEROVERRIDE.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// DATE_AUTOLAYOUT
///
/// Windows 7 and later: Detect the need for right-to-left and left-to-right reading layout using the locale and calendar
/// information, and add marks accordingly. This value cannot be used with DATE_LTRREADING or DATE_RTLREADING. DATE_AUTOLAYOUT is
/// preferred over DATE_LTRREADING and DATE_RTLREADING because it uses the locales and calendars to determine the correct addition of marks.
///
///
/// -
/// DATE_LONGDATE
/// Use the long date format. This value cannot be used with DATE_MONTHDAY, DATE_SHORTDATE, or DATE_YEARMONTH.
///
/// -
/// DATE_LTRREADING
/// Add marks for left-to-right reading layout. This value cannot be used with DATE_RTLREADING.
///
/// -
/// DATE_RTLREADING
/// Add marks for right-to-left reading layout. This value cannot be used with DATE_LTRREADING
///
/// -
/// DATE_SHORTDATE
/// Use the short date format. This is the default. This value cannot be used with DATE_MONTHDAY, DATE_LONGDATE, or DATE_YEARMONTH.
///
/// -
/// DATE_USE_ALT_CALENDAR
///
/// Use the alternate calendar, if one exists, to format the date string. If this flag is set, the function uses the default format
/// for that alternate calendar, rather than using any user overrides. The user overrides will be used only in the event that there
/// is no default format for the specified alternate calendar.
///
///
/// -
/// DATE_YEARMONTH
/// Windows Vista: Use the year/month format. This value cannot be used with DATE_MONTHDAY, DATE_SHORTDATE, or DATE_LONGDATE.
///
/// -
/// DATE_MONTHDAY
///
/// Windows 10: Use the combination of month and day formats appropriate for the specified locale. This value cannot be used with
/// DATE_YEARMONTH, DATE_SHORTDATE, or DATE_LONGDATE.
///
///
///
///
///
/// If the application does not specify DATE_YEARMONTH, DATE_MONTHDAY, DATE_SHORTDATE, or DATE_LONGDATE, and lpFormat is set to
/// NULL, DATE_SHORTDATE is the default.
///
///
///
/// Pointer to a SYSTEMTIME structure that contains the date information to format. The application can set this parameter to
/// NULL if the function is to use the current local system date.
///
///
///
/// Pointer to a format picture string that is used to form the date. Possible values for the format picture string are defined in
/// Day, Month, Year, and Era Format Pictures.
///
/// For example, to get the date string "Wed, Aug 31 94", the application uses the picture string "ddd',' MMM dd yy".
///
/// The function uses the specified locale only for information not specified in the format picture string, for example, the day and
/// month names for the locale. The application can set this parameter to NULL to format the string according to the date
/// format for the specified locale.
///
///
/// Pointer to a buffer in which this function retrieves the formatted date string.
///
/// Size, in characters, of the lpDateStr buffer. The application can set this parameter to 0 to return the buffer size required to
/// hold the formatted date string. In this case, the buffer indicated by lpDateStr is not used.
///
/// Reserved; must set to NULL.
///
///
/// Returns the number of characters written to the lpDateStr buffer if successful. If the cchDate parameter is set to 0, the
/// function returns the number of characters required to hold the formatted date string, including the terminating null character.
///
///
/// This function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError,
/// which can return one of the following error codes:
///
///
// int GetDateFormatEx( _In_opt_ LPCWSTR lpLocaleName, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_ LPCWSTR
// lpFormat, _Out_opt_ LPWSTR lpDateStr, _In_ int cchDate, _In_opt_ LPCWSTR lpCalendar); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318088(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Datetimeapi.h", MSDNShortId = "dd318088")]
public static extern int GetDateFormatEx(string lpLocaleName, DATE_FORMAT dwFlags, in SYSTEMTIME lpDate, string lpFormat, StringBuilder lpDateStr, int cchDate, [Optional] string lpCalendar);
///
/// Formats time as a time string for a locale specified by identifier. The function formats either a specified time or the local
/// system time.
///
///
/// Locale identifier that specifies the locale. You can use the MAKELCID macro to create a locale identifier or use one of
/// the following predefined values.
///
/// Flags specifying time format options. For detailed definitions see the dwFlags parameter of GetTimeFormatEx.
///
/// Pointer to a SYSTEMTIME structure that contains the time information to format. The application can set this parameter to
/// NULL if the function is to use the current local system time.
///
///
/// Pointer to a format picture to use to format the time string. If the application sets this parameter to NULL, the function
/// formats the string according to the time format of the specified locale. If the application does not set the parameter to
/// NULL, the function uses the locale only for information not specified in the format picture string, for example, the
/// locale-specific time markers. For information about the format picture string, see the Remarks section.
///
/// Pointer to a buffer in which this function retrieves the formatted time string.
///
/// Size, in TCHAR values, for the time string buffer indicated by lpTimeStr. Alternatively, the application can set this parameter
/// to 0. In this case, the function returns the required size for the time string buffer, and does not use the lpTimeStr parameter.
///
///
///
/// Returns the number of TCHAR values retrieved in the buffer indicated by lpTimeStr. If the cchTime parameter is set to 0, the
/// function returns the size of the buffer required to hold the formatted time string, including a terminating null character.
///
///
/// This function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError,
/// which can return one of the following error codes:
///
///
// int GetTimeFormat( _In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpTime, _In_opt_ LPCTSTR lpFormat, _Out_opt_
// LPTSTR lpTimeStr, _In_ int cchTime); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318130(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("Datetimeapi.h", MSDNShortId = "dd318130")]
public static extern int GetTimeFormat(uint Locale, TIME_FORMAT dwFlags, in SYSTEMTIME lpTime, string lpFormat, StringBuilder lpTimeStr, int cchTime);
///
/// Formats time as a time string for a locale specified by name. The function formats either a specified time or the local system time.
///
/// Pointer to a locale name, or one of the following predefined values.
///
///
/// Flags specifying time format options. The application can specify a combination of the following values and LOCALE_USE_CP_ACP or LOCALE_NOUSEROVERRIDE.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// TIME_NOMINUTESORSECONDS
/// Do not use minutes or seconds.
///
/// -
/// TIME_NOSECONDS
/// Do not use seconds.
///
/// -
/// TIME_NOTIMEMARKER
/// Do not use a time marker.
///
/// -
/// TIME_FORCE24HOURFORMAT
/// Always use a 24-hour time format.
///
///
///
///
///
/// Pointer to a SYSTEMTIME structure that contains the time information to format. The application can set this parameter to
/// NULL if the function is to use the current local system time.
///
///
/// Pointer to a format picture to use to format the time string. If the application sets this parameter to NULL, the function
/// formats the string according to the time format of the specified locale. If the application does not set the parameter to
/// NULL, the function uses the locale only for information not specified in the format picture string, for example, the
/// locale-specific time markers. For information about the format picture string, see the Remarks section.
///
/// Pointer to a buffer in which this function retrieves the formatted time string.
///
/// Size, in characters, for the time string buffer indicated by lpTimeStr. Alternatively, the application can set this parameter to
/// 0. In this case, the function returns the required size for the time string buffer, and does not use the lpTimeStr parameter.
///
///
///
/// Returns the number of characters retrieved in the buffer indicated by lpTimeStr. If the cchTime parameter is set to 0, the
/// function returns the size of the buffer required to hold the formatted time string, including a terminating null character.
///
///
/// This function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError,
/// which can return one of the following error codes:
///
///
// int GetTimeFormatEx( _In_opt_ LPCWSTR lpLocaleName, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpTime, _In_opt_ LPCWSTR
// lpFormat, _Out_opt_ LPWSTR lpTimeStr, _In_ int cchTime); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318131(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Datetimeapi.h", MSDNShortId = "dd318131")]
public static extern int GetTimeFormatEx(string lpLocaleName, TIME_FORMAT dwFlags, in SYSTEMTIME lpTime, string lpFormat, StringBuilder lpTimeStr, int cchTime);
}
}