Fix date formatting when searching

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Marcel Müller 2022-06-12 01:02:27 +02:00
Родитель 6d70020a51
Коммит b329c02295
5 изменённых файлов: 24 добавлений и 35 удалений

Просмотреть файл

@ -38,7 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
// https://www.php.net/manual/en/class.datetimeinterface.php#datetime.constants.atom
+ (NSDate *)dateFromDateAtomFormat:(NSString *)dateAtomFormatString;
+ (NSString *)dateAtomFormatFromDate:(NSDate *)date;
+ (NSString *)readableDateFromDate:(NSDate *)date;
+ (NSString *)readableDateTimeFromDate:(NSDate *)date;
+ (NSString *)readableTimeOrDateFromDate:(NSDate *)date;
+ (NSString *)getTimeFromDate:(NSDate *)date;
+ (NSString *)relativeTimeFromDate:(NSDate *)date;

Просмотреть файл

@ -29,6 +29,8 @@
#import "NCDatabaseManager.h"
#import "NCUserDefaults.h"
#import "NSDate+DateTools.h"
static NSString *const nextcloudScheme = @"nextcloud:";
@ -143,7 +145,7 @@ static NSString *const nextcloudScheme = @"nextcloud:";
return [dateFormatter stringFromDate:date];
}
+ (NSString *)readableDateFromDate:(NSDate *)date
+ (NSString *)readableDateTimeFromDate:(NSDate *)date
{
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
@ -152,6 +154,20 @@ static NSString *const nextcloudScheme = @"nextcloud:";
return [dateFormatter stringFromDate:date];
}
+ (NSString *)readableTimeOrDateFromDate:(NSDate *)date
{
if ([date isToday]) {
return [self getTimeFromDate:date];
} else if ([date isYesterday]) {
return NSLocalizedString(@"Yesterday", nil);
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setTimeStyle:NSDateFormatterNoStyle];
[formatter setDateStyle:NSDateFormatterShortStyle];
return [formatter stringFromDate:date];
}
+ (NSString *)getTimeFromDate:(NSDate *)date
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

Просмотреть файл

@ -978,7 +978,7 @@ typedef enum FileAction {
NSInteger lobbyTimer = _lobbyDatePicker.date.timeIntervalSince1970;
[self setLobbyState:NCRoomLobbyStateModeratorsOnly withTimer:lobbyTimer];
NSString *lobbyTimerReadable = [NCUtils readableDateFromDate:_lobbyDatePicker.date];
NSString *lobbyTimerReadable = [NCUtils readableDateTimeFromDate:_lobbyDatePicker.date];
_lobbyDateTextField.text = [NSString stringWithFormat:@"%@",lobbyTimerReadable];
[self dismissLobbyDatePicker];
}
@ -1756,7 +1756,7 @@ typedef enum FileAction {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryView = _lobbyDateTextField;
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:_room.lobbyTimer];
_lobbyDateTextField.text = _room.lobbyTimer > 0 ? [NCUtils readableDateFromDate:date] : nil;
_lobbyDateTextField.text = _room.lobbyTimer > 0 ? [NCUtils readableDateTimeFromDate:date] : nil;
[cell.imageView setImage:[UIImage imageNamed:@"timer"]];
return cell;

Просмотреть файл

@ -22,7 +22,6 @@
#import "RoomSearchTableViewController.h"
#import "NSDate+DateTools.h"
#import "UIImageView+AFNetworking.h"
#import "NCAPIController.h"
@ -30,6 +29,7 @@
#import "NCDatabaseManager.h"
#import "NCRoom.h"
#import "NCSettingsController.h"
#import "NCUtils.h"
#import "PlaceholderView.h"
#import "RoomTableViewCell.h"
@ -77,19 +77,6 @@ typedef enum RoomSearchSection {
#pragma mark - Utils
- (NSString *)getDateLabelStringForDate:(NSDate *)date
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
if ([date isToday]) {
[formatter setDateFormat:@"HH:mm"];
} else if ([date isYesterday]) {
return NSLocalizedString(@"Yesterday", nil);
} else {
[formatter setDateFormat:@"dd/MM/yy"];
}
return [formatter stringFromDate:date];
}
- (NCRoom *)roomForIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == RoomSearchSectionFiltered && indexPath.row < _rooms.count) {
@ -160,7 +147,7 @@ typedef enum RoomSearchSection {
cell.titleOnly = YES;
}
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:room.lastActivity];
cell.dateLabel.text = [self getDateLabelStringForDate:date];
cell.dateLabel.text = [NCUtils readableTimeOrDateFromDate:date];
// Set unread messages
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityDirectMentionFlag]) {

Просмотреть файл

@ -26,7 +26,6 @@
#import "AFNetworking.h"
#import "AFImageDownloader.h"
#import "NSDate+DateTools.h"
#import "UIButton+AFNetworking.h"
#import "UIImageView+AFNetworking.h"
@ -971,20 +970,6 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
#pragma mark - Utils
- (NSString *)getDateLabelStringForDate:(NSDate *)date
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
if ([date isToday]) {
[formatter setDateFormat:@"HH:mm"];
} else if ([date isYesterday]) {
return NSLocalizedString(@"Yesterday", nil);
} else {
[formatter setTimeStyle:NSDateFormatterNoStyle];
[formatter setDateStyle:NSDateFormatterShortStyle];
}
return [formatter stringFromDate:date];
}
- (NCRoom *)roomForIndexPath:(NSIndexPath *)indexPath
{
if (_searchController.active && !_resultTableViewController.view.isHidden) {
@ -1100,7 +1085,7 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
cell.titleOnly = YES;
}
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:room.lastActivity];
cell.dateLabel.text = [self getDateLabelStringForDate:date];
cell.dateLabel.text = [NCUtils readableTimeOrDateFromDate:date];
// Set unread messages
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityDirectMentionFlag]) {