Skip to content

Commit

Permalink
move implementation to a new file
Browse files Browse the repository at this point in the history
  • Loading branch information
davedelong committed Feb 11, 2024
1 parent ced2022 commit 32b1234
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
8 changes: 8 additions & 0 deletions Sources/Time/2-Core Calendar/Region.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import Foundation
/// - a `Locale` value, which describes their preferences around formatting values
public struct Region: Hashable, Sendable {

public static func ==(lhs: Self, rhs: Self) -> Bool {
guard lhs.locale.identifier == rhs.locale.identifier else { return false }
guard lhs.timeZone.identifier == rhs.timeZone.identifier else { return false }
guard lhs.calendar.identifier == rhs.calendar.identifier else { return false }

return true
}

/// A snapshot of the user's current `Region`.
public static let current = Region(calendar: .current, timeZone: .current, locale: .current)

Expand Down
33 changes: 33 additions & 0 deletions Sources/Time/4-Fixed Values/Fixed+Equatable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// File.swift
//
//
// Created by Dave DeLong on 2/4/24.
//

import Foundation

extension Fixed: Equatable {

/// Determine if two `Fixed` values are equal.
///
/// Two `Fixed` values are equal if they have the same `Region` and represent the same calendrical components.
/// - Parameter lhs: a `Fixed` value
/// - Parameter rhs: a `Fixed` value
public static func ==(lhs: Self, rhs: Self) -> Bool {
return lhs.region == rhs.region && lhs.dateComponents == rhs.dateComponents
}

}

extension Fixed: Hashable {

/// Compute the hash of an`Fixed` value
///
/// - Parameter hasher: a `Hasher`
public func hash(into hasher: inout Hasher) {
hasher.combine(region)
hasher.combine(dateComponents)
}

}
25 changes: 0 additions & 25 deletions Sources/Time/4-Fixed Values/Fixed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,31 +135,6 @@ public struct Fixed<Smallest: Unit & LTOEEra> {

}

extension Fixed: Equatable {

/// Determine if two `Fixed` values are equal.
///
/// Two `Fixed` values are equal if they have the same `Region` and represent the same calendrical components.
/// - Parameter lhs: a `Fixed` value
/// - Parameter rhs: a `Fixed` value
public static func ==(lhs: Self, rhs: Self) -> Bool {
return lhs.region == rhs.region && lhs.dateComponents == rhs.dateComponents
}

}

extension Fixed: Hashable {

/// Compute the hash of an`Fixed` value
///
/// - Parameter hasher: a `Hasher`
public func hash(into hasher: inout Hasher) {
hasher.combine(region)
hasher.combine(dateComponents)
}

}

extension Fixed: Comparable {

/// Determine if one `Fixed` value is greater than another `Fixed` value.
Expand Down

0 comments on commit 32b1234

Please sign in to comment.