feat: Add FromDateTimeOffset in TimestampTag (#2146)
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Discord
|
||||
/// <summary>
|
||||
/// Gets or sets the time for this timestamp tag.
|
||||
/// </summary>
|
||||
public DateTime Time { get; set; }
|
||||
public DateTimeOffset Time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Converts the current timestamp tag to the string representation supported by discord.
|
||||
@@ -26,11 +26,11 @@ namespace Discord
|
||||
/// <returns>A string that is compatible in a discord message, ex: <code><t:1625944201:f></code></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"<t:{((DateTimeOffset)Time).ToUnixTimeSeconds()}:{(char)Style}>";
|
||||
return $"<t:{Time.ToUnixTimeSeconds()}:{(char)Style}>";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new timestamp tag with the specified datetime object.
|
||||
/// Creates a new timestamp tag with the specified <see cref="DateTime"/> object.
|
||||
/// </summary>
|
||||
/// <param name="time">The time of this timestamp tag.</param>
|
||||
/// <param name="style">The style for this timestamp tag.</param>
|
||||
@@ -43,5 +43,20 @@ namespace Discord
|
||||
Time = time
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new timestamp tag with the specified <see cref="DateTimeOffset"/> object.
|
||||
/// </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 tag.</returns>
|
||||
public static TimestampTag FromDateTimeOffset(DateTimeOffset time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime)
|
||||
{
|
||||
return new TimestampTag
|
||||
{
|
||||
Style = style,
|
||||
Time = time
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user