Trial expiration timezone mismatch
Review this Java code that computes how many whole days a subscription has been active and whether a 30-day trial has ended.
Customers span many timezones and the nightly job runs near DST transitions.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1long daysActive(Instant start, Instant now) {
2 long millis = now.toEpochMilli() - start.toEpochMilli();
3 return millis / (24 * 60 * 60 * 1000);
4}
5
6boolean trialExpired(Subscription sub) {
7 long days = daysActive(sub.startedAt(), Instant.now());
8 return days >= 30;
9}
10
11void nightlyJob(List<Subscription> subs) {
12 for (Subscription sub : subs) {
13 if (trialExpired(sub)) {
14 convertToPaid(sub);
15 }
16 }
17}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.