Skip to content

Commit

Permalink
Simplify DateFormatting code
Browse files Browse the repository at this point in the history
  • Loading branch information
feliciaan committed Nov 27, 2015
1 parent 3a03e90 commit 3c73aac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
36 changes: 14 additions & 22 deletions iOS/Hydra/HomeActivityCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion iOS/Hydra/HomeRestoCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down

0 comments on commit 3c73aac

Please sign in to comment.