Class SubscriptionDateUtils

java.lang.Object
com.broadleafcommerce.subscription.service.utils.SubscriptionDateUtils

public class SubscriptionDateUtils extends Object
An util class for time related calculations.
Author:
Sunny Yu
  • Constructor Details

    • SubscriptionDateUtils

      public SubscriptionDateUtils()
  • Method Details

    • truncateToBeginningOfDay

      public static Instant truncateToBeginningOfDay(@NonNull @NonNull Instant instantToTruncate)
      Helper method to call truncateToBeginningOfDay(Instant, String) without specified timezone.

      Since timezone isn't specified, null is passed in (which means ZoneOffset.UTC is used).

      Parameters:
      instantToTruncate - the Instant to truncate to ChronoUnit.DAYS
      Returns:
      the Instant truncated to ChronoUnit.DAYS in ZoneOffset.UTC
    • truncateToBeginningOfDay

      public static Instant truncateToBeginningOfDay(@NonNull @NonNull Instant instantToTruncate, @Nullable String timezoneString)
      Truncates the given Instant to ChronoUnit.DAYS in the specified timezone. If not specified, ZoneOffset.UTC is 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 Instant was truncated to ChronoUnit.DAYS in ZoneOffset.UTC and 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 Instant to ChronoUnit.DAYS in UTC would result to 2025-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 in 2025-08-10 21:00:00.000000.

      Returns:
      the Instant that is truncated to ChronoUnit.DAYS by the customer's timezone if specified, otherwise ZoneOffset.UTC is used