Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Date.distantReference instead of Date(timeIntervalSince1970:) #23

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Tests/KintoneAPITests/DecodableTests/Date+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

extension Date {
static let distantReference: Date = {
let referenceDate = Date(timeIntervalSinceReferenceDate: 0)
return Calendar(identifier: .iso8601).date(byAdding: .year, value: -1, to: referenceDate)!
}()
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ struct FetchAppsResponseTests {
"code" : "dummy",
"name" : "dummy",
"description" : "dummy",
"createdAt" : "1970-01-01T00:00:00.000Z",
"createdAt" : "0001-01-01T00:00:00.000Z",
"creator" : {
"code" : "dummy",
"name" : "dummy"
},
"modifiedAt" : "1970-01-01T00:00:00.000Z",
"modifiedAt" : "0001-01-01T00:00:00.000Z",
"modifier" : {
"code" : "dummy",
"name" : "dummy"
Expand All @@ -50,10 +50,10 @@ struct FetchAppsResponseTests {
#expect(app.code == "dummy")
#expect(app.name == "dummy")
#expect(app.description == "dummy")
#expect(app.createdAt == Date(timeIntervalSince1970: 0))
#expect(app.createdAt == .distantPast)
#expect(app.creator.code == "dummy")
#expect(app.creator.name == "dummy")
#expect(app.modifiedAt == Date(timeIntervalSince1970: 0))
#expect(app.modifiedAt == .distantPast)
#expect(app.modifier.code == "dummy")
#expect(app.modifier.name == "dummy")
#expect(app.spaceID == nil)
Expand All @@ -70,12 +70,12 @@ struct FetchAppsResponseTests {
"code" : "dummy",
"name" : "dummy",
"description" : "dummy",
"createdAt" : "1970-01-01T00:00:00.000Z",
"createdAt" : "0001-01-01T00:00:00.000Z",
"creator" : {
"code" : "dummy",
"name" : "dummy"
},
"modifiedAt" : "1970-01-01T00:00:00.000Z",
"modifiedAt" : "0001-01-01T00:00:00.000Z",
"modifier" : {
"code" : "dummy",
"name" : "dummy"
Expand All @@ -94,10 +94,10 @@ struct FetchAppsResponseTests {
#expect(app.code == "dummy")
#expect(app.name == "dummy")
#expect(app.description == "dummy")
#expect(app.createdAt == Date(timeIntervalSince1970: 0))
#expect(app.createdAt == .distantPast)
#expect(app.creator.code == "dummy")
#expect(app.creator.name == "dummy")
#expect(app.modifiedAt == Date(timeIntervalSince1970: 0))
#expect(app.modifiedAt == .distantPast)
#expect(app.modifier.code == "dummy")
#expect(app.modifier.name == "dummy")
#expect(app.spaceID == 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ struct FetchFieldsResponseTests {
"required" : true,
"unique" : true,
"defaultNowValue" : false,
"defaultValue" : "1970-01-01"
"defaultValue" : "0001-01-01"
}
},
"revision" : "1"
Expand All @@ -240,7 +240,7 @@ struct FetchFieldsResponseTests {
#expect(attribute.required)
#expect(attribute.unique)
#expect(attribute.defaultNowValue == false)
#expect(attribute.defaultValue == Date(timeIntervalSince1970: 0))
#expect(attribute.defaultValue == .distantPast)
} else {
Issue.record("attribute must be date type.")
}
Expand All @@ -260,7 +260,7 @@ struct FetchFieldsResponseTests {
"required" : true,
"unique" : true,
"defaultNowValue" : false,
"defaultValue" : "1970-01-01T00:00"
"defaultValue" : "0001-01-01T00:00"
}
},
"revision" : "1"
Expand All @@ -278,7 +278,7 @@ struct FetchFieldsResponseTests {
#expect(attribute.required)
#expect(attribute.unique)
#expect(attribute.defaultNowValue == false)
#expect(attribute.defaultValue == Date(timeIntervalSince1970: 0))
#expect(attribute.defaultValue == .distantPast)
} else {
Issue.record("attribute must be date time type.")
}
Expand Down Expand Up @@ -1100,7 +1100,7 @@ struct FetchFieldsResponseTests {
#expect(attribute.noLabel)
#expect(attribute.required)
#expect(attribute.defaultNowValue == false)
#expect(attribute.defaultValue == Date(timeIntervalSince1970: 946684800))
#expect(attribute.defaultValue == .distantReference)
} else {
Issue.record("attribute must be time type.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ struct FetchRecordsResponseTests {
},
"dummy" : {
"type" : "CREATED_TIME",
"value" : "1970-01-01T00:00:00Z"
"value" : "0001-01-01T00:00:00Z"
}
}
]
Expand All @@ -189,7 +189,7 @@ struct FetchRecordsResponseTests {
let field = try #require(record.fields.first)
#expect(field.code == "dummy")
if case let .createdTime(value) = field.value {
#expect(value == Date(timeIntervalSince1970: 0))
#expect(value == .distantPast)
} else {
Issue.record("value must be created time type.")
}
Expand Down Expand Up @@ -239,7 +239,7 @@ struct FetchRecordsResponseTests {

@Test(arguments: [
DateProperty(value: "null", expectedValue: nil),
DateProperty(value: "\"1970-01-01\"", expectedValue: Date(timeIntervalSince1970: 0)),
DateProperty(value: "\"0001-01-01\"", expectedValue: .distantPast),
])
func response_date(_ dateProperty: DateProperty) throws {
let input = """
Expand Down Expand Up @@ -280,7 +280,7 @@ struct FetchRecordsResponseTests {

@Test(arguments: [
DateTimeProperty(value: "null", expectedValue: nil),
DateTimeProperty(value: "\"1970-01-01T00:00:00Z\"", expectedValue: Date(timeIntervalSince1970: 0)),
DateTimeProperty(value: "\"0001-01-01T00:00:00Z\"", expectedValue: .distantPast),
])
func response_dateTime(_ dateTimeProperty: DateTimeProperty) throws {
let input = """
Expand Down Expand Up @@ -1002,7 +1002,7 @@ struct FetchRecordsResponseTests {

@Test(arguments: [
TimeProperty(value: "null", expectedValue: nil),
TimeProperty(value: "\"00:00\"", expectedValue: Date(timeIntervalSince1970: 946684800)),
TimeProperty(value: "\"00:00\"", expectedValue: .distantReference),
])
func response_time(_ timeProperty: TimeProperty) throws {
let input = """
Expand Down Expand Up @@ -1057,7 +1057,7 @@ struct FetchRecordsResponseTests {
},
"dummy" : {
"type" : "UPDATED_TIME",
"value" : "1970-01-01T00:00:00Z"
"value" : "0001-01-01T00:00:00Z"
}
}
]
Expand All @@ -1073,7 +1073,7 @@ struct FetchRecordsResponseTests {
let field = try #require(record.fields.first)
#expect(field.code == "dummy")
if case let .updatedTime(value) = field.value {
#expect(value == Date(timeIntervalSince1970: 0))
#expect(value == .distantPast)
} else {
Issue.record("value must be updated time type.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ struct SubmitRecordRequestTests {
}

@Test(arguments: [
SingleValueFieldProperty(value: .date(Date(timeIntervalSince1970: 0)), expectedValue: "1970-01-01"),
SingleValueFieldProperty(value: .dateTime(Date(timeIntervalSince1970: 0)), expectedValue: "1970-01-01T00:00:00Z"),
SingleValueFieldProperty(value: .date(.distantPast), expectedValue: "0001-01-01"),
SingleValueFieldProperty(value: .dateTime(.distantPast), expectedValue: "0001-01-01T00:00:00Z"),
SingleValueFieldProperty(value: .dropDown("dummy"), expectedValue: "dummy"),
SingleValueFieldProperty(value: .link("https://example.com"), expectedValue: "https:\\/\\/example.com"),
SingleValueFieldProperty(value: .multiLineText("dummy\ndummy"), expectedValue: "dummy\\ndummy"),
SingleValueFieldProperty(value: .number("123.456"), expectedValue: "123.456"),
SingleValueFieldProperty(value: .radioButton("dummy"), expectedValue: "dummy"),
SingleValueFieldProperty(value: .richText("<h1>dummy</h1>"), expectedValue: "<h1>dummy<\\/h1>"),
SingleValueFieldProperty(value: .singleLineText("dummy"), expectedValue: "dummy"),
SingleValueFieldProperty(value: .time(Date(timeIntervalSince1970: 0)), expectedValue: "00:00"),
SingleValueFieldProperty(value: .time(.distantPast), expectedValue: "00:00"),
])
func request_single_value(_ fieldProperty: SingleValueFieldProperty) throws {
let sut = SubmitRecordRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ struct UpdateRecordRequestTests {
}

@Test(arguments: [
SingleValueFieldProperty(value: .date(Date(timeIntervalSince1970: 0)), expectedValue: "1970-01-01"),
SingleValueFieldProperty(value: .dateTime(Date(timeIntervalSince1970: 0)), expectedValue: "1970-01-01T00:00:00Z"),
SingleValueFieldProperty(value: .date(.distantPast), expectedValue: "0001-01-01"),
SingleValueFieldProperty(value: .dateTime(.distantPast), expectedValue: "0001-01-01T00:00:00Z"),
SingleValueFieldProperty(value: .dropDown("dummy"), expectedValue: "dummy"),
SingleValueFieldProperty(value: .link("https://example.com"), expectedValue: "https:\\/\\/example.com"),
SingleValueFieldProperty(value: .multiLineText("dummy\ndummy"), expectedValue: "dummy\\ndummy"),
SingleValueFieldProperty(value: .number("123.456"), expectedValue: "123.456"),
SingleValueFieldProperty(value: .radioButton("dummy"), expectedValue: "dummy"),
SingleValueFieldProperty(value: .richText("<h1>dummy</h1>"), expectedValue: "<h1>dummy<\\/h1>"),
SingleValueFieldProperty(value: .singleLineText("dummy"), expectedValue: "dummy"),
SingleValueFieldProperty(value: .time(Date(timeIntervalSince1970: 0)), expectedValue: "00:00"),
SingleValueFieldProperty(value: .time(.distantPast), expectedValue: "00:00"),
])
func request_single_value(_ fieldProperty: SingleValueFieldProperty) throws {
let sut = UpdateRecordRequest(
Expand Down
Loading