summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-04-28 18:39:17 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-04-28 18:39:17 +0300
commit175ed5d764b1c35e0d97f949e030382acea8527e (patch)
tree318a3edb92296a08761a3bd821475a32aecc1f2b
parenteb40a21481eaae317e7a8638ab51e8e624a7d817 (diff)
fixes #2365 (NewStory: date/times are displayed according to the OS locale settings)
-rw-r--r--include/m_timezones.h1
-rw-r--r--libs/win32/mir_core.libbin466504 -> 466724 bytes
-rw-r--r--libs/win64/mir_core.libbin471444 -> 471634 bytes
-rw-r--r--plugins/NewStory/src/templates.cpp89
-rw-r--r--plugins/NewStory/src/templates.h2
-rw-r--r--src/mir_core/src/mir_core.def1
-rw-r--r--src/mir_core/src/mir_core64.def1
-rw-r--r--src/mir_core/src/timezones.cpp24
8 files changed, 68 insertions, 50 deletions
diff --git a/include/m_timezones.h b/include/m_timezones.h
index 2a2cf06d48..1196b3b7c0 100644
--- a/include/m_timezones.h
+++ b/include/m_timezones.h
@@ -54,6 +54,7 @@ EXTERN_C MIR_CORE_DLL(int) TimeZone_PrepareList(MCONTACT hContact, LPCSTR szModu
EXTERN_C MIR_CORE_DLL(int) TimeZone_SelectListItem(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags);
EXTERN_C MIR_CORE_DLL(int) TimeZone_GetTimeZoneTime(HANDLE hTZ, SYSTEMTIME *st);
+EXTERN_C MIR_CORE_DLL(int) TimeZone_GetSystemTime(HANDLE hTZ, mir_time src, SYSTEMTIME *dest, DWORD dwFlags);
EXTERN_C MIR_CORE_DLL(mir_time) TimeZone_UtcToLocal(HANDLE hTZ, mir_time ts);
EXTERN_C MIR_CORE_DLL(LPTIME_ZONE_INFORMATION) TimeZone_GetInfo(HANDLE hTZ);
diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib
index bb12c1ed93..87139eb570 100644
--- a/libs/win32/mir_core.lib
+++ b/libs/win32/mir_core.lib
Binary files differ
diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib
index 9cca412287..431a9e1c01 100644
--- a/libs/win64/mir_core.lib
+++ b/libs/win64/mir_core.lib
Binary files differ
diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp
index 7ccf117a7f..dce4f4c10c 100644
--- a/plugins/NewStory/src/templates.cpp
+++ b/plugins/NewStory/src/templates.cpp
@@ -189,48 +189,53 @@ void vfEvent(int, TemplateVars *vars, MCONTACT, ItemData *item)
vars->SetVar('D', L">>", false);
// %t: timestamp
- _tcsftime(buf, _countof(buf), L"%d.%m.%Y, %H:%M", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('t', buf, true);
-
- // %h: hour (24 hour format, 0-23)
- _tcsftime(buf, _countof(buf), L"%H", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('h', buf, true);
-
- // %a: hour (12 hour format)
- _tcsftime(buf, _countof(buf), L"%h", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('a', buf, true);
-
- // %m: minute
- _tcsftime(buf, _countof(buf), L"%M", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('m', buf, true);
-
- // %s: second
- _tcsftime(buf, _countof(buf), L"%S", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('s', buf, true);
-
- // %o: month
- _tcsftime(buf, _countof(buf), L"%m", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('o', buf, true);
-
- // %d: day of month
- _tcsftime(buf, _countof(buf), L"%d", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('d', buf, true);
-
- // %y: year
- _tcsftime(buf, _countof(buf), L"%Y", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('y', buf, true);
-
- // %w: day of week (Sunday, Monday... translatable)
- _tcsftime(buf, _countof(buf), L"%A", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('w', TranslateW(buf), false);
-
- // %p: AM/PM symbol
- _tcsftime(buf, _countof(buf), L"%p", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('p', buf, true);
-
- // %O: Name of month, translatable
- _tcsftime(buf, _countof(buf), L"%B", _localtime32((__time32_t *)&item->dbe.timestamp));
- vars->SetVar('O', TranslateW(buf), false);
+ SYSTEMTIME st;
+ if (!TimeZone_GetSystemTime(nullptr, item->dbe.timestamp, &st, 0)) {
+ CMStringW tmp;
+ GetDateFormatW(LOCALE_USER_DEFAULT, 0, &st, L"dd.MM.yyyy, ", buf, _countof(buf)); tmp += buf;
+ GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, L"HH:mm", buf, _countof(buf)); tmp += buf;
+ vars->SetVar('t', tmp, true);
+
+ // %h: hour (24 hour format, 0-23)
+ GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, L"HH", buf, _countof(buf));
+ vars->SetVar('h', buf, true);
+
+ // %a: hour (12 hour format)
+ GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, L"hh", buf, _countof(buf));
+ vars->SetVar('a', buf, true);
+
+ // %m: minute
+ GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, L"mm", buf, _countof(buf));
+ vars->SetVar('m', buf, true);
+
+ // %s: second
+ GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, L"ss", buf, _countof(buf));
+ vars->SetVar('s', buf, true);
+
+ // %o: month
+ GetDateFormatW(LOCALE_USER_DEFAULT, 0, &st, L"MM", buf, _countof(buf));
+ vars->SetVar('o', buf, true);
+
+ // %d: day of month
+ GetDateFormatW(LOCALE_USER_DEFAULT, 0, &st, L"dd", buf, _countof(buf));
+ vars->SetVar('d', buf, true);
+
+ // %y: year
+ GetDateFormatW(LOCALE_USER_DEFAULT, 0, &st, L"yyyy", buf, _countof(buf));
+ vars->SetVar('y', buf, true);
+
+ // %w: day of week (Sunday, Monday... translatable)
+ GetDateFormatW(LOCALE_USER_DEFAULT, 0, &st, L"dddd", buf, _countof(buf));
+ vars->SetVar('w', TranslateW(buf), false);
+
+ // %p: AM/PM symbol
+ GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, L"tt", buf, _countof(buf));
+ vars->SetVar('p', buf, true);
+
+ // %O: Name of month, translatable
+ GetDateFormatW(LOCALE_USER_DEFAULT, 0, &st, L"MMMM", buf, _countof(buf));
+ vars->SetVar('O', TranslateW(buf), false);
+ }
}
void vfMessage(int, TemplateVars *vars, MCONTACT, ItemData *item)
diff --git a/plugins/NewStory/src/templates.h b/plugins/NewStory/src/templates.h
index 69491a4a3c..931773ce78 100644
--- a/plugins/NewStory/src/templates.h
+++ b/plugins/NewStory/src/templates.h
@@ -16,7 +16,7 @@ struct TemplateVars
return val[id];
}
- __forceinline void SetVar(uint8_t id, wchar_t *v, bool d) {
+ __forceinline void SetVar(uint8_t id, const wchar_t *v, bool d) {
if (val[id] && del[id])
mir_free(val[id]);
val[id] = mir_wstrdup(v);
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def
index 6927452795..7b5c2f8b23 100644
--- a/src/mir_core/src/mir_core.def
+++ b/src/mir_core/src/mir_core.def
@@ -1465,3 +1465,4 @@ XmlGetChildText @1645
?EventsRev@DB@@YGPAVEventCursorBase@1@IAAUDBEVENTINFO@@@Z @1689 NONAME
?begin@EventCursorBase@DB@@QAEIXZ @1690 NONAME
?end@EventCursorBase@DB@@QAEIXZ @1691 NONAME
+TimeZone_GetSystemTime @1692
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def
index adaccb1163..c66e248673 100644
--- a/src/mir_core/src/mir_core64.def
+++ b/src/mir_core/src/mir_core64.def
@@ -1465,3 +1465,4 @@ XmlGetChildText @1645
?EventsRev@DB@@YAPEAVEventCursorBase@1@IAEAUDBEVENTINFO@@@Z @1689 NONAME
?begin@EventCursorBase@DB@@QEAAIXZ @1690 NONAME
?end@EventCursorBase@DB@@QEAAIXZ @1691 NONAME
+TimeZone_GetSystemTime @1692
diff --git a/src/mir_core/src/timezones.cpp b/src/mir_core/src/timezones.cpp
index 54a46ee82e..c5008caa77 100644
--- a/src/mir_core/src/timezones.cpp
+++ b/src/mir_core/src/timezones.cpp
@@ -317,15 +317,20 @@ MIR_CORE_DLL(int) TimeZone_PrintDateTime(HANDLE hTZ, LPCTSTR szFormat, LPTSTR sz
return 0;
}
-MIR_CORE_DLL(int) TimeZone_PrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, size_t cbDest, DWORD dwFlags)
+MIR_CORE_DLL(int) TimeZone_GetSystemTime(HANDLE hTZ, mir_time ts, SYSTEMTIME *dest, DWORD dwFlags)
{
- MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ;
- if (tz == nullptr && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)))
+ if (dest == nullptr)
+ return 2;
+
+ MIM_TIMEZONE *tz = (MIM_TIMEZONE *)hTZ;
+ if (tz == nullptr && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) {
+ memset(dest, 0, sizeof(SYSTEMTIME));
return 1;
+ }
if (tz == nullptr)
tz = &myInfo.myTZ;
-
+
FILETIME ft;
if (tz == UTC_TIME_HANDLE)
UnixTimeToFileTime(ts, &ft);
@@ -336,10 +341,15 @@ MIR_CORE_DLL(int) TimeZone_PrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFor
UnixTimeToFileTime(ts + tz->offset, &ft);
}
- SYSTEMTIME st;
- FileTimeToSystemTime(&ft, &st);
+ FileTimeToSystemTime(&ft, dest);
+ return 0;
+}
- FormatTime(&st, szFormat, szDest, cbDest);
+MIR_CORE_DLL(int) TimeZone_PrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, size_t cbDest, DWORD dwFlags)
+{
+ SYSTEMTIME st;
+ if (!TimeZone_GetSystemTime(hTZ, ts, &st, dwFlags))
+ FormatTime(&st, szFormat, szDest, cbDest);
return 0;
}