Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abbreviated timespan formatter doesn't work for beyond a week #63

Open
krnwonseungee opened this issue Jun 30, 2015 · 1 comment
Open

Comments

@krnwonseungee
Copy link

Hi there, it seems that the TimespanFormatter abbreviated format does not work correctly for time spans beyond a week. Wondering if this was intentional by design?

Works correctly:
tsf.format(400000, {direction: "none", type: "abbreviated"}) "5d"

tsf.format(500000, {direction: "none", type: "abbreviated"}) "6d"

tsf.format(600000, {direction: "none", type: "abbreviated"}) "7d"

Breaks:
tsf.format(700000, {direction: "none", type: "abbreviated"}) VM89:14 Uncaught TypeError: Cannot read property 'one' of undefined at t.eval (eval at <anonymous> (http://local-change.org:3000/public/js/changeAssets.js:11502:5), <anonymous>:14:8229) at t.e.TimespanFormatter.t.format (eval at <anonymous> (http://local-change.org:3000/public/js/changeAssets.js:11502:5), <anonymous>:14:8303) at <anonymous>:2:22 at Object.InjectedScript._evaluateOn (<anonymous>:895:140) at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34) at Object.InjectedScript.evaluate (<anonymous>:694:21)

@KL-7
Copy link
Contributor

KL-7 commented Jun 30, 2015

@krnwonseungee hey, it's definitely a bug, but it's a tricky one.

Looks like the problem is that if you don't specify units explicitly, TimespanFormatter tries to guess them and pick the largest one that fits into your time span. In your example it picks days for 1-7 days, but starting from 8 days it tries to format your time span in weeks. Unfortunately, we have data for abbreviated format only for days, but not for weeks, so it fails to return an abbreviated string once your time span is bigger than a week.

There are two possible workarounds here: either use short format (which is slightly longer than abbreviated) or pass day as desired time unit (examples are in Russian):

fmt.format(100000, {direction: "none", type: "short"}) // => "1 дн." - short for "1 day"
fmt.format(700000, {direction: "none", type: "short"}) // => "1 нед." - short for "1 week"

fmt.format(100000, {unit: "day", direction: "none", type: "abbreviated"}) // => "1 д"
fmt.format(700000, {unit: "day", direction: "none", type: "abbreviated"}) // => "8 д"

I'll definitely work on a permanent fix for the issue, but it might be a while before I get to it, so if either of the options above is acceptable for you, I'd suggest using it for the time being.

And thanks for reporting the bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants