mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-08 21:37:58 +00:00
[iOS] Improve confirmed existence format
Signed-off-by: matheusgomesms <matheusgomesms@noreply.codeberg.org>
This commit is contained in:
@@ -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,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])
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user