Skip to content

Add formatDuration function#1671

Merged
kossnocorp merged 66 commits intomasterfrom
format-duration
May 10, 2020
Merged

Add formatDuration function#1671
kossnocorp merged 66 commits intomasterfrom
format-duration

Conversation

@kossnocorp
Copy link
Copy Markdown
Member

@kossnocorp kossnocorp commented Mar 14, 2020

Add formatDuration function that allows formatting Duration object as a human-readable string, i.e.:

formatDuration({ years: 0, months: 9 })
//=> '9 months'

formatDuration({ years: 0, months: 9 }, null, { zero: true })
//=> '0 years 9 months'

formatDuration({ years: 2, months: 9, weeks: 3 }, { delimiter: ', ' })
//=> '2 years, 9 months, 3 weeks'

A big part of this pull-request is adding weeks to locale's formatDistance. Meaning we have to update every locale before we can ship this PR 😱

🚧 Locales to update

  • Afrikaans af locale
  • Arabic ar-DZ locale (Algeria)
  • Arabic ar-MA locale (Moroccan)
  • Arabic ar-SA locale (Sauid Arabic)
  • Azerbaijani az locale
  • Bulgarian bg locale
  • Bengali bn locale
  • Catalan ca locale
  • Czech cs locale
  • Welsh cy locale
  • Danish da locale
  • German de locale
  • Greek el locale
  • English en-AU locale (Australia)
  • English en-CA locale (Canada)
  • English en-GB locale (UK)
  • English en-US locale (USA)
  • Esperanto eo locale
  • Spanish es locale
  • Estonian et locale
  • Persian/Farsi fa-IR locale (Iran)
  • Finnish fi locale
  • French fr locale
  • French fr-CA locale (Canada)
  • Galician gl locale
  • Gujarati gu locale
  • Hebrew he locale
  • Hindi hi locale
  • Croatian hr locale
  • Hungarian hu locale
  • Armenian hy locale
  • Indonesian id locale
  • Icelandic is locale
  • Italian it locale
  • Japanese ja locale
  • Georgian ka locale
  • Kazakh kk locale
  • Korean ko locale
  • Lithuanian lt locale
  • Latvian lv locale
  • Macedonian mk locale
  • Malay ms locale
  • Maltese mt locale
  • Norwegian Bokmål nb locale
  • Dutch nl locale
  • Norwegian Nynorsk nn locale
  • Polish pl locale
  • Portuguese bt-BR locale (Brazil)
  • Romanian ro locale
  • Russian ru locale
  • Slovak sk locale
  • Slovenian sl locale
  • Serbian cyrillic sr locale
  • Serbian latin sr-Latn locale
  • Swedish sv locale
  • Tamil ta locale (India)
  • Telugu te locale
  • Thai th locale
  • Turkish tr locale
  • Uighur ug locale
  • Ukrainian uk locale
  • Uzbek uz locale
  • Vietnamese vi locale
  • Chinese Simplified zh-CN locale
  • Chinese Traditional zh-TW locale

threeToTen: '{{count}} أشهر', // TODO
other: '{{count}} شهر' // TODO
},

Copy link
Copy Markdown
Member Author

@kossnocorp kossnocorp Mar 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@date-fns/i18n-ar-dz @date-fns/i18n-ar-sa hey, we're adding weeks to formatDistance. Please take a look 🙏 It shouldn't take more than a few minutes. Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arabic ar-SA locale (Sauid Arabia) is done.

threeToTen: '{{count}} أشهر', // TODO
other: '{{count}} شهر' // TODO
},

Copy link
Copy Markdown
Member Author

@kossnocorp kossnocorp Mar 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@date-fns/i18n-ar-dz @date-fns/i18n-ar-sa hey, we're adding weeks to formatDistance. Please take a look 🙏 It shouldn't take more than a few minutes. Thanks!

threeToTen: '{{count}} أشهر', // TODO
other: '{{count}} شهر' // TODO
},

Copy link
Copy Markdown
Member Author

