Skip to content

New Calendar Identifiers #1171

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

Merged
merged 1 commit into from
Feb 17, 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
120 changes: 120 additions & 0 deletions Sources/FoundationEssentials/Calendar/Calendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,42 @@ public struct Calendar : Hashable, Equatable, Sendable {
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
case islamicUmmAlQura

@available(FoundationPreview 6.2, *)
case bangla

@available(FoundationPreview 6.2, *)
case gujarati

@available(FoundationPreview 6.2, *)
case kannada

@available(FoundationPreview 6.2, *)
case malayalam

@available(FoundationPreview 6.2, *)
case marathi

@available(FoundationPreview 6.2, *)
case odia

@available(FoundationPreview 6.2, *)
case tamil

@available(FoundationPreview 6.2, *)
case telugu

@available(FoundationPreview 6.2, *)
case vikram

@available(FoundationPreview 6.2, *)
case dangi

@available(FoundationPreview 6.2, *)
case thai

@available(FoundationPreview 6.2, *)
case vietnamese

package static let cldrKeywordKey = "ca"
package static let legacyKeywordKey = ICULegacyKey("calendar")

Expand Down Expand Up @@ -89,6 +125,18 @@ public struct Calendar : Hashable, Equatable, Sendable {
case "roc": self = .republicOfChina
case "islamic-tbla": self = .islamicTabular
case "islamic-umalqura": self = .islamicUmmAlQura
case "bangla": self = .bangla
case "gujarati": self = .gujarati
case "kannada": self = .kannada
case "malayalam": self = .malayalam
case "marathi": self = .marathi
case "odia": self = .odia
case "tamil": self = .tamil
case "telugu": self = .telugu
case "vikram": self = .vikram
case "dangi": self = .dangi
case "thai": self = .thai
case "vietnamese": self = .vietnamese
default: return nil
}
}
Expand All @@ -111,6 +159,18 @@ public struct Calendar : Hashable, Equatable, Sendable {
case .republicOfChina: return "roc"
case .islamicTabular: return "islamic-tbla"
case .islamicUmmAlQura: return "islamic-umalqura"
case .bangla: return "bangla"
case .gujarati: return "gujarati"
case .kannada: return "kannada"
case .malayalam: return "malayalam"
case .marathi: return "marathi"
case .odia: return "odia"
case .tamil: return "tamil"
case .telugu: return "telugu"
case .vikram: return "vikram"
case .dangi: return "dangi"
case .thai: return "thai"
case .vietnamese: return "vietnamese"
}
}

Expand All @@ -133,6 +193,18 @@ public struct Calendar : Hashable, Equatable, Sendable {
case .coptic: return "coptic"
case .ethiopicAmeteMihret: return "ethiopic"
case .ethiopicAmeteAlem: return "ethiopic-amete-alem"
case .bangla: return "bangla"
case .gujarati: return "gujarati"
case .kannada: return "kannada"
case .malayalam: return "malayalam"
case .marathi: return "marathi"
case .odia: return "odia"
case .tamil: return "tamil"
case .telugu: return "telugu"
case .vikram: return "vikram"
case .dangi: return "dangi"
case .thai: return "thai"
case .vietnamese: return "vietnamese"
}
}

Expand Down Expand Up @@ -1312,6 +1384,30 @@ public struct Calendar : Hashable, Equatable, Sendable {
return .islamicTabular
case .islamicUmmAlQura:
return .islamicUmmAlQura
case .bangla:
return .bangla
case .gujarati:
return .gujarati
case .kannada:
return .kannada
case .malayalam:
return .malayalam
case .marathi:
return .marathi
case .odia:
return .odia
case .tamil:
return .tamil
case .telugu:
return .telugu
case .vikram:
return .vikram
case .dangi:
return .dangi
case .thai:
return .thai
case .vietnamese:
return .vietnamese
}
}

Expand Down Expand Up @@ -1349,6 +1445,30 @@ public struct Calendar : Hashable, Equatable, Sendable {
return .islamicTabular
case .islamicUmmAlQura:
return .islamicUmmAlQura
case .bangla:
return .bangla
case .gujarati:
return .gujarati
case .kannada:
return .kannada
case .malayalam:
return .malayalam
case .marathi:
return .marathi
case .odia:
return .odia
case .tamil:
return .tamil
case .telugu:
return .telugu
case .vikram:
return .vikram
case .dangi:
return .dangi
case .thai:
return .thai
case .vietnamese:
return .vietnamese
default:
return nil
}
Expand Down
54 changes: 54 additions & 0 deletions Sources/FoundationInternationalization/Calendar/Calendar_ICU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,33 @@ internal final class _CalendarICU: _CalendarProtocol, @unchecked Sendable {
if time < -42790982400.0 { return nil }
case .chinese:
if time < -146325744000.0 { return nil }
case .bangla:
fallthrough
case .gujarati:
fallthrough
case .kannada:
fallthrough
case .malayalam:
fallthrough
case .marathi:
fallthrough
case .odia:
fallthrough
case .tamil:
fallthrough
case .telugu:
fallthrough
case .vikram:
// TODO: This is copied from `.indian` and needs to be revisited for each new calendar.
if time < -60645542400.0 { return nil }
return Date(timeIntervalSinceReferenceDate: -60645542400.0)
case .dangi:
fallthrough
case .thai:
fallthrough
case .vietnamese:
// TODO: This is copied from `.chinese` and needs to be revisited for each new calendar.
if time < -146325744000.0 { return nil }
}
case .hour:
let ti = Double(timeZone.secondsFromGMT(for: capped))
Expand Down Expand Up @@ -1541,6 +1568,33 @@ internal final class _CalendarICU: _CalendarProtocol, @unchecked Sendable {
if time < -42790982400.0 { return nil }
case .chinese:
if time < -146325744000.0 { return nil }
case .bangla:
fallthrough
case .gujarati:
fallthrough
case .kannada:
fallthrough
case .malayalam:
fallthrough
case .marathi:
fallthrough
case .odia:
fallthrough
case .tamil:
fallthrough
case .telugu:
fallthrough
case .vikram:
// TODO: This is copied from `.indian` and needs to be revisited for each new calendar.
if time < -60645542400.0 { return nil }
return DateInterval(start: Date(timeIntervalSinceReferenceDate: -60645542400.0), duration: inf_ti)
case .dangi:
fallthrough
case .thai:
fallthrough
case .vietnamese:
// TODO: This is copied from `.chinese` and needs to be revisited for each new calendar.
if time < -146325744000.0 { return nil }
}
case .hour:
let ti = Double(timeZone.secondsFromGMT(for: capped))
Expand Down