diff --git a/FeelsWidget2/FeelsVoteWidget.swift b/FeelsWidget2/FeelsVoteWidget.swift index 1a92712..1301d8d 100644 --- a/FeelsWidget2/FeelsVoteWidget.swift +++ b/FeelsWidget2/FeelsVoteWidget.swift @@ -60,6 +60,21 @@ struct VotedStatsView: View { UserDefaultsStore.moodMoodImagable() } + /// Returns "Today" if the voting date is today, otherwise returns formatted date like "Sun, Dec 28th" + private var votingDateString: String { + if Calendar.current.isDateInToday(entry.votingDate) { + return String(localized: "Today") + } else { + let dayFormatter = DateFormatter() + dayFormatter.dateFormat = "EEE" // "Sun" + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "MMM d" // "Dec 28" + let day = dayFormatter.string(from: entry.votingDate) + let date = dateFormatter.string(from: entry.votingDate) + return "\(day), \(date)" + } + } + var body: some View { if family == .systemSmall { smallLayout @@ -122,7 +137,7 @@ struct VotedStatsView: View { .font(.subheadline.weight(.semibold)) .foregroundColor(moodTint.color(forMood: mood)) - Text("Today") + Text(votingDateString) .font(.caption2) .foregroundStyle(.secondary) } @@ -223,6 +238,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: false, todaysMood: nil, @@ -236,6 +252,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .great, @@ -249,6 +266,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .good, @@ -262,6 +280,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .average, @@ -275,6 +294,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .bad, @@ -288,6 +308,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .horrible, @@ -301,6 +322,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: false, hasVotedToday: false, todaysMood: nil, @@ -316,6 +338,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: false, todaysMood: nil, @@ -329,6 +352,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .great, @@ -342,6 +366,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .good, @@ -355,6 +380,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .average, @@ -368,6 +394,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .bad, @@ -381,6 +408,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .horrible, @@ -394,6 +422,7 @@ private enum VoteWidgetPreviewHelpers { } timeline: { VoteWidgetEntry( date: Date(), + votingDate: Date(), hasSubscription: false, hasVotedToday: false, todaysMood: nil, diff --git a/FeelsWidget2/WidgetModels.swift b/FeelsWidget2/WidgetModels.swift index c13f879..283a510 100644 --- a/FeelsWidget2/WidgetModels.swift +++ b/FeelsWidget2/WidgetModels.swift @@ -56,6 +56,7 @@ struct SimpleEntry: TimelineEntry { struct VoteWidgetEntry: TimelineEntry { let date: Date + let votingDate: Date let hasSubscription: Bool let hasVotedToday: Bool let todaysMood: Mood? diff --git a/FeelsWidget2/WidgetProviders.swift b/FeelsWidget2/WidgetProviders.swift index c81777f..efaec73 100644 --- a/FeelsWidget2/WidgetProviders.swift +++ b/FeelsWidget2/WidgetProviders.swift @@ -154,7 +154,7 @@ struct VoteWidgetProvider: TimelineProvider { // Show sample "already voted" state for widget picker preview let sampleStats = MoodStats(totalEntries: 30, moodCounts: [.great: 10, .good: 12, .average: 5, .bad: 2, .horrible: 1]) let promptText = UserDefaultsStore.personalityPackable().randomPushNotificationStrings().body - return VoteWidgetEntry(date: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .good, stats: sampleStats, promptText: promptText) + return VoteWidgetEntry(date: Date(), votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .good, stats: sampleStats, promptText: promptText) } func getSnapshot(in context: Context, completion: @escaping (VoteWidgetEntry) -> Void) { @@ -162,7 +162,7 @@ struct VoteWidgetProvider: TimelineProvider { if context.isPreview { let sampleStats = MoodStats(totalEntries: 30, moodCounts: [.great: 10, .good: 12, .average: 5, .bad: 2, .horrible: 1]) let promptText = UserDefaultsStore.personalityPackable().randomPushNotificationStrings().body - let entry = VoteWidgetEntry(date: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .good, stats: sampleStats, promptText: promptText) + let entry = VoteWidgetEntry(date: Date(), votingDate: Date(), hasSubscription: true, hasVotedToday: true, todaysMood: .good, stats: sampleStats, promptText: promptText) completion(entry) return } @@ -254,6 +254,7 @@ struct VoteWidgetProvider: TimelineProvider { return VoteWidgetEntry( date: Date(), + votingDate: votingDate, hasSubscription: hasSubscription, hasVotedToday: hasVotedToday, todaysMood: todaysMood,