mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-28 05:34:12 -04:00
parent
b2ac5d8b45
commit
b2a22ab2a9
1 changed files with 21 additions and 4 deletions
|
@ -340,13 +340,25 @@ internal static partial class MarkdownParser
|
|||
)
|
||||
);
|
||||
|
||||
// https://discord.com/developers/docs/reference#message-formatting-timestamp-styles
|
||||
var format = m.Groups[2].Value.NullIfWhiteSpace() switch
|
||||
{
|
||||
// Ignore the 'relative' format because it doesn't make sense in a static export
|
||||
// Known formats
|
||||
"t" => "t",
|
||||
"T" => "T",
|
||||
"d" => "d",
|
||||
"D" => "D",
|
||||
"f" => "f",
|
||||
"F" => "F",
|
||||
// Relative format: ignore because it doesn't make sense in a static export
|
||||
"r" => null,
|
||||
"R" => null,
|
||||
// Discord's date formats are (mostly) compatible with .NET's date formats
|
||||
var f => f
|
||||
// Unknown format: throw an exception to consider this timestamp invalid
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/1156
|
||||
var f
|
||||
=> throw new InvalidOperationException(
|
||||
$"Unknown timestamp format '{f}'."
|
||||
)
|
||||
};
|
||||
|
||||
return new TimestampNode(instant, format);
|
||||
|
@ -354,7 +366,12 @@ internal static partial class MarkdownParser
|
|||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/681
|
||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/766
|
||||
catch (Exception ex)
|
||||
when (ex is FormatException or ArgumentOutOfRangeException or OverflowException)
|
||||
when (ex
|
||||
is FormatException
|
||||
or ArgumentOutOfRangeException
|
||||
or OverflowException
|
||||
or InvalidOperationException
|
||||
)
|
||||
{
|
||||
// For invalid timestamps, Discord renders "Invalid Date" instead of ignoring the markdown
|
||||
return TimestampNode.Invalid;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue