Currently Apple has their own calendar called Birthdays which takes the birthdays from contacts and makes it as a regular calendar event along with the birthday number, they even do this for Hebrew Birthdays. I have tried (unsuccessfully thus far) to take the same concept and create a calendar for reoccurring events on a specific date in the Hebrew Calendar. An example of this would be Yahrtzeits, which is observed on the Hebrew date each year after a person dies. I want to add it to the system calendars like how Apple does it this way it can be used with any app not just my own. Currently there isn't a way to specify the calendar (like Calendar(identifier: .hebrew) or even make a custom EKRecurrenceRule, also from some of the debugging of the Birthdays calendar, it seems that the date saved is the Gregorian date and that theres some internal calculations happening. Is there a way to add reoccurring Hebrew Events or do I need to reinvent the wheel?
Post
Replies
Boosts
Views
Activity
I'm trying to format a date to show the current time with the least amount of digits as possible. Using Date.FormatStyle and adding .hour() is the closest I can get. See the code below ↓
var formatStyle = Date.FormatStyle()
var hourMinute: Date.FormatStyle{
formatStyle
.hour()
.minute()
}
// Output 3:15 PM
var hourMinuteDefaultDigits: Date.FormatStyle{
formatStyle
.hour(.defaultDigits(amPM: .omitted))
.minute()
}
// Output 03:15
My goal is to output 3:15 without the amPm but that doesn't seem possible using Date.FormatStyle.
Based on the documentation this is the function signature
func hour(_ format: Date.FormatStyle.Symbol.Hour = .defaultDigits(amPM: .abbreviated)) -> Date.FormatStyle
// Output 3:15 PM
For some reason if I put .omitted for the amPM then defaultDigits and twoDigits return the same 2 digits for the hour
I'm trying to display an Int in Hebrew. so for example 123 should display אבג
1 = א
2 = ב
3 = ג
I have tried specifying the locale based on a the answer to a different post of mine where the solution was to specify the numbering system in the locale Locale(identifier: "he-IL@numbers=hebr")
print(123.formatted(.number.locale(Locale(identifier: "en@numbers=hebr"))))
// Output: 123
When setting the same locale for dates it formats properly with Hebrew numbers.
However if I do Arabic instead of Hebrew the numbers display properly in arabic the result for this is ``
print(123.formatted(.number.locale(Locale(identifier: "en@numbers=Arab"))))
// Output: ١٢٣
Below is the code I've tried running in a playground:
This is the code I ran in the playground
Is there a way using Date.FormatStyle to make the numbers also show in Hebrew the same way DateFormatter does?
For some reason using Date.FormatStyle doesn't seem to have the ability to show the numbers locally.
Here's some sample code, you can see that using DateFormatter the locale is respected and it displays properly but using Date.FormatStyle the numbers are still regular numbers.
Update: Here's a modified version of DateFormatter. The goal is using Date.FormatStyle and getting the same result as DateFormatter
import SwiftUI
struct ContentView: View {
let date = Date.now
var body: some View {
List{
Text(date.formatted(formatStyle.attributed))
.environment(\.locale,
Locale(languageCode: .hebrew, script: .hebrew, languageRegion: .israel))
.environment(\.calendar, Calendar(identifier: .hebrew))
Text(date, format: formattttttt)
.environment(\.locale,
Locale(languageCode: .hebrew, script: .hebrew, languageRegion: .israel))
.environment(\.calendar, Calendar(identifier: .hebrew))
Text(dateFormatted(date: date))
}
}
func dateFormatted(date: Date) -> String{
let dateFormatter = DateFormatter()
dateFormatter.calendar = Calendar(identifier: .hebrew)
dateFormatter.locale = Locale(identifier: "he")
dateFormatter.dateStyle = .full
return dateFormatter.string(from: date)
}
let formatStyle = Date.FormatStyle(
date: .complete,
time: .omitted,
locale: Locale(languageCode: .hebrew, script: .hebrew, languageRegion: .israel),
calendar: Calendar(identifier: .hebrew)
)
let formattttttt = Date.FormatStyle(
date: .complete, time: .omitted, locale: Locale(identifier: "he"), calendar: Calendar(identifier: .hebrew)).locale(Locale(identifier: "he"))
}