mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-15 08:34:22 +00:00
[iOS] Improve confirmed existence format
Signed-off-by: matheusgomesms <matheusgomesms@noreply.codeberg.org>
This commit is contained in:
committed by
Yannik Bloscheck
parent
49b0ec164d
commit
70215404c3
@@ -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];
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user