Fix vote widget to show actual voting date instead of hardcoded Today

When rating for a previous day (e.g., rating last night for yesterday),
the medium vote widget now correctly shows the date like "Sun, Dec 28"
instead of always displaying "Today".

- Add votingDate property to VoteWidgetEntry
- Add dynamic date formatting in VotedStatsView
- Update all preview entries with votingDate parameter

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-29 10:06:15 -06:00
parent c59f215535
commit 2de96495e0
3 changed files with 34 additions and 3 deletions

View File

@@ -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,