Timezone issue in IdentityIQ

Hi all,

I am facing an issue where I need the difference between 2 dates to be equal to 21 days.

The code that I have written is working as expected except 1 case

When the two dates fall under CET and CEST due to the daylight saving, the difference is never 21 days.

I tried setting the time zone to UTC, but it does not work.

Below is the code that I am using.

  String DATE_FORMAT = "MM/dd/yyyy";  
  SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);

  //forcing the parsing to UTC
  sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
  //forcing the parsing to UTC
  String endDate = "03/30/2026";

  Date leaverDate = null;
  leaverDate = sdf.parse(endDate);  
  
  Date todayDateObj = sdf.parse("03/08/2026");
  c.setTime(todayDateObj);

  //get todays date with hh:mm:ss as 00:00:00    
  //Calendar c = Calendar.getInstance();
  c.set(Calendar.HOUR_OF_DAY, 0);
  c.set(Calendar.MINUTE, 0);
  c.set(Calendar.SECOND, 0);
  c.set(Calendar.MILLISECOND, 0);
  Date todayDate = c.getTime();
  
  // get identity start date with hh:mm:ss as 00:00:00
  c.setTime(leaverDate);
  c.set(Calendar.HOUR_OF_DAY, 0);
  c.set(Calendar.MINUTE, 0);
  c.set(Calendar.SECOND, 0);
  c.set(Calendar.MILLISECOND, 0);
  leaverDate = c.getTime();   

  // get difference in dates and return true if difference is equal to 7 days     
  long diff =  leaverDate.getTime() - todayDate.getTime();
  log.debug("difference in dates for 21 days email..." + diff); 

  //trigger workflow if 21 days
  if(diff == 1814400000){  
    return "true";
  }
  else
    return "false";

Please assist

Thanks in advance

Possibly "if (Math.abs(diff - 1814400000) <= 3600000) ... " will do what you need.

Or “if (ChronoUnit.DAYS.between(todayDate, leaverDate) == 21) ...

@rishavghoshacc You are comparing milliseconds, Please try to compare date difference in days.

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

String DATE_FORMAT = "MM/dd/yyyy";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);

LocalDate today = LocalDate.parse("03/08/2026", formatter);
LocalDate leaver = LocalDate.parse("03/30/2026", formatter);

long daysBetween = ChronoUnit.DAYS.between(today, leaver);

if (daysBetween == 21) {
    return "true";
} else {
    return "false";
}

@rishavghoshacc Please test this outside IIQ first. You should use ChronoUnit.DAYS. It only counts a “day” if a full 24-hour cycle has completed. If 20 days and 23 hours have passed, it returns 20.
Also, as you are dealing with timezone, you should be using ZonedDateTime apis. which can help converting the date to the timezone before doing the comparision.

Sample Code:

import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public static void checkThreshold(Date utcDate, String userTz, int dayLimit) {
    if (utcDate == null) return;

    ZonedDateTime nowInUserZone = ZonedDateTime.now(ZoneId.of(userTz));

    ZonedDateTime termInUserZone = utcDate.toInstant().atZone(ZoneId.of(userTz));

    long daysPast = ChronoUnit.DAYS.between(termInUserZone, nowInUserZone);

    if (daysPast > dayLimit) {
        System.out.println("Over " + dayLimit + " days. Current: " + daysPast);
    } 
    }
}

Note: Found a fix?Help the community by marking the comment as solution. Feel free to react(:heart:,:+1:, etc.)with an emoji to show your appreciation or message me directly if your problem requires a deeper dive.