@kossnocorp kossnocorp Mar 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@date-fns/i18n-ar-dz @date-fns/i18n-ar-sa hey, we're adding weeks to formatDistance. Please take a look 🙏 It shouldn't take more than a few minutes. Thanks!

Copy link
Copy Markdown
Member Author

@kossnocorp kossnocorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we can merge it, we have to update all v2 locales.

Comment thread src/locale/af/_lib/formatDistance/index.js
Comment thread src/locale/az/_lib/formatDistance/index.js
Comment thread src/locale/bg/_lib/formatDistance/index.js
Comment thread src/locale/bn/_lib/formatDistance/index.js
Comment thread src/locale/ca/_lib/formatDistance/index.js
Comment thread src/locale/uk/_lib/formatDistance/index.js
Comment thread src/locale/uz/_lib/formatDistance/index.js
Comment thread src/locale/vi/_lib/formatDistance/index.js
Comment thread src/locale/zh-CN/_lib/formatDistance/index.js
one: '1 個月', // TODO
other: '{{count}} 個月' // TODO
},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@date-fns/i18n-zh-tw hey, we're adding weeks to formatDistance. Please take a look 🙏 It shouldn't take more than a few minutes. Thanks!

@kossnocorp
Copy link
Copy Markdown
Member Author

Please forgive me for spamming, but I couldn't find any better way to handle this. I hope you didn't receive every comment as a separate email. If so, I'm double sorry and RIP your inbox.

@emil9453
Copy link
Copy Markdown
Contributor

emil9453 commented Apr 15, 2020 via email

Copy link
Copy Markdown
Contributor

@imballinst imballinst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kossnocorp added my suggestions related to the id locale. Thanks for the kind notification!

Comment thread src/locale/id/_lib/formatDistance/index.js
Comment thread src/locale/id/_lib/formatDistance/index.js
Comment thread src/locale/el/_lib/formatDistance/index.js Outdated
Comment thread src/locale/el/_lib/formatDistance/index.js Outdated
Comment thread src/locale/da/_lib/formatDistance/index.js
Comment thread src/locale/fr/_lib/formatDistance/index.js
Comment thread src/locale/fr-CH/_lib/formatDistance/index.js
Comment thread src/locale/ug/_lib/formatDistance/index.js
@kbrabrand
Copy link
Copy Markdown
Contributor

kbrabrand commented Apr 15, 2020

@kossnocorp Was a bit unsure how you wanted this, but I've fixed the Norwegian locales (nb and nn) by pushing commits to the PR branch, and updated your PR comment.

Comment thread src/locale/ja/_lib/formatDistance/index.js
@kossnocorp
Copy link
Copy Markdown
Member Author

@kbrabrand that's perfect, thank you!

Comment thread src/locale/uz/_lib/formatDistance/index.js
@Pyppe
Copy link
Copy Markdown
Contributor

Pyppe commented Apr 16, 2020

Added Finnish locale in 353d0db

Comment thread src/locale/it/_lib/formatDistance/index.js Outdated
Comment thread src/locale/it/_lib/formatDistance/index.js Outdated
Comment thread src/locale/it/_lib/formatDistance/index.js Outdated
Comment thread src/locale/it/_lib/formatDistance/index.js Outdated
@sibiraj-s
Copy link
Copy Markdown
Member

sibiraj-s commented Apr 16, 2020

@kossnocorp here for tamil locale #1725

gpetrioli
gpetrioli previously approved these changes Apr 22, 2020
@gpetrioli gpetrioli dismissed their stale review April 22, 2020 14:36

was accidental, i wanted to approve a single commit

@kossnocorp
Copy link
Copy Markdown
Member Author

Thanks, everyone for helping, I finally finished all locales (some with the help of Google Translate, so thanks to it as well!)!

You're all awesome, have a great weekend!

@kossnocorp kossnocorp merged commit 2108814 into master May 10, 2020
@kossnocorp kossnocorp deleted the format-duration branch May 10, 2020 11:01
This was referenced May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.