Skip to content

Commit 2da56fe

Browse files
patch(snowflake): update discord epoch to be static property
1 parent 1ea990f commit 2da56fe

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Sources/DiscordKitCore/Extensions/Snowflake+decode.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
import Foundation
99

10-
let DISCORD_EPOCH = 1420070400000
11-
1210
public extension Snowflake {
11+
static let DISCORD_EPOCH = 1420070400000
12+
1313
/// Decodes this Snowflake into a Date
1414
func decodeToDate() -> Date? {
1515
guard let intSnowflake = Int(self) else { return nil }
16-
let millisTimestamp = (intSnowflake >> 22) + DISCORD_EPOCH
16+
let millisTimestamp = (intSnowflake >> 22) + Self.DISCORD_EPOCH
1717
return Date(timeIntervalSince1970: Double(millisTimestamp) / 1000.0)
1818
}
1919
}

Sources/DiscordKitCore/Objects/Data/Snowflake.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public typealias Snowflake = String
1111

1212
extension Snowflake {
1313
init(timestamp: Date = .init()) {
14-
let epoch = Int(timestamp.timeIntervalSince1970*1000) - DISCORD_EPOCH
14+
let epoch = Int(timestamp.timeIntervalSince1970*1000) - Self.DISCORD_EPOCH
1515
self.init(epoch << 22)
1616
}
1717
}

0 commit comments

Comments
 (0)