docs: @Pure
  	@SuppressWarnings({"checkstyle:magicnumber", "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"})
  	public static String formatTime(double amount, TimeUnit unit) {
  		double amt;
  		double coef = 1.;
  		switch (unit) {
  		case DAYS:
  			coef = 86400.;
  			break;
  		case HOURS:
  			coef = 3600.;
  			break;
  		case MINUTES:
  			coef = 60.;
  			break;
  		case SECONDS:
  			break;
  		case MILLISECONDS:
  			coef = 1e-3;
  			break;
  		case MICROSECONDS:
  			coef = 1e-6;
  			break;
  		case NANOSECONDS:
  			coef = 1e-9;
  			break;
  		default:
  			throw new IllegalArgumentException();
  		}
  
  		// amount is in seconds
  		amt = amount * coef;
  
  		final StringBuilder text = new StringBuilder();
  
  		String centuries = ""; //$NON-NLS-1$
  		String years = ""; //$NON-NLS-1$
  		String days = ""; //$NON-NLS-1$
  		String hours = ""; //$NON-NLS-1$
  		String minutes = ""; //$NON-NLS-1$
  		String seconds = ""; //$NON-NLS-1$
  		long ah = 0;
  		long am = 0;
  		long as = 0;
  		int idx = 0;
  
  		if (amt >= 3153600000.) {
  			final long a = (long) Math.floor(amt / 3153600000.);
  			centuries = Locale.getString((a >= 2) ? "TIME_FORMAT_Cs" : "TIME_FORMAT_C", //$NON-NLS-1$ //$NON-NLS-2$
  					Long.toString(a));
  			amt -= a * 3153600000.;
  			text.append(centuries);
  			idx |= 32;
  		}
  
  		if (amt >= 31536000.) {
  			final long a = (long) Math.floor(amt / 31536000.);
  			years = Locale.getString((a >= 2) ? "TIME_FORMAT_Ys" : "TIME_FORMAT_Y", //$NON-NLS-1$ //$NON-NLS-2$
  					Long.toString(a));
  			amt -= a * 31536000.;
  			if (text.length() > 0) {
  				text.append(' ');
  			}
  			text.append(years);
  			idx |= 16;
  		}
  
  		if (amt >= 86400.) {
  			final long a = (long) Math.floor(amt / 86400.);
  			days = Locale.getString((a >= 2) ? "TIME_FORMAT_Ds" : "TIME_FORMAT_D", //$NON-NLS-1$ //$NON-NLS-2$
  					Long.toString(a));
  			amt -= a * 86400.;
  			if (text.length() > 0) {
  				text.append(' ');
  			}
  			text.append(days);
  			idx |= 8;
  		}
  
  		//-------------------
  
  		if (amt >= 3600.) {
  			ah = (long) Math.floor(amt / 3600.);
  			hours = Long.toString(ah);
  			if (ah < 10.) {
  				hours = "0" + hours; //$NON-NLS-1$
  			}
  			amt -= ah * 3600.;
  			idx |= 4;
  		}
  
  		if (amt >= 60.) {
  			am = (long) Math.floor(amt / 60.);
  			minutes = Long.toString(am);
  			if (am < 10.) {
  				minutes = "0" + minutes; //$NON-NLS-1$
  			}
  			amt -= am * 60.;
  			idx |= 2;
  		}
  
  		if (amt >= 0. || idx == 0) {
  			if (idx >= 8) {
  				as = (long) Math.floor(amt);
  				seconds = Long.toString(as);
  			} else {
  				final NumberFormat fmt = new DecimalFormat("#0.000"); //$NON-NLS-1$
  				seconds = fmt.format(amt);
  			}
  			idx |= 1;
  		}
  
  		if ((idx & 7) == 7) {
  			if (text.length() > 0) {
  				text.append(' ');
  			}
  			if (idx >= 8 && as > 0) {
  				if (as < 10.) {
  					seconds = "0" + seconds; //$NON-NLS-1$
  				}
  			} else if (idx < 8 && amt > 0. && amt < 10.) {
  				seconds = "0" + seconds; //$NON-NLS-1$
  			}
  			text.append(Locale.getString("TIME_FORMAT_HMS", hours, minutes, seconds)); //$NON-NLS-1$
  		} else {
  			if (ah > 0) {
  				if (text.length() > 0) {
  					text.append(' ');
  				}
  				text.append(Locale.getString((ah >= 2) ? "TIME_FORMAT_Hs" : "TIME_FORMAT_H", //$NON-NLS-1$ //$NON-NLS-2$
  						hours));
  			}
  			if (am > 0) {
  				if (text.length() > 0) {
  					text.append(' ');
  				}
  				text.append(Locale.getString((am >= 2) ? "TIME_FORMAT_Ms" : "TIME_FORMAT_M", //$NON-NLS-1$ //$NON-NLS-2$
  						minutes));
  			}
  			if (idx >= 8 && as > 0) {
  				if (text.length() > 0) {
  					text.append(' ');
  				}
  				text.append(Locale.getString((as >= 2) ? "TIME_FORMAT_Ss" : "TIME_FORMAT_S", //$NON-NLS-1$ //$NON-NLS-2$
  						seconds));
  			} else if (idx < 8 && amt > 0.) {
  				if (text.length() > 0) {
  					text.append(' ');
  				}
  				text.append(Locale.getString((amt >= 2.) ? "TIME_FORMAT_Ss" : "TIME_FORMAT_S", //$NON-NLS-1$ //$NON-NLS-2$
  						seconds));
  			}
  		}
  
  		return text.toString();
  	}