Skip to content

Commit 13ca142

Browse files
AchoArnoldCopilot
andcommitted
fix: render billing dates in the user's timezone
Format the billing period using the user's configured timezone via user.Location() instead of UTC, so dates match what the user sees. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0c46667 commit 13ca142

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

api/pkg/emails/hermes_user_email_factory.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ type hermesUserEmailFactory struct {
1515
generator hermes.Hermes
1616
}
1717

18-
// formatBillingDate renders a date like "19 June 2026" in UTC, matching how
19-
// the billing cycle boundaries are computed in the billing usage repository.
20-
func formatBillingDate(t time.Time) string {
21-
return t.UTC().Format("2 January 2006")
18+
// formatBillingDate renders a date like "19 June 2026" in the user's timezone.
19+
func formatBillingDate(t time.Time, location *time.Location) string {
20+
return t.In(location).Format("2 January 2006")
2221
}
2322

2423
func (factory *hermesUserEmailFactory) APIKeyRotated(emailAddress string, timestamp time.Time, timezone string) (*Email, error) {
@@ -75,7 +74,7 @@ func (factory *hermesUserEmailFactory) UsageLimitExceeded(user *entities.User, u
7574
Body: hermes.Body{
7675
Intros: []string{
7776
fmt.Sprintf("You've reached your limit of %d messages on the %s plan, so new messages will not be processed until your usage resets.", user.SubscriptionName.Limit(), user.SubscriptionName),
78-
fmt.Sprintf("Between %s and %s you sent %d messages and received %d, for a total of %d.", formatBillingDate(usage.StartTimestamp), formatBillingDate(usage.EndTimestamp), usage.SentMessages, usage.ReceivedMessages, usage.TotalMessages()),
77+
fmt.Sprintf("Between %s and %s you sent %d messages and received %d, for a total of %d.", formatBillingDate(usage.StartTimestamp, user.Location()), formatBillingDate(usage.EndTimestamp, user.Location()), usage.SentMessages, usage.ReceivedMessages, usage.TotalMessages()),
7978
},
8079
Actions: []hermes.Action{
8180
{
@@ -121,7 +120,7 @@ func (factory *hermesUserEmailFactory) UsageLimitAlert(user *entities.User, usag
121120
Body: hermes.Body{
122121
Intros: []string{
123122
fmt.Sprintf("This is a friendly heads-up that you've used %d%% of your monthly SMS limit on the %s plan.", percent, user.SubscriptionName),
124-
fmt.Sprintf("Between %s and %s you sent %d messages and received %d, for a total of %d out of your %d message limit.", formatBillingDate(usage.StartTimestamp), formatBillingDate(usage.EndTimestamp), usage.SentMessages, usage.ReceivedMessages, usage.TotalMessages(), user.SubscriptionName.Limit()),
123+
fmt.Sprintf("Between %s and %s you sent %d messages and received %d, for a total of %d out of your %d message limit.", formatBillingDate(usage.StartTimestamp, user.Location()), formatBillingDate(usage.EndTimestamp, user.Location()), usage.SentMessages, usage.ReceivedMessages, usage.TotalMessages(), user.SubscriptionName.Limit()),
125124
},
126125
Actions: []hermes.Action{
127126
{

0 commit comments

Comments
 (0)