Skip to content

Fix issues with timestamp in AppNotificationBuilder #2814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
71a2da7
FI develop into WNP_ContentBuilder_Prev1 (#2656)
loneursid Jun 23, 2022
9be0803
User/erlangl/fi develop into feature (#2660)
loneursid Jun 24, 2022
4355c4e
Merge branch 'develop' of https://github.com/microsoft/WindowsAppSDK …
kythant Jun 28, 2022
6149efb
FI develop into Content Builder feature branch (#2717)
loneursid Jul 12, 2022
d394165
FI develop into notification feature branch (#2733)
loneursid Jul 25, 2022
eca07a6
Merge branch 'develop' of https://github.com/microsoft/WindowsAppSDK …
kythant Jul 26, 2022
ad6a94c
AppNotificationBuilder features (#2786)
pmpurifoy Jul 29, 2022
2fd4a1f
Merge branch 'develop' into feature/WNP_ContentBuilder_Prev1
kythant Jul 29, 2022
a103cab
AppNotificationContent Builder 1.2 spec (#2648)
pmpurifoy Jul 30, 2022
7348ed6
Merge branch 'develop' into feature/WNP_ContentBuilder_Prev1
kythant Aug 1, 2022
6cb166b
AppNotificationBuilder - Code Improvements (#2801)
loneursid Aug 2, 2022
5c91499
AppNotificationContent Builder Core Features - part II (#2760)
loneursid Aug 3, 2022
3d9830d
Merge branch 'develop' into feature/WNP_ContentBuilder_Prev1
kythant Aug 3, 2022
0c06ed2
Fixed timestamp parsing
pmpurifoy Aug 3, 2022
5e4961a
AppNotificationBuilder - ProgressBar (#2780)
loneursid Aug 4, 2022
657803e
Address nits
pmpurifoy Aug 4, 2022
ffb4620
Fix build break in user/purifoypaul/TimestampFix (#2815)
loneursid Aug 4, 2022
43507fc
Merge branch 'feature/WNP_ContentBuilder_Prev1' into user/purifoypaul…
pmpurifoy Aug 4, 2022
7410c86
Encoding/Decoding AppNotificationBuilder arguments (#2805)
pmpurifoy Aug 4, 2022
15e01ab
Merge branch 'feature/WNP_ContentBuilder_Prev1' into user/purifoypaul…
pmpurifoy Aug 4, 2022
0dbd98e
Merge branch 'develop' into user/purifoypaul/TimestampFix
Aug 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation
winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationBuilder AppNotificationBuilder::SetTimeStamp(winrt::Windows::Foundation::DateTime const& value)
{
auto seconds{ winrt::clock::to_time_t(value) };
struct tm buf{};
gmtime_s(&buf, &seconds);
struct tm buf {};
localtime_s(&buf, &seconds);

std::wstringstream buffer;
buffer << std::put_time(&buf, L"%FT%T");
buffer << std::put_time(&buf, L"%FT%T%z");

std::wstring timestamp{ buffer.str() };
timestamp.insert(timestamp.size() - c_offsetIndexValue, L":");
m_timeStamp = wil::str_printf<std::wstring>(L" displayTimestamp='%ls'", timestamp.c_str());

m_timeStamp = wil::str_printf<std::wstring>(L" displayTimestamp='%lsZ'", buffer.str().c_str());
return *this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ constexpr uint8_t c_maxButtonElements{ 5 };
constexpr size_t c_maxEncodingSize{ 3 };
constexpr uint8_t c_maxTextInputElements{ 5 };
constexpr uint8_t c_maxSelectionElements{ 5 };
constexpr uint8_t c_offsetIndexValue{ 2 };

namespace AppNotificationBuilder
{
Expand Down
17 changes: 10 additions & 7 deletions test/AppNotificationBuilderTests/APITests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ namespace Test::AppNotification::Builder

TEST_METHOD(AppNotificationBuilderSetTimeStamp)
{
std::wstring dateTimeFormat{ L"%d/%m/%Y %H:%M:%S" };
std::wistringstream ss(L"22/12/2016 01:12:10");
auto time{ winrt::Windows::Foundation::DateTime::clock::now() };
auto builder{ winrt::AppNotificationBuilder().SetTimeStamp(time) };

struct tm dateTime {};
ss >> std::get_time(&dateTime, dateTimeFormat.c_str());
std::time_t time{ mktime(&dateTime) };
auto timeStamp{ winrt::clock::from_time_t(time) };
auto timeAsTimeT{ winrt::clock::to_time_t(time) };
localtime_s(&dateTime, &timeAsTimeT);

auto builder{ winrt::AppNotificationBuilder().SetTimeStamp(timeStamp) };
auto expected{ L"<toast displayTimestamp='2016-12-22T09:12:10Z'><visual><binding template='ToastGeneric'></binding></visual></toast>" };
std::wstringstream buffer;
buffer << std::put_time(&dateTime, L"%FT%T%z");

std::wstring expectedTimestamp{ buffer.str() };
expectedTimestamp.insert(expectedTimestamp.size() - c_offsetIndexValue, L":");
std::wstring expected{ wil::str_printf<std::wstring>(L"<toast displayTimestamp='%ls'><visual><binding template='ToastGeneric'></binding></visual></toast>", expectedTimestamp.c_str()) };

VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected);
}
Expand Down
7 changes: 5 additions & 2 deletions test/AppNotificationBuilderTests/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
#include <sddl.h>
#include <appmodel.h>

#include <vector>
#include <string>
#include <algorithm>
#include <wil/resource.h>
#include <wil/stl.h>
#include <wil/result.h>
#include <wil/cppwinrt.h>
#include <wil/token_helpers.h>
#include <wil/resource.h>
#include <wrl.h>
#include <WexTestClass.h>

#include <string>
#include <sstream>
#include <iomanip>

Expand Down