Fix TimestampTag being sadge (#2468)
* Im so sad * Im so sad v2 * oopsie uwu
This commit is contained in:
@@ -5,17 +5,28 @@ namespace Discord
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a class used to make timestamps in messages. see <see href="https://discord.com/developers/docs/reference#message-formatting-timestamp-styles"/>.
|
/// Represents a class used to make timestamps in messages. see <see href="https://discord.com/developers/docs/reference#message-formatting-timestamp-styles"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TimestampTag
|
public readonly struct TimestampTag
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the style of the timestamp tag.
|
/// Gets the time for this timestamp tag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TimestampTagStyles Style { get; set; } = TimestampTagStyles.ShortDateTime;
|
public DateTimeOffset Time { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the time for this timestamp tag.
|
/// Gets the style of this tag. <see langword="null"/> if none was provided.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTimeOffset Time { get; set; }
|
public TimestampTagStyles? Style { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="TimestampTag"/> from the provided time.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">The time for this timestamp tag.</param>
|
||||||
|
/// <param name="style">The style for this timestamp tag.</param>
|
||||||
|
public TimestampTag(DateTimeOffset time, TimestampTagStyles? style = null)
|
||||||
|
{
|
||||||
|
Time = time;
|
||||||
|
Style = style;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts the current timestamp tag to the string representation supported by discord.
|
/// Converts the current timestamp tag to the string representation supported by discord.
|
||||||
@@ -23,11 +34,23 @@ namespace Discord
|
|||||||
/// If the <see cref="Time"/> is null then the default 0 will be used.
|
/// If the <see cref="Time"/> is null then the default 0 will be used.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will use the provided <see cref="Style"/> if provided. If this value is null, it will default to <see cref="TimestampTagStyles.ShortDateTime"/>.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>A string that is compatible in a discord message, ex: <code><t:1625944201:f></code></returns>
|
/// <returns>A string that is compatible in a discord message, ex: <code><t:1625944201:f></code></returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
=> ToString(Style ?? TimestampTagStyles.ShortDateTime);
|
||||||
return $"<t:{Time.ToUnixTimeSeconds()}:{(char)Style}>";
|
|
||||||
}
|
/// <summary>
|
||||||
|
/// Converts the current timestamp tag to the string representation supported by discord.
|
||||||
|
/// <para>
|
||||||
|
/// If the <see cref="Time"/> is null then the default 0 will be used.
|
||||||
|
/// </para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="style">The formatting style for this tag.</param>
|
||||||
|
/// <returns>A string that is compatible in a discord message, ex: <code><t:1625944201:f></code></returns>
|
||||||
|
public string ToString(TimestampTagStyles style)
|
||||||
|
=> $"<t:{Time.ToUnixTimeSeconds()}:{(char)style}>";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new timestamp tag with the specified <see cref="DateTime"/> object.
|
/// Creates a new timestamp tag with the specified <see cref="DateTime"/> object.
|
||||||
@@ -35,14 +58,8 @@ namespace Discord
|
|||||||
/// <param name="time">The time of this timestamp tag.</param>
|
/// <param name="time">The time of this timestamp tag.</param>
|
||||||
/// <param name="style">The style for this timestamp tag.</param>
|
/// <param name="style">The style for this timestamp tag.</param>
|
||||||
/// <returns>The newly create timestamp tag.</returns>
|
/// <returns>The newly create timestamp tag.</returns>
|
||||||
public static TimestampTag FromDateTime(DateTime time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime)
|
public static TimestampTag FromDateTime(DateTime time, TimestampTagStyles? style = null)
|
||||||
{
|
=> new(time, style);
|
||||||
return new TimestampTag
|
|
||||||
{
|
|
||||||
Style = style,
|
|
||||||
Time = time
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new timestamp tag with the specified <see cref="DateTimeOffset"/> object.
|
/// Creates a new timestamp tag with the specified <see cref="DateTimeOffset"/> object.
|
||||||
@@ -50,13 +67,25 @@ namespace Discord
|
|||||||
/// <param name="time">The time of this timestamp tag.</param>
|
/// <param name="time">The time of this timestamp tag.</param>
|
||||||
/// <param name="style">The style for this timestamp tag.</param>
|
/// <param name="style">The style for this timestamp tag.</param>
|
||||||
/// <returns>The newly create timestamp tag.</returns>
|
/// <returns>The newly create timestamp tag.</returns>
|
||||||
public static TimestampTag FromDateTimeOffset(DateTimeOffset time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime)
|
public static TimestampTag FromDateTimeOffset(DateTimeOffset time, TimestampTagStyles? style = null)
|
||||||
{
|
=> new(time, style);
|
||||||
return new TimestampTag
|
|
||||||
{
|
/// <summary>
|
||||||
Style = style,
|
/// Immediately formats the provided time and style into a timestamp string.
|
||||||
Time = time
|
/// </summary>
|
||||||
};
|
/// <param name="time">The time of this timestamp tag.</param>
|
||||||
}
|
/// <param name="style">The style for this timestamp tag.</param>
|
||||||
|
/// <returns>The newly create timestamp string.</returns>
|
||||||
|
public static string FormatFromDateTime(DateTime time, TimestampTagStyles style)
|
||||||
|
=> FormatFromDateTimeOffset(time, style);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Immediately formats the provided time and style into a timestamp string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">The time of this timestamp tag.</param>
|
||||||
|
/// <param name="style">The style for this timestamp tag.</param>
|
||||||
|
/// <returns>The newly create timestamp string.</returns>
|
||||||
|
public static string FormatFromDateTimeOffset(DateTimeOffset time, TimestampTagStyles style)
|
||||||
|
=> $"<t:{time.ToUnixTimeSeconds()}:{(char)style}>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user