question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Long time formats for Czech do not include number of hours

See original GitHub issue

Hello,

it seems that the definition of long time formats for the Czech language (in https://github.com/date-fns/date-fns/blob/master/src/locale/cs/_lib/formatLong/index.ts#L11) uses H instead of HH unlike other locales. This then results in weird behavior when switching between languages because strings like 1 hours 15 minutes change to hour 15 minutes (in Czech).

This behaviour was encountered in jellyfin-vue that uses date-fns 2.28.0 (https://github.com/jellyfin/jellyfin-vue/blob/master/package.json#L46).

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
KucharczykLcommented, Jan 18, 2022

Hope I won’t sound too aggressive but it should have been asked what are the reasons and use cases for omitting the number, not the other way around (asking why the number should be included). Having a number is the default and never wrong. Not having a number is change from the default and can sometimes be wrong or odd.

0reactions
fturmelcommented, Jan 17, 2022

Interesting. So, maybe this is just the wrong way to build a localized media duration string? How should a project like Jellyfin approach this problem? Is this a blind spot of date-fns that should be considered?

@KucharczykL @janziemba could you share some use cases that would require to have or not have the number 1, just so we can document them?

For the sake of comparison, here are all locales using formatDuration and Intl.NumberFormat (❌ indicates no support in Chrome 97, will fallback to system’s default locale)

results table
locale date-fns formatDuration Intl.NumberFormat same?
af 1 uur 15 minute
ar ساعة واحدة 15 دقيقة ساعة 15 دقيقة
ar-DZ ساعة واحدة 15 دقيقة ساعة 15 دقيقة
ar-EG ساعة 15 دقيقة ساعة ١٥ دقيقة
ar-MA ساعة واحدة 15 دقيقة ساعة 15 دقيقة
ar-SA ساعة واحدة 15 دقيقة ساعة ١٥ دقيقة
ar-TN ساعة 15 دقيقة ساعة 15 دقيقة
az 1 saat 15 dəqiqə 1 hour 15 minutes
be 1 гадзіна 15 хвілін
bg 1 час 15 минути 1 час 15 минути
bn ১ ঘন্টা ১৫ মিনিট ১ ঘন্টা ১৫ মিনিট
bs 1 sat 15 minuta 1 hour 15 minutes
ca 1 hora 15 minuts 1 hora 15 minuts
cs hodina 15 minut 1 hodina 15 minut
cy 1 awr 15 munud
da 1 time 15 minutter 1 time 15 minutter
de 1 Stunde 15 Minuten 1 Stunde 15 Minuten
de-AT 1 Stunde 15 Minuten 1 Stunde 15 Minuten
el 1 ώρα 15 λεπτά 1 ώρα 15 λεπτά
en-AU 1 hour 15 minutes 1 hour 15 minutes
en-CA an hour 15 minutes 1 hour 15 minutes
en-GB 1 hour 15 minutes 1 hour 15 minutes
en-IE 1 hour 15 minutes 1 hour 15 minutes
en-IN 1 hour 15 minutes 1 hour 15 minutes
en-NZ 1 hour 15 minutes 1 hour 15 minutes
en-US 1 hour 15 minutes 1 hour 15 minutes
en-ZA 1 hour 15 minutes 1 hour 15 minutes
eo 1 horo 15 minutoj
es 1 hora 15 minutos 1 hora 15 minutos
et üks tund 15 minutit 1 tund 15 minutit
eu 1 ordu 15 minutu
fa-IR 1 ساعت 15 دقیقه ۱ ساعت ۱۵ دقیقه
fi tunti 15 minuuttia 1 tunti 15 minuuttia
fr 1 heure 15 minutes 1 heure 15 minutes
fr-CA 1 heure 15 minutes 1 heure 15 minutes
fr-CH 1 heure 15 minutes 1 heure 15 minutes
fy 1 oere 15 minuten
gd 1 uair de thìde 15 mionaidean
gl 1 hora 15 minutos
gu 1 કલાક 15 મિનિટ 1 કલાક 15 મિનિટ
he שעה 15 דקות שעה 15 דקות
hi १ घंटा १५ मिनट 1 घंटा 15 मिनट
hr 1 sat 15 minuta 1 sat 15 minuta
ht 1 lè 15 minit
hu 1 óra 15 perc 1 óra 15 perc
hy 1 ժամ 15 րոպե
id 1 jam 15 menit 1 jam 15 menit
is 1 klukkustund 15 mínútur
it un’ora 15 minuti 1 ora 15 minuti
ja 1時間 15分 1 時間 15 分
ja-Hira 1じかん 15ふん 1 時間 15 分
ka 1 საათი 15 წუთი
kk 1 сағат 15 минут
km 1 ម៉ោង 15 នាទី
kn 1 ಗಂಟೆ 15 ನಿಮಿಷಗಳು 1 ಗಂಟೆ 15 ನಿಮಿಷಗಳು
ko 1시간 15분 1시간 15분
lb eng Stonn 15 Minutten
lt valanda 15 minučių 1 valanda 15 minučių
lv 1 stunda 15 minūtes 1 stunda 15 minūšu
mk 1 час 15 минути
mn 1 цаг 15 минут
ms 1 jam 15 minit 1 jam 15 minit
mt siegħa 15 minuti
nb en time 15 minutter 1 time 15 minutter
nl 1 uur 15 minuten 1 uur 15 minuten
nl-BE 1 uur 15 minuten 1 uur 15 minuten
nn ein time 15 minutt
pl godzina 15 minut 1 godzina 15 minut
pt 1 hora 15 minutos 1 hora 15 minutos
pt-BR 1 hora 15 minutos 1 hora 15 minutos
ro 1 oră 15 minute 1 oră 15 minute
ru 1 час 15 минут 1 час 15 минут
sk hodina 15 minút 1 hodina 15 minút
sl 1 ura 15 minut 1 ura 15 minut
sq 1 orë 15 minuta
sr 1 сат 15 минута 1 сат 15 минута
sr-Latn 1 sat 15 minuta 1 sat 15 minuta
sv en timme 15 minuter 1 timme 15 minuter
ta 1 மணி நேரம் 15 நிமிடங்கள் 1 மணிநேரம் 15 நிமிடங்கள்
te ఒక గంట 15 నిమిషాలు 1 గంట 15 నిమిషాలు
th 1 ชั่วโมง 15 นาที 1 ชั่วโมง 15 นาที
tr 1 saat 15 dakika 1 saat 15 dakika
ug بىر سائەت مىنۇت 15
uk 1 годину 15 хвилин 1 година 15 хвилин
uz 1 soat 15 minut 1 hour 15 minutes
uz-Cyrl 1 соат 15 дақиқа 1 hour 15 minutes
vi 1 giờ 15 phút 1 giờ 15 phút
zh-CN 1 小时 15 分钟 1小时 15分钟
zh-HK 1 小時 15 分鐘 1 小時 15 分鐘
zh-TW 1 小時 15 分鐘 1 小時 15 分鐘
source code
import { formatDuration } from "date-fns";
import * as locales from "date-fns/locale";

function dateFnsFormat(locale) {
  return formatDuration(
    { hours: 1, minutes: 15 },
    {
      format: ["hours", "minutes"],
      locale
    }
  );
}

function intlFormat(localeCode) {
  if (Intl.NumberFormat.supportedLocalesOf(localeCode).length === 0) {
    return "❌";
  }

  const hours = new Intl.NumberFormat(localeCode, {
    style: "unit",
    unit: "hour",
    unitDisplay: "long"
  }).format(1);

  const minutes = new Intl.NumberFormat(localeCode, {
    style: "unit",
    unit: "minute",
    unitDisplay: "long"
  }).format(15);

  return hours + " " + minutes;
}

console.log("|locale|date-fns formatDuration |Intl.NumberFormat|same?|");
console.log("|-|-|-|-|");

Object.values(locales)
  .sort((a, b) => a.code.localeCompare(b.code))
  .forEach((locale) => {
    const a = dateFnsFormat(locale);
    const b = intlFormat(locale.code)
      // some `fr` locales use non-breaking spaces
      .replace(String.fromCharCode(160), " ");
    const areSame = a === b ? "✅" : " ";

    console.log("|", locale.code, "|", a, "|", b, "|", areSame, "|");
  });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Date and time notation in the Czech Republic - Wikipedia
The Czech Republic hosts two different standardized forms of date and time writing. The Rules of Czech Orthography are mandatory for the educational...
Read more >
Dos and Don'ts: Time - Prague, Czech Republic - Expats.cz
In Czech it is půl osmé, i.e., half of the eighth hour. As with the earlier example the word for hour, hodina, is...
Read more >
Czech Style Guide - Inflectra Corporation
Additional Long Date. Format 2. N/A. Leading Zero in Day Field for Short Date Format. No ... Time. Country/region. Czech Republic. 24 hour...
Read more >
Czech Republic Employment Law - Replicon
The on-call time during which work is not performed shall not be included in working hours. Act No. 262/2006 Coll., Labour Code, §...
Read more >
DateTime::Format::CLDR issues parsing long Czech dates
What am I doing wrong? Why does it not parse the date? UPDATE. This is what I have actually been using to test...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found