Skip to content

Commit 8d98ae7

Browse files
authored
chore: kickoff release
2 parents a5a981a + 0211104 commit 8d98ae7

File tree

53 files changed

+954
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+954
-179
lines changed

.github/workflows/closed_issue_message.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Closed Issue Message
33
on:
44
issues:
55
types: [closed]
6+
7+
permissions:
8+
issues: write
9+
610
jobs:
711
auto_comment:
812
runs-on: ubuntu-latest

Amplify/Categories/DataStore/Model/Internal/Model+DateFormatting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public struct ModelDateFormatting {
2727
public static let encodingStrategy: JSONEncoder.DateEncodingStrategy = {
2828
let strategy = JSONEncoder.DateEncodingStrategy.custom { date, encoder in
2929
var container = encoder.singleValueContainer()
30-
try container.encode(Temporal.DateTime(date).iso8601String)
30+
try container.encode(Temporal.DateTime(date, timeZone: .utc).iso8601String)
3131
}
3232
return strategy
3333
}()

Amplify/Categories/DataStore/Model/Internal/Persistable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Foundation
2020
/// - `Temporal.Time`
2121
/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
2222
/// by host applications. The behavior of this may change without warning.
23-
public protocol Persistable {}
23+
public protocol Persistable: Encodable {}
2424

2525
extension Bool: Persistable {}
2626
extension Double: Persistable {}

Amplify/Categories/DataStore/Model/Temporal/Date.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ extension Temporal {
1818
///
1919
/// - Note: `.medium`, `.long`, and `.full` are the same date format.
2020
public struct Date: TemporalSpec {
21+
2122
// Inherits documentation from `TemporalSpec`
2223
public let foundationDate: Foundation.Date
2324

25+
// Inherits documentation from `TemporalSpec`
26+
public let timeZone: TimeZone? = .utc
27+
2428
// Inherits documentation from `TemporalSpec`
2529
public static func now() -> Self {
26-
Temporal.Date(Foundation.Date())
30+
Temporal.Date(Foundation.Date(), timeZone: .utc)
2731
}
2832

2933
// Inherits documentation from `TemporalSpec`
30-
public init(_ date: Foundation.Date) {
34+
public init(_ date: Foundation.Date, timeZone: TimeZone?) {
3135
self.foundationDate = Temporal
3236
.iso8601Calendar
3337
.startOfDay(for: date)

Amplify/Categories/DataStore/Model/Temporal/DateTime.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,33 @@ extension Temporal {
1515
/// * `.long` => `yyyy-MM-dd'T'HH:mm:ssZZZZZ`
1616
/// * `.full` => `yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ`
1717
public struct DateTime: TemporalSpec {
18+
1819
// Inherits documentation from `TemporalSpec`
1920
public let foundationDate: Foundation.Date
2021

22+
// Inherits documentation from `TemporalSpec`
23+
public let timeZone: TimeZone?
24+
2125
// Inherits documentation from `TemporalSpec`
2226
public static func now() -> Self {
23-
Temporal.DateTime(Foundation.Date())
27+
Temporal.DateTime(Foundation.Date(), timeZone: .utc)
2428
}
2529

2630
/// `Temporal.Time` of this `Temporal.DateTime`.
2731
public var time: Time {
28-
Time(foundationDate)
32+
Time(foundationDate, timeZone: timeZone)
2933
}
3034

3135
// Inherits documentation from `TemporalSpec`
32-
public init(_ date: Foundation.Date) {
36+
public init(_ date: Foundation.Date, timeZone: TimeZone? = .utc) {
3337
let calendar = Temporal.iso8601Calendar
3438
let components = calendar.dateComponents(
3539
DateTime.iso8601DateComponents,
3640
from: date
3741
)
3842

43+
self.timeZone = timeZone
44+
3945
foundationDate = calendar
4046
.date(from: components) ?? date
4147
}
@@ -57,3 +63,5 @@ extension Temporal {
5763

5864
// Allow date unit and time unit operations on `Temporal.DateTime`
5965
extension Temporal.DateTime: DateUnitOperable, TimeUnitOperable {}
66+
67+
extension Temporal.DateTime: Sendable { }

Amplify/Categories/DataStore/Model/Temporal/SpecBasedDateConverting.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212
@usableFromInline
1313
internal struct SpecBasedDateConverting<Spec: TemporalSpec> {
1414
@usableFromInline
15-
internal typealias DateConverter = (_ string: String, _ format: TemporalFormat?) throws -> Date
15+
internal typealias DateConverter = (_ string: String, _ format: TemporalFormat?) throws -> (Date, TimeZone)
1616

1717
@usableFromInline
1818
internal let convert: DateConverter
@@ -28,19 +28,21 @@ internal struct SpecBasedDateConverting<Spec: TemporalSpec> {
2828
internal static func `default`(
2929
iso8601String: String,
3030
format: TemporalFormat? = nil
31-
) throws -> Date {
31+
) throws -> (Date, TimeZone) {
3232
let date: Foundation.Date
33+
let tz: TimeZone = TimeZone(iso8601DateString: iso8601String) ?? .utc
3334
if let format = format {
3435
date = try Temporal.date(
3536
from: iso8601String,
3637
with: [format(for: Spec.self)]
3738
)
39+
3840
} else {
3941
date = try Temporal.date(
4042
from: iso8601String,
4143
with: TemporalFormat.sortedFormats(for: Spec.self)
4244
)
4345
}
44-
return date
46+
return (date, tz)
4547
}
4648
}

Amplify/Categories/DataStore/Model/Temporal/Temporal+Comparable.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import Foundation
1515
extension TemporalSpec where Self: Comparable {
1616

1717
public static func == (lhs: Self, rhs: Self) -> Bool {
18-
return lhs.iso8601String == rhs.iso8601String
18+
return lhs.iso8601FormattedString(format: .full, timeZone: .utc)
19+
== rhs.iso8601FormattedString(format: .full, timeZone: .utc)
1920
}
2021

2122
public static func < (lhs: Self, rhs: Self) -> Bool {
22-
return lhs.iso8601String < rhs.iso8601String
23+
return lhs.iso8601FormattedString(format: .full, timeZone: .utc)
24+
< rhs.iso8601FormattedString(format: .full, timeZone: .utc)
2325
}
2426
}
2527

Amplify/Categories/DataStore/Model/Temporal/Temporal.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public protocol TemporalSpec {
2727
/// by a Foundation `Date` instance.
2828
var foundationDate: Foundation.Date { get }
2929

30+
/// The timezone field is an optional field used to specify the timezone associated
31+
/// with a particular date.
32+
var timeZone: TimeZone? { get }
33+
3034
/// The ISO-8601 formatted string in the UTC `TimeZone`.
3135
/// - SeeAlso: `iso8601FormattedString(TemporalFormat, TimeZone) -> String`
3236
var iso8601String: String { get }
@@ -57,7 +61,7 @@ public protocol TemporalSpec {
5761
/// Constructs a `TemporalSpec` from a `Date` object.
5862
/// - Parameter date: The `Date` instance that will be used as the reference of the
5963
/// `TemporalSpec` instance.
60-
init(_ date: Foundation.Date)
64+
init(_ date: Foundation.Date, timeZone: TimeZone?)
6165

6266
/// A string representation of the underlying date formatted using ISO8601 rules.
6367
///
@@ -90,25 +94,25 @@ extension TemporalSpec {
9094
/// The ISO8601 representation of the scalar using `.full` as the format and `.utc` as `TimeZone`.
9195
/// - SeeAlso: `iso8601FormattedString(format:timeZone:)`
9296
public var iso8601String: String {
93-
iso8601FormattedString(format: .full)
97+
iso8601FormattedString(format: .full, timeZone: timeZone ?? .utc)
9498
}
9599

96100
@inlinable
97101
public init(iso8601String: String, format: TemporalFormat) throws {
98-
let date = try SpecBasedDateConverting<Self>()
102+
let (date, tz) = try SpecBasedDateConverting<Self>()
99103
.convert(iso8601String, format)
100104

101-
self.init(date)
105+
self.init(date, timeZone: tz)
102106
}
103107

104108
@inlinable
105109
public init(
106110
iso8601String: String
107111
) throws {
108-
let date = try SpecBasedDateConverting<Self>()
112+
let (date, tz) = try SpecBasedDateConverting<Self>()
109113
.convert(iso8601String, nil)
110114

111-
self.init(date)
115+
self.init(date, timeZone: tz)
112116
}
113117
}
114118

Amplify/Categories/DataStore/Model/Temporal/TemporalOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ extension TemporalSpec {
3333
"""
3434
)
3535
}
36-
return Self.init(date)
36+
return Self.init(date, timeZone: timeZone)
3737
}
3838
}

Amplify/Categories/DataStore/Model/Temporal/Time.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ extension Temporal {
1818
// Inherits documentation from `TemporalSpec`
1919
public let foundationDate: Foundation.Date
2020

21+
// Inherits documentation from `TemporalSpec`
22+
public let timeZone: TimeZone? = .utc
23+
2124
// Inherits documentation from `TemporalSpec`
2225
public static func now() -> Self {
23-
Temporal.Time(Foundation.Date())
26+
Temporal.Time(Foundation.Date(), timeZone: .utc)
2427
}
2528

2629
// Inherits documentation from `TemporalSpec`
27-
public init(_ date: Foundation.Date) {
30+
public init(_ date: Foundation.Date, timeZone: TimeZone?) {
2831
// Sets the date to a fixed instant so time-only operations are safe
2932
let calendar = Temporal.iso8601Calendar
3033
var components = calendar.dateComponents(
@@ -45,7 +48,6 @@ extension Temporal {
4548
components.year = 2_000
4649
components.month = 1
4750
components.day = 1
48-
4951
self.foundationDate = calendar
5052
.date(from: components) ?? date
5153
}

0 commit comments

Comments
 (0)