[iOS] Improve confirmed existence format

Signed-off-by: matheusgomesms <matheusgomesms@noreply.codeberg.org>
This commit is contained in:
matheusgomesms
2026-01-06 11:39:16 -03:00
committed by Yannik Bloscheck
parent 49b0ec164d
commit 70215404c3
3 changed files with 46 additions and 10 deletions

View File

@@ -32,7 +32,7 @@ NSDate * _Nullable ParseDateString(NSString * _Nullable dateString) {
dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd";
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
dateFormatter.timeZone = [NSTimeZone localTimeZone];
});
return [dateFormatter dateFromString:dateString];

View File

@@ -85,10 +85,28 @@ class OpeningHoursViewController: UIViewController {
}
if let checkDate = self.openingHoursCheckDate, self.expanded {
let checkDateFormatter = RelativeDateTimeFormatter()
checkDateFormatter.unitsStyle = .spellOut
checkDateFormatter.localizedString(for: checkDate, relativeTo: Date.now)
self.checkDateLabel.text = String(format: L("hours_confirmed_time_ago"), checkDateFormatter.localizedString(for: checkDate, relativeTo: Date.now))
let dateString: String
// Check if the date is strictly "Today" or "Yesterday"
if Calendar.current.isDateInToday(checkDate) || Calendar.current.isDateInYesterday(checkDate) {
// Case 1: Today/Yesterday -> Use "today" / "yesterday"
// Can be replaced by Date.RelativeFormatStyle with iOS 18+
let checkDateFormatter = DateFormatter()
checkDateFormatter.dateStyle = .medium
checkDateFormatter.timeStyle = .none
checkDateFormatter.doesRelativeDateFormatting = true
let rawString = checkDateFormatter.string(from: checkDate)
// Lowercase first letter: "Today" -> "today"
dateString = rawString.prefix(1).lowercased() + rawString.dropFirst()
} else {
// Case 2: Older -> Use "2 years ago"
let relativeCheckDateFormatter = RelativeDateTimeFormatter()
relativeCheckDateFormatter.unitsStyle = .spellOut
dateString = relativeCheckDateFormatter.localizedString(for: checkDate, relativeTo: Date())
}
self.checkDateLabel.text = String(format: L("hours_confirmed_time_ago"), dateString)
NSLayoutConstraint.activate([self.checkDateLabelTopLayoutConstraint])
NSLayoutConstraint.activate([self.checkDateLabelBottomLayoutConstraint])

View File

@@ -458,11 +458,29 @@ class PlacePageInfoViewController: UIViewController {
setupOpenWithAppView()
if let checkDate = placePageInfoData.checkDate {
let checkDateFormatter = RelativeDateTimeFormatter()
checkDateFormatter.unitsStyle = .spellOut
checkDateFormatter.localizedString(for: checkDate, relativeTo: Date.now)
self.checkDateLabel.text = String(format: L("existence_confirmed_time_ago"), checkDateFormatter.localizedString(for: checkDate, relativeTo: Date.now))
checkDateLabel.isHidden = false
let dateString: String
// Check if the date is strictly "Today" or "Yesterday"
if Calendar.current.isDateInToday(checkDate) || Calendar.current.isDateInYesterday(checkDate) {
// Case 1: Today/Yesterday -> Use "today" / "yesterday"
// Can be replaced by Date.RelativeFormatStyle with iOS 18+
let checkDateFormatter = DateFormatter()
checkDateFormatter.dateStyle = .medium
checkDateFormatter.timeStyle = .none
checkDateFormatter.doesRelativeDateFormatting = true
let rawString = checkDateFormatter.string(from: checkDate)
// Lowercase first letter: "Today" -> "today"
dateString = rawString.prefix(1).lowercased() + rawString.dropFirst()
} else {
// Case 2: Older -> Use "2 years ago"
let relativeCheckDateFormatter = RelativeDateTimeFormatter()
relativeCheckDateFormatter.unitsStyle = .spellOut
dateString = relativeCheckDateFormatter.localizedString(for: checkDate, relativeTo: Date())
}
self.checkDateLabel.text = String(format: L("existence_confirmed_time_ago"), dateString)
checkDateLabel.isHidden = false
NSLayoutConstraint.activate([checkDateLabelLayoutConstraint])
} else {
checkDateLabel.text = String()