Browse Source

feat: Add FromDateTimeOffset in TimestampTag (#2146)

tags/3.4.0
sabihoshi GitHub 3 years ago
parent
commit
553055b724
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 4 deletions
  1. +19
    -4
      src/Discord.Net.Core/Entities/Messages/TimestampTag.cs

+ 19
- 4
src/Discord.Net.Core/Entities/Messages/TimestampTag.cs View File

@@ -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>&lt;t:1625944201:f&gt;</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
};
}
}
}
}

Loading…
Cancel
Save