Class SubscriptionDateUtils
- Author:
- Sunny Yu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetCustomerTimeZone(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Gets the customer timezone from the givenCartif specified.static StringgetCustomerTimeZone(@NonNull com.broadleafcommerce.order.client.domain.Order order) Gets the customer timezone from the givenOrderif specified.static InstanttruncateToBeginningOfDay(@NonNull Instant instantToTruncate, String timezoneString) Truncates the givenInstanttoChronoUnit.DAYSin the specified timezone.
-
Constructor Details
-
SubscriptionDateUtils
public SubscriptionDateUtils()
-
-
Method Details
-
getCustomerTimeZone
@Nullable public static String getCustomerTimeZone(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Gets the customer timezone from the givenCartif specified.- Parameters:
cart- theCartto get the timezone from- Returns:
- the customer timezone from the given
Cart, if specified
-
getCustomerTimeZone
@Nullable public static String getCustomerTimeZone(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order) Gets the customer timezone from the givenOrderif specified.- Parameters:
order- theOrderto get the timezone from- Returns:
- the customer timezone from the given
Order, if specified
-
truncateToBeginningOfDay
public static Instant truncateToBeginningOfDay(@NonNull @NonNull Instant instantToTruncate, @Nullable String timezoneString) Truncates the givenInstanttoChronoUnit.DAYSin the specified timezone. If not specified,ZoneOffset.UTCis used.This is used to align the subscription dates in customer's perspectives, which is particularly important in timeframes where the local time is on a different day than UTC. If the
Instantwas truncated toChronoUnit.DAYSinZoneOffset.UTCand the customer is in a different timezone, it may result in loss/gain of hours.For example, if the customer is in the EEST timezone, which is 3 hours ahead of UTC, and signs up for the subscription at 2am 8/11/2025 EEST time, which is 11pm 8/10/2025 in UTC. Truncating the
InstanttoChronoUnit.DAYSin UTC would result to2025-08-10 00:00:00.000000. However, in the customer's perspective, the subscription sign up date should have been on 8/11/2025. This method is to help truncating to DAYS accurately based on the customer's timezone, which in this case would result in2025-08-10 21:00:00.000000.- Returns:
- the
Instantthat is truncated toChronoUnit.DAYSby the customer's timezone if specified, otherwiseZoneOffset.UTCis used
-