src/com/darkyen/TimePattern.java
/**
	 * Split the duration in seconds to bins according to selected units, so that can be used to represent
	 * the time naturally.
	 *
	 * When the amount cannot be represented precisely (only when SECOND is not in selectedUnits),
	 * the value of the smallest unit is rounded so that it is closer to the real value.
	 *
	 * <pre>
	 *     Examples:
	 *     123 seconds in (WEEK, DAY, HOUR, MINUTE, SECOND) -> {WEEK: 0, DAY: 0, HOUR: 0, MINUTE: 2, SECOND: 3}
	 *     123 seconds in (MINUTE) -> {MINUTE: 2}
	 *     100 seconds in (MINUTE) -> {MINUTE: 2} because of rounding
	 *     59 minutes and 59 seconds in (HOUR, MINUTE) -> {HOUR: 1, MINUTE: 0} because of rounding
	 * </pre>
	 */
Split the duration in seconds to bins according to selected units, so that can be used to represent
the time naturally.

When the amount cannot be represented precisely (only when SECOND is not in selectedUnits),
the value of the smallest unit is rounded so that it is closer to the real value.


Split the duration in seconds to bins according to selected units so that can be used to represent the time naturally . When the amount cannot be represented precisely ( only when SECOND is not in selectedUnits ) the value of the smallest unit is rounded so that it is closer to the real value .
private static EnumMap<TimeUnit, Integer> secondsToUnits(int seconds, EnumSet<TimeUnit> selectedUnits) {
		final EnumMap<TimeUnit, Integer> result = new EnumMap<>(TimeUnit.class);
		TimeUnit lastUnit = null;
		for (TimeUnit unit : selectedUnits) {
			result.put(unit, seconds / unit.ofSeconds);
			seconds %= unit.ofSeconds;
			lastUnit = unit;
		}
		if (seconds > 0 && lastUnit != null && seconds * 2 > lastUnit.ofSeconds) {
			result.put(lastUnit, result.get(lastUnit) + 1);
			redistributePossiblyOvergrownUnit(result, lastUnit);
		}
		return result;
	}
private static EnumMap < TimeUnit , Integer > secondsToUnits ( int seconds , EnumSet < TimeUnit > selectedUnits ) { final EnumMap < TimeUnit , Integer > result = new EnumMap < > ( TimeUnit . class ) ; TimeUnit lastUnit = null ; for ( TimeUnit unit : selectedUnits ) { result . put ( unit , seconds / unit . ofSeconds ) ; seconds %= unit . ofSeconds ; lastUnit = unit ; } if ( seconds > 0 && lastUnit != null && seconds * 2 > lastUnit . ofSeconds ) { result . put ( lastUnit , result . get ( lastUnit ) + 1 ) ; redistributePossiblyOvergrownUnit ( result , lastUnit ) ; } return result ; }
Split the duration in seconds to bins according to selected units, so that can be used to represent
 the time naturally.
Split the duration in seconds to bins according to selected units so that can be used to represent the time naturally .