microsoft / AdaptiveCards

A new way for developers to exchange card content in a common and consistent way.
https://adaptivecards.io
MIT License
1.75k stars 550 forks source link

[Rendering] [UWP] DateInputRenderer - Time calculation bug #6900

Open beervoley opened 2 years ago

beervoley commented 2 years ago

Target Platforms

UWP

SDK Version

3.0.2

Application Name

N/A

Problem Description

AdaptiveDateInputRenderer has a capability to parse date in various format from the string parameter. This parameter can include time of the day besides year, month and day. Function GetDateTime that's being used to convert that time to local time is not taking into account the tiem of day when converting. It can result in incorrect time calculation if the timezone is ahead of UTC by certain amount (need to investigate).

winrt::DateTime GetDateTime(unsigned int year, unsigned int month, unsigned int day)
{
    // TODO: investigate the midnight bug. If the timezone will be ahead of UTC we can do -1 day when converting
    SYSTEMTIME systemTime = {(WORD)year, (WORD)month, 0, (WORD)day};

    // Convert to UTC
    TIME_ZONE_INFORMATION timeZone;
    GetTimeZoneInformation(&timeZone);
    TzSpecificLocalTimeToSystemTime(&timeZone, &systemTime, &systemTime);

    // Convert to ticks
    FILETIME fileTime;
    SystemTimeToFileTime(&systemTime, &fileTime);

    return winrt::clock::from_FILETIME({fileTime});
}

Screenshots

No response

Card JSON

N/A

Sample Code Language

No response

Sample Code

No response

beervoley commented 2 years ago

@paulcam206 FYI