From bc89d3c4854be63c90899904a6e5dd14245d6659 Mon Sep 17 00:00:00 2001
From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com>
Date: Thu, 15 Sep 2022 06:59:21 +0200
Subject: [PATCH] Fix TimestampTag being sadge (#2468)
* Im so sad
* Im so sad v2
* oopsie uwu
---
.../Entities/Messages/TimestampTag.cs | 79 +++++++++++++------
1 file changed, 54 insertions(+), 25 deletions(-)
diff --git a/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs b/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs
index 3beffdbb6..1ca6dc41c 100644
--- a/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs
+++ b/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs
@@ -5,17 +5,28 @@ namespace Discord
///
/// Represents a class used to make timestamps in messages. see .
///
- public class TimestampTag
+ public readonly struct TimestampTag
{
///
- /// Gets or sets the style of the timestamp tag.
+ /// Gets the time for this timestamp tag.
///
- public TimestampTagStyles Style { get; set; } = TimestampTagStyles.ShortDateTime;
+ public DateTimeOffset Time { get; }
///
- /// Gets or sets the time for this timestamp tag.
+ /// Gets the style of this tag. if none was provided.
///
- public DateTimeOffset Time { get; set; }
+ public TimestampTagStyles? Style { get; }
+
+ ///
+ /// Creates a new from the provided time.
+ ///
+ /// The time for this timestamp tag.
+ /// The style for this timestamp tag.
+ public TimestampTag(DateTimeOffset time, TimestampTagStyles? style = null)
+ {
+ Time = time;
+ Style = style;
+ }
///
/// Converts the current timestamp tag to the string representation supported by discord.
@@ -23,11 +34,23 @@ namespace Discord
/// If the is null then the default 0 will be used.
///
///
+ ///
+ /// Will use the provided if provided. If this value is null, it will default to .
+ ///
/// A string that is compatible in a discord message, ex: <t:1625944201:f>
public override string ToString()
- {
- return $"";
- }
+ => ToString(Style ?? TimestampTagStyles.ShortDateTime);
+
+ ///
+ /// Converts the current timestamp tag to the string representation supported by discord.
+ ///
+ /// If the is null then the default 0 will be used.
+ ///
+ ///
+ /// The formatting style for this tag.
+ /// A string that is compatible in a discord message, ex: <t:1625944201:f>
+ public string ToString(TimestampTagStyles style)
+ => $"";
///
/// Creates a new timestamp tag with the specified object.
@@ -35,14 +58,8 @@ namespace Discord
/// The time of this timestamp tag.
/// The style for this timestamp tag.
/// The newly create timestamp tag.
- public static TimestampTag FromDateTime(DateTime time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime)
- {
- return new TimestampTag
- {
- Style = style,
- Time = time
- };
- }
+ public static TimestampTag FromDateTime(DateTime time, TimestampTagStyles? style = null)
+ => new(time, style);
///
/// Creates a new timestamp tag with the specified object.
@@ -50,13 +67,25 @@ namespace Discord
/// The time of this timestamp tag.
/// The style for this timestamp tag.
/// The newly create timestamp tag.
- public static TimestampTag FromDateTimeOffset(DateTimeOffset time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime)
- {
- return new TimestampTag
- {
- Style = style,
- Time = time
- };
- }
+ public static TimestampTag FromDateTimeOffset(DateTimeOffset time, TimestampTagStyles? style = null)
+ => new(time, style);
+
+ ///
+ /// Immediately formats the provided time and style into a timestamp string.
+ ///
+ /// The time of this timestamp tag.
+ /// The style for this timestamp tag.
+ /// The newly create timestamp string.
+ public static string FormatFromDateTime(DateTime time, TimestampTagStyles style)
+ => FormatFromDateTimeOffset(time, style);
+
+ ///
+ /// Immediately formats the provided time and style into a timestamp string.
+ ///
+ /// The time of this timestamp tag.
+ /// The style for this timestamp tag.
+ /// The newly create timestamp string.
+ public static string FormatFromDateTimeOffset(DateTimeOffset time, TimestampTagStyles style)
+ => $"";
}
-}
\ No newline at end of file
+}