Skip to content

Commit

Permalink
Fix DateTimeOffset invalid values.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloupe committed Oct 10, 2023
1 parent 898a406 commit 57bb003
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions Slackord/Classes/Reconstruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ private static void ReconstructMessage(DeconstructedMessage deconstructedMessage
_ = Application.Current.Dispatcher.Dispatch(() => { ApplicationWindow.WriteToDebugWindow($"Invalid timestamp format: {currentValue}\n"); });
return;
}
long timestampMilliseconds = (long)(timestampDouble * 1000);
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(timestampMilliseconds);

double timestampSeconds = timestampDouble;
long timestampMilliseconds = (long)(timestampSeconds * 1000);
long timestampFractionalMilliseconds = (long)((timestampSeconds % 1) * 1000000);
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(timestampMilliseconds).AddTicks(timestampFractionalMilliseconds);

DateTimeFormatInfo dtfi = CultureInfo.CurrentCulture.DateTimeFormat;
string customFormat = $"{dtfi.ShortDatePattern} {dtfi.LongTimePattern}";
string timestamp = dateTimeOffset.ToString(customFormat);
Expand All @@ -93,20 +97,16 @@ private static void ReconstructMessage(DeconstructedMessage deconstructedMessage

if (deconstructedMessage.User != null && UsersDict.TryGetValue(deconstructedMessage.User, out DeconstructedUser user))
{
// Set the userName to the user's DisplayName, Name, RealName, or Id, in order of fallback.
userName = !string.IsNullOrEmpty(user.Profile.DisplayName) ? user.Profile.DisplayName :
!string.IsNullOrEmpty(user.Name) ? user.Name :
!string.IsNullOrEmpty(user.Profile.RealName) ? user.Profile.RealName :
user.Id;
// Set the userAvatar to the user's Avatar of Image192, then format the message with the timestamp and message content.
userAvatar = user.Profile.Avatar;
formattedMessage = $"[{timestamp}] : {messageContent}";
}
else
{
// We couldn't find a user here, so set it to "Unknown User". This doesn't happen often, but it can happen.
_ = Application.Current.Dispatcher.Dispatch(() => { ApplicationWindow.WriteToDebugWindow($"User not found for message: {timestamp} {deconstructedMessage.Text}\nSetting to \"Unknown User\"...\n"); });
userName = "Unknown User";
_ = Application.Current.Dispatcher.Dispatch(() => { ApplicationWindow.WriteToDebugWindow($"User not found: {deconstructedMessage.User}\n"); });
}

if (!string.IsNullOrEmpty(formattedMessage))
Expand Down Expand Up @@ -135,7 +135,6 @@ private static void ReconstructMessage(DeconstructedMessage deconstructedMessage
}
}


private static string ConvertToDiscordMarkdown(string input)
{
try
Expand Down
2 changes: 1 addition & 1 deletion Slackord/Classes/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ internal class Version
{
public static string GetVersion()
{
string version = "v4.1.1";
string version = "v4.1.2";

return version;
}
Expand Down

0 comments on commit 57bb003

Please sign in to comment.