[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
parent 5e8d2e1a59
commit 9916850758
3 changed files with 44 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,27 @@ 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"
let df = DateFormatter()
df.dateStyle = .medium
df.timeStyle = .none
df.doesRelativeDateFormatting = true
let rawString = df.string(from: checkDate)
// Lowercase first letter: "Today" -> "today"
dateString = rawString.prefix(1).lowercased() + rawString.dropFirst()
} else {
// Case 2: Older -> Use "2 years ago"
let rdf = RelativeDateTimeFormatter()
rdf.unitsStyle = .spellOut
dateString = rdf.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,28 @@ 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"
let df = DateFormatter()
df.dateStyle = .medium
df.timeStyle = .none
df.doesRelativeDateFormatting = true // Generates "Today"
let rawString = df.string(from: checkDate)
// Lowercase first letter: "Today" -> "today"
dateString = rawString.prefix(1).lowercased() + rawString.dropFirst()
} else {
// Case 2: Older -> Use "2 years ago"
let rdf = RelativeDateTimeFormatter()
rdf.unitsStyle = .spellOut
dateString = rdf.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()