From 3c73aac38ea9179364f77529e08d635e5dafbe80 Mon Sep 17 00:00:00 2001 From: Feliciaan De Palmenaer Date: Fri, 27 Nov 2015 22:16:22 +0100 Subject: [PATCH] Simplify DateFormatting code --- .../HomeActivityCollectionViewCell.swift | 36 ++++++++----------- iOS/Hydra/HomeRestoCollectionViewCell.swift | 2 +- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/iOS/Hydra/HomeActivityCollectionViewCell.swift b/iOS/Hydra/HomeActivityCollectionViewCell.swift index eb1a5940..422574fe 100644 --- a/iOS/Hydra/HomeActivityCollectionViewCell.swift +++ b/iOS/Hydra/HomeActivityCollectionViewCell.swift @@ -15,37 +15,29 @@ class HomeActivityCollectionViewCell: UICollectionViewCell { @IBOutlet weak var descriptionLabel: UILabel! @IBOutlet weak var locationLabel: UILabel! @IBOutlet weak var imageView: UIImageView! - + var activity: AssociationActivity? { didSet { - associationLabel.text = activity?.association.displayName + let longDateFormatter = NSDateFormatter.H_dateFormatterWithAppLocale() + longDateFormatter.timeStyle = .ShortStyle + longDateFormatter.dateStyle = .LongStyle + longDateFormatter.doesRelativeDateFormatting = true + + let shortDateFormatter = NSDateFormatter.H_dateFormatterWithAppLocale() + shortDateFormatter.timeStyle = .ShortStyle + shortDateFormatter.dateStyle = .NoStyle - let dateStartFormatter = NSDateFormatter.H_dateFormatterWithAppLocale() - dateStartFormatter.dateFormat = "EEE d MMMM H:mm"; - let dateEndFormatter = NSDateFormatter.H_dateFormatterWithAppLocale() + associationLabel.text = activity?.association.displayName titleLabel.text = activity?.title - dateEndFormatter.dateFormat = "H:mm"; - if (self.activity!.start.isToday()) { - if self.activity!.start.dateByAddingDays(1).isLaterThanDate(self.activity!.end) { - dateLabel.text = "vandaag \(dateEndFormatter.stringFromDate((self.activity?.start)!)) - \(dateEndFormatter.stringFromDate((self.activity?.end)!))" - } else { - dateLabel.text = "vandaag \(dateEndFormatter.stringFromDate((self.activity?.start)!)) - \(dateStartFormatter.stringFromDate((self.activity?.end)!))" - } - } else if (self.activity!.start.isTomorrow()) { - if self.activity!.start.dateByAddingDays(1).isLaterThanDate(self.activity!.end) { - dateLabel.text = "morgen \(dateEndFormatter.stringFromDate((self.activity?.start)!)) - \(dateEndFormatter.stringFromDate((self.activity?.end)!))" - } else { - dateLabel.text = "morgen \(dateEndFormatter.stringFromDate((self.activity?.start)!)) - \(dateStartFormatter.stringFromDate((self.activity?.end)!))" - } - } else if (self.activity!.end != nil) { + if (self.activity!.end != nil) { if self.activity!.start.dateByAddingDays(1).isLaterThanDate(self.activity!.end) { - dateLabel.text = "\(dateStartFormatter.stringFromDate((self.activity?.start)!)) - \(dateEndFormatter.stringFromDate((self.activity?.end)!))" + dateLabel.text = "\(longDateFormatter.stringFromDate((self.activity?.start)!)) - \(shortDateFormatter.stringFromDate((self.activity?.end)!))" } else { - dateLabel.text = "\(dateStartFormatter.stringFromDate((self.activity?.start)!)) - \(dateStartFormatter.stringFromDate((self.activity?.end)!))" + dateLabel.text = "\(longDateFormatter.stringFromDate((self.activity?.start)!)) - \(longDateFormatter.stringFromDate((self.activity?.end)!))" } } else { - dateLabel.text = "\(dateStartFormatter.stringFromDate((self.activity?.start)!))" + dateLabel.text = longDateFormatter.stringFromDate((self.activity?.start)!) } descriptionLabel.text = activity?.descriptionText diff --git a/iOS/Hydra/HomeRestoCollectionViewCell.swift b/iOS/Hydra/HomeRestoCollectionViewCell.swift index 4a2f8200..ddde6f6e 100644 --- a/iOS/Hydra/HomeRestoCollectionViewCell.swift +++ b/iOS/Hydra/HomeRestoCollectionViewCell.swift @@ -24,7 +24,7 @@ class HomeRestoCollectionViewCell: UICollectionViewCell, UITableViewDataSource, } else { let formatter = NSDateFormatter.H_dateFormatterWithAppLocale() formatter.dateFormat = "EEEE d MMMM" - dayLabel.text = "" + formatter.stringFromDate(restoMenu!.day) + dayLabel.text = formatter.stringFromDate(restoMenu!.day) } } else { dayLabel.text = ""