Skip to content

Commit 97a8620

Browse files
committed
Fix timezone parsing for monetize subscription dates
1 parent e53088d commit 97a8620

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

client/dashboard/me/billing-monetize-subscriptions/monetize-item.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export const MonetizeSubscriptionTerms = ( {
2222
return <>{ __( 'Never expires' ) }</>;
2323
}
2424

25-
// Check if end_date is in the past
26-
const endDate = new Date( subscription.end_date );
25+
// Check if end_date is in the past (convert to ISO 8601 and append Z to parse as UTC)
26+
const endDate = new Date( subscription.end_date.replace( ' ', 'T' ) + 'Z' );
2727
const isExpired = endDate < new Date();
2828

2929
// Show "Expired" for past dates
@@ -44,14 +44,14 @@ export const MonetizeSubscriptionTerms = ( {
4444
{ subscription.renew_interval === null
4545
? // translators: %(date)s is the date the subscription expires. Format is LL (e.g. January 1, 2020).
4646
sprintf( __( 'Expires on %(date)s' ), {
47-
date: formatDate( new Date( Date.parse( subscription?.end_date ?? '' ) ), locale, {
47+
date: formatDate( new Date( subscription.end_date.replace( ' ', 'T' ) + 'Z' ), locale, {
4848
dateStyle: 'long',
4949
} ),
5050
} )
5151
: // translators: %(amount)s is the renewal price, %(date)s is the date the subscription renews. Format is LL (e.g. January 1, 2020).
5252
sprintf( __( 'Renews at %(amount)s on %(date)s' ), {
5353
amount: formatCurrency( Number( subscription.renewal_price ), subscription.currency ),
54-
date: formatDate( new Date( Date.parse( subscription?.end_date ?? '' ) ), locale, {
54+
date: formatDate( new Date( subscription.end_date.replace( ' ', 'T' ) + 'Z' ), locale, {
5555
dateStyle: 'long',
5656
} ),
5757
} ) }

client/dashboard/me/billing-monetize-subscriptions/monetize-subscription.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ function AutoRenewButton( {
8484
if ( isAutoRenewing ) {
8585
// translators: date is a formatted date string
8686
return sprintf( __( 'You will be billed on %(date)s' ), {
87-
date: formatDate( new Date( Date.parse( data?.end_date ?? '' ) ), locale, {
88-
dateStyle: 'long',
89-
} ),
87+
date: formatDate(
88+
new Date( ( data?.end_date ?? '' ).replace( ' ', 'T' ) + 'Z' ),
89+
locale,
90+
{
91+
dateStyle: 'long',
92+
}
93+
),
9094
} );
9195
}
9296
} )();
@@ -230,7 +234,14 @@ export default function MonetizeSubscriptionDetails() {
230234
const formattedExpiry = useFormattedTime( subscription?.end_date ?? '' );
231235
const formattedRenewal = useFormattedTime( subscription?.end_date ?? '' );
232236
const isOneTimePurchase = subscription?.renew_interval === 'one-time';
237+
const endDate = subscription?.end_date
238+
? new Date( subscription.end_date.replace( ' ', 'T' ) + 'Z' )
239+
: null;
240+
const isExpired = endDate && endDate < new Date();
233241
const expiryDateTitle = ( () => {
242+
if ( isExpired ) {
243+
return __( 'Expired' );
244+
}
234245
if ( isProduct ) {
235246
return __( 'Paid until' );
236247
}
@@ -285,6 +296,7 @@ export default function MonetizeSubscriptionDetails() {
285296
}
286297
return __( 'Auto-renew is disabled.' );
287298
} )() }
299+
intent={ isExpired ? 'error' : undefined }
288300
/>
289301

290302
{ isOneTimePurchase && (

0 commit comments

Comments
 (0)