Comments (5)
Dear amir mohammad
I think you have set the locale globally like moment.locale('fa')
try the following code
let fromNow = moment.from("2018-10-25T13:20:00+00:00", 'en').locale('fa').fromNow()
console.log(fromNow)
from jalali-moment.
Can we discuss more on this @fingerpich ?
I think as ISO Date is a standard date format, it might be better to not treat it as locale date, but a standard date in 'en'
locale.
I say this because it's very common to use this standard to get date/time from db/server and show it in locale format, and using it like below, might add a lot of moment.from(time, 'en').locale('fa')
into code instead of simply moment.from(time)
when time is ISO standard and locale is already globally sat.
let fromNow = moment.from("2019-01-17T08:19:19.975Z", 'en').locale(currentActiveLocale).fromNow()
console.log(fromNow)
Yet I found nothing about this in moment docs, and didn't check other calendar implementations of moment.js.
I have created a branch with a sample code to fix this on my fork, but it's better to know your opinion about it, then I create pull request for that.
from jalali-moment.
I generally agree with you, in jalali-moment
, 'fa' locale is using total different calendar, so parsing dates also happen in same 'fa' calendar (and locale).
Can we make this as an option? Like user can configure jalali-moment
to use gregorian calendar for parser even when locale is set to 'fa' and formatter is using Persian calendar?
moment.locale('fa', { useGregorianParser: true });
// use it everywhere like:
moment("2019-01-17T08:19:19.975Z").format("YYYY MM DD"); // "1397 10 27"
This will save our UI code base a lot of repetitive code, as right now I have two options:
moment.locale(navigator.language); // lets assume it's 'fa'
// use it everywhere like
moment(new Date("2019-01-17T08:19:19.975Z")).format("YYYY MM DD"); // "1397 10 27"
or
moment.locale('en');
// use it everywhere like
moment("2019-01-17T08:19:19.975Z").locale(navigator.language).format("YYYY MM DD"); // when navigator.language is 'fa' -> "1397 10 27"
Or even it gets better if moment
accepts other calendar implementations and gets configured by locale options like:
import moment from 'moment';
moment.locale('fa', { useNativeCalendarFormatter: true, useNativeCalendarParser: false });
and this will be huge benefit when we want to support users from Arabic countries with pretty native Islamic calendar.
// no need to import other moment plugin as npm packages
moment.locale('ar', { useNativeCalendarFormatter: true, useNativeCalendarParser: false });
Because right now I have to create a wrapper around moment
, jalali-moment
and something like moment-hijri
to support all these different calendars for MiddleEast users.
``
from jalali-moment.
Yes it is a good idea and helpful if we consider that without this option it should do the same thing as before. if you can create a pull request and i will help you.
About moment I think its more than this as you can see in this issue
from jalali-moment.
Thanks a lot
but as long as you didn't change the global locale you can use it as easy as the following code
let fromNow = moment("2019-01-17T08:19:19.975Z").locale('fa').fromNow();
console.log(fromNow)
you know it's a rare thing that you need to change global locale to fa
for example when you have lots of code such as moment(specificDate)
and specificDate
are used to be a gregorian date but now it's going to be jalali date like the situation we have in converting a gregorian calendar to shamsi calendar, we don't want to change all those codes so we can easily change the global locale and it works.
So when you need to change the global locale to fa
you have to use method from
for parsing the gregorian dates.
from jalali-moment.
Related Issues (20)
- Convert a Unix timestamp to moment HOT 1
- jalali diff not working on different server & client timezone HOT 2
- Gregorian to Jalali HOT 1
- Angular 11, "CommonJS or AMD dependencies can cause optimization bailouts" warning HOT 3
- end of week HOT 1
- problem with ie11 HOT 3
- Use ECMAScript 6 import/export instead of CommonJS HOT 1
- jalali-moment with vite and vue not working HOT 4
- does it makes Grafana in Farsi or just for showing date in reports? HOT 1
- 27/1/1400 can be interpereted different in different time zones HOT 1
- add function not worked properly HOT 2
- ایراد نمایش در بخش ثانیه HOT 1
- After converting, the date always comes back one day off HOT 3
- moment deprecation HOT 1
- jalali_moment__WEBPACK_IMPORTED_MODULE_1___namespace_cache is not a function HOT 1
- timezone in 1402 is not correct ! HOT 4
- The `isSameOrAfter()` method does not return the expected result when comparing a Jalali date with a valid date.
- moment('1402-01-02', 'jYYYY-jMM-JDD').format('jYYYY-jMM-jDD') return 1402-01-01
- In the first six months of the year, the time is one hour behind.
- isValid has bug with string
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jalali-moment.