Skip to content

Commit 89102c2

Browse files
authored
Fixed humanization of time unit less than 1 second (coduo#125)
* Fixed humanization of time unit less than 1 second * Added support for 0 seconds
1 parent 9b7942f commit 89102c2

23 files changed

+97
-59
lines changed

src/Coduo/PHPHumanizer/Aeon/Calendar/UnitCompound.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,16 @@ public function components() : array
6565
$compoundResults[] = new CompoundResult(new Minute(), $unit->inTimeMinutes());
6666
}
6767

68-
if ($unit->inTimeSeconds()) {
68+
if ($unit->inTimeSeconds() || $unit->inTimeMilliseconds()) {
6969
$seconds = $unit->inTimeSeconds();
7070

7171
if ($unit->inTimeMilliseconds() > 0) {
7272
$seconds += $unit->inTimeMilliseconds() / 1000;
7373
}
7474

7575
$compoundResults[] = new CompoundResult(new Second(), $seconds);
76+
} elseif (!\count($compoundResults)) {
77+
$compoundResults[] = new CompoundResult(new Second(), 0);
7678
}
7779

7880
return $compoundResults;

src/Coduo/PHPHumanizer/Resources/translations/difference.af.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ just_now:
22
past: "[0,Inf] nou nou"
33
future: "[0,Inf] netnou"
44
second:
5-
past: "{1} %count% sekonde gelede|[2,Inf] %count% sekondes gelede"
6-
future: "{1} %count% sekonde van nou af|[2,Inf] %count% sekondes van nou af"
5+
past: "[0,1] %count% sekonde gelede|[2,Inf] %count% sekondes gelede"
6+
future: "[0,1] %count% sekonde van nou af|[2,Inf] %count% sekondes van nou af"
77
minute:
88
past: "{1} %count% minuut gelede|[2,Inf] %count% minute gelede"
99
future: "{1} %count% minuut van nou af|[2,Inf] %count% minute van nou af"
@@ -24,7 +24,7 @@ year:
2424
future: "{1} %count% jaar van nou af|[2,Inf] %count% jaar van nou af"
2525

2626
compound:
27-
second: "{1} %count% sekonde|[2,Inf] %count% sekondes"
27+
second: "[0,1] %count% sekonde|[2,Inf] %count% sekondes"
2828
minute: "{1} %count% minuut|[2,Inf] %count% minute"
2929
hour: "{1} %count% uur|[2,Inf] %count% ure"
3030
day: "{1} %count% dag|[2,Inf] %count% dae"

src/Coduo/PHPHumanizer/Resources/translations/difference.az.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ just_now:
22
past: "[0,Inf] indi"
33
future: "[0,Inf] indi"
44
second:
5-
past: "{1} %count% saniyə əvvəl|[2,Inf] %count% saniyə əvvəl"
6-
future: "{1} %count% saniyə sonra|[2,Inf] %count% saniyə sonra"
5+
past: "[0,1] %count% saniyə əvvəl|[2,Inf] %count% saniyə əvvəl"
6+
future: "[0,1] %count% saniyə sonra|[2,Inf] %count% saniyə sonra"
77
minute:
88
past: "{1} %count% dəqiqə əvvəl|[2,Inf] %count% dəqiqə əvvəl"
99
future: "{1} %count% dəqiqə sonra|[2,Inf] %count% dəqiqə sonra"
@@ -24,7 +24,7 @@ year:
2424
future: "{1} %count% il sonra|[2,Inf] %count% il sonra"
2525

2626
compound:
27-
second: "{1} %count% saniyə|[2,Inf] %count% saniyə"
27+
second: "[0,1] %count% saniyə|[2,Inf] %count% saniyə"
2828
minute: "{1} %count% dəqiqə|[2,Inf] %count% dəqiqə"
2929
hour: "{1} %count% saat|[2,Inf] %count% saat"
3030
day: "{1} %count% gün|[2,Inf] %count% gün"

src/Coduo/PHPHumanizer/Resources/translations/difference.bg.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ just_now:
22
past: "[0,Inf] в момента"
33
future: "[0,Inf] в момента"
44
second:
5-
past: "{1} преди %count% секунда|[2,Inf] преди %count% секунди"
6-
future: "{1} след %count% секунда|[2,Inf] след %count% секунди"
5+
past: "[0,1] преди %count% секунда|[2,Inf] преди %count% секунди"
6+
future: "[0,1] след %count% секунда|[2,Inf] след %count% секунди"
77
minute:
88
past: "{1} преди %count% минута|[2,Inf] преди %count% минути"
99
future: "{1} след %count% минута|[2,Inf] след %count% минути"
@@ -24,7 +24,7 @@ year:
2424
future: "{1} след %count% година|[2,Inf] след %count% години"
2525

2626
compound:
27-
second: "{1} %count% секунда|[2,Inf] %count% секунди"
27+
second: "[0,1] %count% секунда|[2,Inf] %count% секунди"
2828
minute: "{1} %count% минута|[2,Inf] %count% минути"
2929
hour: "{1} %count% час|[2,Inf] %count% часа"
3030
day: "{1} %count% ден|[2,Inf] %count% дни"

src/Coduo/PHPHumanizer/Resources/translations/difference.da.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ just_now:
22
past: "[0,Inf] lige nu"
33
future: "[0,Inf] lige nu"
44
second:
5-
past: "{1} %count% sekund siden|[2,Inf] %count% sekunder siden"
6-
future: "{1} %count% sekund fra nu|[2,Inf] %count% sekunder fra nu"
5+
past: "[0,1] %count% sekund siden|[2,Inf] %count% sekunder siden"
6+
future: "[0,1] %count% sekund fra nu|[2,Inf] %count% sekunder fra nu"
77
minute:
88
past: "{1} %count% minut siden|[2,Inf] %count% minutter siden"
99
future: "{1} %count% minut fra nu|[2,Inf] %count% minutter fra nu"
@@ -24,7 +24,7 @@ year:
2424
future: "{1} %count% år fra nu|[2,Inf] %count% år fra nu"
2525

2626
compound:
27-
second: "{1} %count% sekund|[2,Inf] %count% sekunder"
27+
second: "[0,1] %count% sekund|[2,Inf] %count% sekunder"
2828
minute: "{1} %count% minut|[2,Inf] %count% minutter"
2929
hour: "{1} %count% time|[2,Inf] %count% timer"
3030
day: "{1} %count% dag|[2,Inf] %count% dage"

src/Coduo/PHPHumanizer/Resources/translations/difference.de.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ just_now:
22
past: "[0,Inf] jetzt gerade"
33
future: "[0,Inf] jetzt gerade"
44
second:
5-
past: "{1} vor %count% Sekunde|[2,Inf] vor %count% Sekunden"
6-
future: "{1} in %count% Sekunde|[2,Inf] in %count% Sekunden"
5+
past: "[0,1] vor %count% Sekunde|[2,Inf] vor %count% Sekunden"
6+
future: "[0,1] in %count% Sekunde|[2,Inf] in %count% Sekunden"
77
minute:
88
past: "{1} vor %count% Minute|[2,Inf] vor %count% Minuten"
99
future: "{1} in %count% Minute|[2,Inf] in %count% Minuten"
@@ -24,7 +24,7 @@ year:
2424
future: "{1} in %count% Jahr|[2,Inf] in %count% Jahren"
2525

2626
compound:
27-
second: "{1} %count% Sekunde|[2,Inf] %count% Sekunden"
27+
second: "[0,1] %count% Sekunde|[2,Inf] %count% Sekunden"
2828
minute: "{1} %count% Minute|[2,Inf] %count% Minuten"
2929
hour: "{1} %count% Stunde|[2,Inf] %count% Stunden"
3030
day: "{1} %count% Tag|[2,Inf] %count% Tagen"

src/Coduo/PHPHumanizer/Resources/translations/difference.en.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ just_now:
22
past: "[0,Inf] just now"
33
future: "[0,Inf] just now"
44
second:
5-
past: "{1} %count% second ago|[2,Inf] %count% seconds ago"
6-
future: "{1} %count% second from now|[2,Inf] %count% seconds from now"
5+
past: "[0,1] %count% second ago|[2,Inf] %count% seconds ago"
6+
future: "[0,1] %count% second from now|[2,Inf] %count% seconds from now"
77
minute:
88
past: "{1} %count% minute ago|[2,Inf] %count% minutes ago"
99
future: "{1} %count% minute from now|[2,Inf] %count% minutes from now"
@@ -24,7 +24,7 @@ year:
2424
future: "{1} %count% year from now|[2,Inf] %count% years from now"
2525

2626
compound:
27-
second: "{1} %count% second|[2,Inf] %count% seconds"
27+
second: "[0,1] %count% second|[2,Inf] %count% seconds"
2828
minute: "{1} %count% minute|[2,Inf] %count% minutes"
2929
hour: "{1} %count% hour|[2,Inf] %count% hours"
3030
day: "{1} %count% day|[2,Inf] %count% days"

src/Coduo/PHPHumanizer/Resources/translations/difference.es.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ just_now:
22
past: "[0,Inf] ahora mismo"
33
future: "[0,Inf] ahora mismo"
44
second:
5-
past: "{1} hace %count% segundo |[2,Inf] hace %count% segundos"
6-
future: "{1} dentro de %count% segundo|[2,Inf] dentro de %count% segundos"
5+
past: "[0,1] hace %count% segundo |[2,Inf] hace %count% segundos"
6+
future: "[0,1] dentro de %count% segundo|[2,Inf] dentro de %count% segundos"
77
minute:
88
past: "{1} hace %count% minuto|[2,Inf] hace %count% minutos"
99
future: "{1} dentro de %count% minuto|[2,Inf] dentro de %count% minutos"
@@ -24,7 +24,7 @@ year:
2424
future: "{1} dentro de %count% año|[2,Inf] dentro de %count% años"
2525

2626
compound:
27-
second: "{1} %count% segundo|[2,Inf] %count% segundos"
27+
second: "[0,1] %count% segundo|[2,Inf] %count% segundos"
2828
minute: "{1} %count% minuto|[2,Inf] %count% minutos"
2929
hour: "{1} %count% hora|[2,Inf] %count% horas"
3030
day: "{1} %count% día|[2,Inf] %count% días"

src/Coduo/PHPHumanizer/Resources/translations/difference.fr.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ just_now:
22
past: "[0,Inf] à l'instant"
33
future: "[0,Inf] à l'instant"
44
second:
5-
past: "{1} il y a %count% seconde|[2,Inf] il y a %count% secondes"
6-
future: "{1} il y a maintenant %count% seconde|[2,Inf] il y a maintenant %count% secondes"
5+
past: "[0,1] il y a %count% seconde|[2,Inf] il y a %count% secondes"
6+
future: "[0,1] il y a maintenant %count% seconde|[2,Inf] il y a maintenant %count% secondes"
77
minute:
88
past: "{1} il y a %count% minute|[2,Inf] il y a %count% minutes"
99
future: "{1} il y a maintenant %count% minute|[2,Inf] il y a maintenant %count% minutes"
@@ -24,7 +24,7 @@ year:
2424
future: "{1} il y a maintenant %count% année|[2,Inf] il y a maintenant %count% années"
2525

2626
compound:
27-
second: "{1} %count% seconde|[2,Inf] %count% secondes"
27+
second: "[0,1] %count% seconde|[2,Inf] %count% secondes"
2828
minute: "{1} %count% minute|[2,Inf] %count% minutes"
2929
hour: "{1} %count% heure|[2,Inf] %count% heures"
3030
day: "{1} %count% jour|[2,Inf] %count% jours"

src/Coduo/PHPHumanizer/Resources/translations/difference.id.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ just_now:
22
past: "[0,Inf] baru saja"
33
future: "[0,Inf] baru saja"
44
second:
5-
past: "{1} %count% detik yang lalu|[2,Inf] %count% detik yang lalu"
6-
future: "{1} %count% detik dari sekarang|[2,Inf] %count% detik dari sekarang"
5+
past: "[0,1] %count% detik yang lalu|[2,Inf] %count% detik yang lalu"
6+
future: "[0,1] %count% detik dari sekarang|[2,Inf] %count% detik dari sekarang"
77
minute:
88
past: "{1} %count% menit yang lalu|[2,Inf] %count% menit yang lalu"
99
future: "{1} %count% menit dari sekarang|[2,Inf] %count% menit dari sekarang"
@@ -24,7 +24,7 @@ year:
2424
future: "{1} %count% tahun dari sekarang|[2,Inf] %count% tahun dari sekarang"
2525

2626
compound:
27-
second: "{1} %count% detik|[2,Inf] %count% detik"
27+
second: "[0,1] %count% detik|[2,Inf] %count% detik"
2828
minute: "{1} %count% menit|[2,Inf] %count% menit"
2929
hour: "{1} %count% jam|[2,Inf] %count% jam"
3030
day: "{1} %count% hari|[2,Inf] %count% hari"

0 commit comments

Comments
 (0)