2021-01-30 00:07:43 +00:00
|
|
|
using Myriad.Types;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace Myriad.Extensions;
|
|
|
|
|
|
|
|
public static class SnowflakeExtensions
|
2021-01-30 00:07:43 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
public static readonly DateTimeOffset DiscordEpoch = new(2015, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public static DateTimeOffset SnowflakeToTimestamp(ulong snowflake) =>
|
|
|
|
DiscordEpoch + TimeSpan.FromMilliseconds(snowflake >> 22);
|
2021-01-30 00:07:43 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public static DateTimeOffset Timestamp(this Message msg) => SnowflakeToTimestamp(msg.Id);
|
|
|
|
public static DateTimeOffset Timestamp(this Channel channel) => SnowflakeToTimestamp(channel.Id);
|
|
|
|
public static DateTimeOffset Timestamp(this Guild guild) => SnowflakeToTimestamp(guild.Id);
|
|
|
|
public static DateTimeOffset Timestamp(this Webhook webhook) => SnowflakeToTimestamp(webhook.Id);
|
|
|
|
public static DateTimeOffset Timestamp(this User user) => SnowflakeToTimestamp(user.Id);
|
2021-01-30 00:07:43 +00:00
|
|
|
}
|