MCPcopy Create free account
hub / github.com/MenoData/Time4J / print

Method print

base/src/main/java/net/time4j/PrettyTime.java:827–875  ·  view source on GitHub ↗
(
        long amount,
        CalendarUnit unit,
        TextWidth width
    )

Source from the content-addressed store, hash-verified

825 * @see #print(Duration, TextWidth)
826 */
827 public String print(
828 long amount,
829 CalendarUnit unit,
830 TextWidth width
831 ) {
832 UnitPatterns p = UnitPatterns.of(this.locale);
833 CalendarUnit u;
834
835 switch (unit) {
836 case MILLENNIA:
837 amount = MathUtils.safeMultiply(amount, 1000);
838 u = CalendarUnit.YEARS;
839 break;
840 case CENTURIES:
841 amount = MathUtils.safeMultiply(amount, 100);
842 u = CalendarUnit.YEARS;
843 break;
844 case DECADES:
845 amount = MathUtils.safeMultiply(amount, 10);
846 u = CalendarUnit.YEARS;
847 break;
848 case YEARS:
849 u = CalendarUnit.YEARS;
850 break;
851 case QUARTERS:
852 amount = MathUtils.safeMultiply(amount, 3);
853 u = CalendarUnit.MONTHS;
854 break;
855 case MONTHS:
856 u = CalendarUnit.MONTHS;
857 break;
858 case WEEKS:
859 if (this.weekToDays) {
860 amount = MathUtils.safeMultiply(amount, 7);
861 u = CalendarUnit.DAYS;
862 } else {
863 u = CalendarUnit.WEEKS;
864 }
865 break;
866 case DAYS:
867 u = CalendarUnit.DAYS;
868 break;
869 default:
870 throw new UnsupportedOperationException(unit.name());
871 }
872
873 String pattern = p.getPattern(width, this.getCategory(amount), u);
874 return this.format(pattern, amount);
875 }
876
877 /**
878 * <p>Formats given duration in clock units. </p>

Callers 1

formatMethod · 0.95

Calls 15

ofMethod · 0.95
safeMultiplyMethod · 0.95
getPatternMethod · 0.95
getCategoryMethod · 0.95
formatMethod · 0.95
fromMethod · 0.95
pushDurationMethod · 0.95
nameMethod · 0.65
isEmptyMethod · 0.65
isCalendricalMethod · 0.65
isNegativeMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected