/** * This method used to calculate time difference between timestamp to present. * * @param timeStamp earlier timestamp. * @return timeDurationTimestamp timestamp difference from current time to current lifecycle last state changed * time. */ public static long calculateTimeDifferenceToPresent(String timeStamp) { if (StringUtils.isEmpty(getCurrentTime()) && StringUtils.isEmpty(timeStamp)) { throw new IllegalArgumentException( "Invalid arguments supplied as timestamp two: '" + timeStamp + "' is not set"); } return Timestamp.valueOf(getCurrentTime()).getTime() - Timestamp.valueOf(timeStamp).getTime(); }
/** * This method used to check whether a duration is between a specific boundary. * * @param duration lifecycle current state duration timestamp. * @param minTime boundary lower value. * @param maxTime boundary upper value. * @return true when duration is between the boundary. */ public static boolean isDurationBetweenTimestamps(long duration, String minTime, String maxTime) { boolean result = false; // Current duration in milly seconds long durationInMillySeconds = TimeUnit.MILLISECONDS.convert(duration, TimeUnit.MILLISECONDS); // Get checkpoint boundary values in milly seconds long minBoundaryInMillySeconds = getMillySecondsByDuration(minTime); // Get checkpoint boundary values in milly seconds long maxBoundaryInMillySeconds = getMillySecondsByDuration(maxTime); // Check the duration is between the boundaries if (minBoundaryInMillySeconds < durationInMillySeconds && durationInMillySeconds < maxBoundaryInMillySeconds) { result = true; } return result; }
long duration = CheckpointTimeUtils.calculateTimeDifference(CheckpointTimeUtils .getCurrentTime(), checkpointLastUpdatedTime); if (CheckpointTimeUtils.isDurationBetweenTimestamps(duration, checkpointMin, checkpointMax)) { currentLCStateDurationInfo currentLCStateDurationInfo .put(GovernanceConstants.LIFECYCLE_DURATION, CheckpointTimeUtils .formatTimeDuration(duration)); break; GovernanceConstants.LAST_UPDATED_TIME); if (lastUpdateTIme != null) { long duration = CheckpointTimeUtils.calculateTimeDifferenceToPresent(lastUpdateTIme); currentLCStateDurationInfo.put(GovernanceConstants.LIFECYCLE_DURATION_COLOUR, null); currentLCStateDurationInfo .put(GovernanceConstants.LIFECYCLE_DURATION, CheckpointTimeUtils.formatTimeDuration(duration)); } else { return null; GovernanceConstants.LAST_UPDATED_TIME); if (lastUpdateTIme != null) { long duration = CheckpointTimeUtils.calculateTimeDifferenceToPresent(lastUpdateTIme); currentLCStateDurationInfo.put(GovernanceConstants.LIFECYCLE_DURATION_COLOUR, null); currentLCStateDurationInfo .put(GovernanceConstants.LIFECYCLE_DURATION, CheckpointTimeUtils.formatTimeDuration(duration)); } else {