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

Non-Arabic Numerals #416

Closed
bcmn opened this issue Nov 27, 2018 · 4 comments
Closed

Non-Arabic Numerals #416

bcmn opened this issue Nov 27, 2018 · 4 comments

Comments

@bcmn
Copy link

bcmn commented Nov 27, 2018

Our specific use case requires for conditionally displaying "eastern arabic numerals" ۰۱۲۳۴۵۶۷۸۹ instead of "arabic numerals" 0123456789. Presumably any implementation would be intended to be easily extensible for any other commonly-used base 10 numeral systems.

This would result in DayJS strings like:

۲۸ آوریل ۲۰۱۸
پیش ساعت ۴

instead of (the current behaviour):

28 آوریل 2018
پیش ساعت 4

This issue is primarily to ascertain whether this is something that other people would feel is useful or necessary to have as a plugin for DayJS, though there are also some implementation issues that might be useful to discuss.

Obviously the alternative is that this could remain a bespoke implementation detail, & our project just treats this as a generic string formatting operation, completely unaware of DayJS.


Implementation Thoughts

After a quick investigation, I'm not sure DayJS currently has a way of applying this sort of library-wide formatting operation to all strings returned?

It is very easy to add the behaviour to any one function, e.g. .format or the overridden .format function of the advancedFormat plugin, but this would very noticeably miss applying the logic to other plugins, such as relativeTime. Is there a better solution than this?

I'm aware advancedFormat currently uses binding to achieve some conditional formatting. There may be a way to do this for all plugins that might return a string containing a numeral, but it doesn't seem ideal. 🤔

@iamkun
Copy link
Owner

iamkun commented Dec 17, 2018

You may could extend advancedFormat by adding your own tokens, like DEMO.

import advancedFormat from 'dayjs/plugin/advancedFormat' 
import youOwnFormat from 'dayjs/plugin/youOwnFormat' 
dayjs.extend(advancedFormat) 
dayjs.extend(youOwnFormat) 
dayjs().format('DEMO YYYY - MM') 

@ghost
Copy link

ghost commented Feb 11, 2019

@bcmn You might could simply do a global replace('1234', '۰۱۲۳۴۵۶۷۸۹') on the final format result .

This might be easy and without a dayjs plugin.

@VehpuS
Copy link
Contributor

VehpuS commented Jan 2, 2021

@bcmn - If still relevant, I believe #1255 solves this issue (at least that's how it's done in moment.js).

@iamkun
Copy link
Owner

iamkun commented Jan 3, 2021

@VehpuS great job, THX. I think we could mark this issue as fixed

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

3 participants