- if ( $duration < $MINUTE ) {
- $s = $duration;
- $time_unit = $self->loc("sec");
- }
- elsif ( $duration < ( 2 * $HOUR ) ) {
- $s = int( $duration / $MINUTE + 0.5 );
- $time_unit = $self->loc("min");
- }
- elsif ( $duration < ( 2 * $DAY ) ) {
- $s = int( $duration / $HOUR + 0.5 );
- $time_unit = $self->loc("hours");
- }
- elsif ( $duration < ( 2 * $WEEK ) ) {
- $s = int( $duration / $DAY + 0.5 );
- $time_unit = $self->loc("days");
- }
- elsif ( $duration < ( 2 * $MONTH ) ) {
- $s = int( $duration / $WEEK + 0.5 );
- $time_unit = $self->loc("weeks");
- }
- elsif ( $duration < $YEAR ) {
- $s = int( $duration / $MONTH + 0.5 );
- $time_unit = $self->loc("months");
- }
- else {
- $s = int( $duration / $YEAR + 0.5 );
- $time_unit = $self->loc("years");
+ my @res;
+
+ my $coef = 2;
+ my $i = 0;
+ while ( $duration > 0 && ++$i <= $args{'Show'} ) {
+
+ my ($locstr, $unit);
+ if ( $duration < $MINUTE ) {
+ $locstr = $args{Short}
+ ? '[_1]s' # loc
+ : '[quant,_1,second,seconds]'; # loc
+ $unit = 1;
+ }
+ elsif ( $duration < ( $coef * $HOUR ) ) {
+ $locstr = $args{Short}
+ ? '[_1]m' # loc
+ : '[quant,_1,minute,minutes]'; # loc
+ $unit = $MINUTE;
+ }
+ elsif ( $duration < ( $coef * $DAY ) ) {
+ $locstr = $args{Short}
+ ? '[_1]h' # loc
+ : '[quant,_1,hour,hours]'; # loc
+ $unit = $HOUR;
+ }
+ elsif ( $duration < ( $coef * $WEEK ) ) {
+ $locstr = $args{Short}
+ ? '[_1]d' # loc
+ : '[quant,_1,day,days]'; # loc
+ $unit = $DAY;
+ }
+ elsif ( $duration < ( $coef * $MONTH ) ) {
+ $locstr = $args{Short}
+ ? '[_1]W' # loc
+ : '[quant,_1,week,weeks]'; # loc
+ $unit = $WEEK;
+ }
+ elsif ( $duration < $YEAR ) {
+ $locstr = $args{Short}
+ ? '[_1]M' # loc
+ : '[quant,_1,month,months]'; # loc
+ $unit = $MONTH;
+ }
+ else {
+ $locstr = $args{Short}
+ ? '[_1]Y' # loc
+ : '[quant,_1,year,years]'; # loc
+ $unit = $YEAR;
+ }
+ my $value = int( $duration / $unit + ($i < $args{'Show'}? 0 : 0.5) );
+ $duration -= int( $value * $unit );
+
+ push @res, $self->loc($locstr, $value);
+
+ $coef = 1;