piuccio / intl-unofficial-duration-unit-format Goto Github PK
View Code? Open in Web Editor NEWUnofficial implementation of time duration UnitFormat
Unofficial implementation of time duration UnitFormat
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch [email protected]
for the project I'm working on.
Some versions of Hermes can return literal values so this fix accounts for that
Here is the diff that solved my problem:
diff --git a/node_modules/intl-unofficial-duration-unit-format/index.js b/node_modules/intl-unofficial-duration-unit-format/index.js
index 3473329..704ff8d 100644
--- a/node_modules/intl-unofficial-duration-unit-format/index.js
+++ b/node_modules/intl-unofficial-duration-unit-format/index.js
@@ -107,7 +107,8 @@ DurationUnitFormat.prototype._formatValue = function (number) {
DurationUnitFormat.prototype._trimOutput = function (result, parts) {
const trimmed = trim(result, this.isTimer);
- if (!trimmed.find((_) => _.type !== 'literal')) {
+ // Accounts for Android Hermes limitation https://hermesengine.dev/docs/intl/#android-10-and-older-sdk--30
+ if (!trimmed.find((_) => _.type !== 'literal' || _.value.trim() !== '')) {
// if everything cancels out and there are only literals,
// then return 0 on the lowest available unit
const minUnit = [
This issue body was partially generated by patch-package.
When using the following options with de locale:
durationFormatOptions = {style: DurationUnitFormat.styles.NARROW, format: '{day} {hour}'}
days and hours abbreviations are in english i.e d and h instead of T and Std
[Update] it appears to also be in english for czech
Is it possible to have a double-digit hour without using the day for the TIMER style ?
When I use format: '{hour}:{minutes}' together with style TIMER, I get 1:43 but I would like 01:43
Thanks :)
In the following basic example:
import DurationUnitFormat from 'intl-unofficial-duration-unit-format';
const duration = new DurationUnitFormat(
[
'en-GB',
'en',
],
{
style: DurationUnitFormat.styles.TIMER,
},
);
// currently
console.log(duration.formatToParts(3500)); // [{"type":"minute","value":"58"},{"type":"literal","value":":"},{"type":"second","value":"20"}]
// ideal
console.log(duration.format(3500)); // '58:20'
Is there a way to get the above ideal output, without having to explicitly handle the formatToParts() returned object?
I can do it in the following way:
duration.formatToParts(3500).map(({ type, value }) => value).join('')
...but this feels inelegant, and doesn't match my expectations from using the other similar Intl.DateTimeFormat
, Intl.NumberFormat
etc, all of which have a format()
method.
Hello,
When building my app on android or IOS with react-native, I see this log warning:
warn Package intl-unofficial-duration-unit-format has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /Users/I543492/Documents/emobility/ev-mobile/node_modules/intl-unofficial-duration-unit-format/package.json
Do you have any hints ?
Also when running the test suite on GitHub, I see this error:
โ Test suite failed to run Cannot find module 'intl-messageformat' from 'node_modules/intl-unofficial-duration-unit-format/dist/cjs/duration-unit-format.cjs.js' Require stack: node_modules/intl-unofficial-duration-unit-format/dist/cjs/duration-unit-format.cjs.js src/I18n/I18nManager.tsx __tests__/I18nManagerTests.tsx at Resolver.resolveModule (node_modules/jest-runtime/node_modules/jest-resolve/build/index.js:306:[11](https://github.com/sap-labs-france/ev-mobile/runs/5406296843?check_suite_focus=true#step:7:11)) at Object.<anonymous> (node_modules/intl-unofficial-duration-unit-format/dist/cjs/duration-unit-format.cjs.js:3:25)
Can we have a new version released with the fix detailed in commit 8da2bb3? I would prefer referencing a version number rather than the commit SHA ๐.
Hello! It looks like the version coming in via npm is out of date as it has the NARROW style commented out. Can we get an updated version released?
Currently, if the numbers are too low (e.g., less than an hour), there is no way to have 0 values hidden. This may complicate things with a formatter because if there are no hours and {hours}, {minutes}
is chosen, one will be left with , 20 s
or such. I think therefore that the hideZeroValues
and fields
options are important for such cases in controlling what will be shown.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.