/** * Creates a {@link ProfilePeriod} given a timestamp defined in milliseconds * from the epoch. * * @param periodId A monotonically increasing number identifying the period. * @param duration The duration of each profile period. * @param units The units of the duration; hours, minutes, etc. */ public static ProfilePeriod fromPeriodId(long periodId, long duration, TimeUnit units) { if(periodId < 0) { throw new IllegalArgumentException(format("period id must be >= 0; got '%d'", periodId)); } return new ProfilePeriod(periodId, duration, units); }
/** * Creates a {@link ProfilePeriod} given a timestamp defined in milliseconds * from the epoch. * * @param epochMillis A timestamp contained somewhere within the profile period. * @param duration The duration of each profile period. * @param units The units of the duration; hours, minutes, etc. */ public static ProfilePeriod fromTimestamp(long epochMillis, long duration, TimeUnit units) { if(duration <= 0) { throw new IllegalArgumentException(format("period duration must be > 0; got '%d %s'", duration, units)); } long durationMillis = units.toMillis(duration); long periodId = epochMillis / durationMillis; return new ProfilePeriod(periodId, duration, units); }