Class SubscriptionDateUtils
- Author:
- Sunny Yu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InstanttruncateToBeginningOfDay(@NonNull Instant instantToTruncate) Helper method to calltruncateToBeginningOfDay(Instant, String)without specified timezone.static InstanttruncateToBeginningOfDay(@NonNull Instant instantToTruncate, String timezoneString) Truncates the givenInstanttoChronoUnit.DAYSin the specified timezone.
-
Constructor Details
-
SubscriptionDateUtils
public SubscriptionDateUtils()
-
-
Method Details
-
truncateToBeginningOfDay
Helper method to calltruncateToBeginningOfDay(Instant, String)without specified timezone.Since timezone isn't specified, null is passed in (which means
ZoneOffset.UTCis used).- Parameters:
instantToTruncate- theInstantto truncate toChronoUnit.DAYS- Returns:
- the
Instanttruncated toChronoUnit.DAYSinZoneOffset.UTC
-
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
-