Files
videorem/videorem/Date+Extensions.swift

43 lines
1.1 KiB
Swift

//
// Date+Extensions.swift
// videorem
//
// Created by Felix Förtsch on 07.02.26.
//
import Foundation
// MARK: - Date Extensions
extension Date {
/// Returns the month and year as a formatted string (e.g., "Februar 2026")
var monthYearString: String {
CalendarConfig.monthYearFormatter.string(from: self)
}
/// Returns the year as a string (e.g., "2026")
var yearString: String {
CalendarConfig.yearFormatter.string(from: self)
}
/// Returns the month name (e.g., "Februar")
var monthName: String {
CalendarConfig.monthFormatter.string(from: self)
}
/// Returns a formatted header text for the video list sections
func headerText(calendar: Calendar) -> String {
if calendar.isDateInToday(self) {
return "Heute"
} else if calendar.isDateInYesterday(self) {
return "Gestern"
} else {
return CalendarConfig.dateHeaderFormatter.string(from: self)
}
}
/// Returns the time as a string (e.g., "14:30")
var timeString: String {
CalendarConfig.timeFormatter.string(from: self)
}
}