alibaba-aero / jalaliday Goto Github PK
View Code? Open in Web Editor NEWPersian (Jalali, Khorshidi) Plugin for Day.js
License: MIT License
Persian (Jalali, Khorshidi) Plugin for Day.js
License: MIT License
Please consider the sample:
import dayjs from 'dayjs';
import jalaliday from 'jalaliday';
dayjs.extend(jalaliday);
dayjs.calendar('jalali');
const date = dayjs('1367/02/23', { jalali: true })
const gregory = date.calendar('gregory')
const jalaliDate = date.calendar('jalali');
// Should be 1367/02/23, but is 1367/1/23
console.log(jalaliDate.year() + "/" + jalaliDate.month() +"/"+ jalaliDate.date());
// Should be 1988/05/13, but is 1988/4/13
console.log(gregory.year() + "/" + gregory.month() +"/"+ gregory.date());
This library calculates the conversion of dates incorrectly.
In the $set
method, the $d
property is being updated in this order:
setDate
setMonth
setFullYear
It causes unexpected results in certain cases like this one:
// 2019-11-01
dayjs('1398-08-10', { jalali: true })
.calendar('jalali')
.date(9)
The results should be 1398-08-09
but it becomes 1398-07-09
. This happens because setDate
is called first. Which depends on the current month value and if the given date exceeds the limit of that month, it goes to the next one.
We should reverse the order so that setDate
can be aware of the new month value.
Example for Bahman (1399/11/11):
const date = dayjs().calendar('jalali').locale('fa');
console.log('days =', date.daysInMonth());
for (let i = 1; i <= date.daysInMonth(); i++) {
console.log('day ' + (i < 10 ? '0' : '') + i + 'th = ' + date.format('DD'));
}
Output:
Hi there,
Just a quick reminder that there are two changes in 1.8.9 to our developers.
Date wrapper Utils.wrapper
could be overridden in the plugin.
The name of Utiles[*] has been changed to a shorter name in order to reduce the package size.
Cheers.
Hi,
I found out that this library uses an incorrect method for calculating leap years,
As an example:
This library shows Esfand month 1403 as 29 days, which is actually a 30-day month.
Additionally, I checked the jalaali-js library and found that it is calculating leap years correctly.
Demo:
https://js-r3ebqv.stackblitz.io
List of leap years (problem is with the leap before the five-year leap)
As an example, the year 1408 is a five-year leap, and the leap before this year is 1403. or the year 1441 is a five-year leap, and the leap before this year is 1436.
There is no support for five-year leap years in this plugin, and all leap years are based on four-year leap years.
وقتی ماه رو تنظیم میکنم برای ماه 12 دچار اشکال میشه.
`
dayjs().calendar('jalali').locale('fa').month(11).format('MMMM'); // فروردین
dayjs().calendar('jalali').locale('fa').month(0).format('MMMM'); // فروردین
dayjs().calendar('jalali').locale('fa').date(1).month(11).format('MMMM'); // اسفند
`
According to the following lines I believe Utils object keys aren't really correct. But I don't have any ideas about why this works in the tests.
https://github.com/iamkun/dayjs/blob/dev/src/index.js#L43
https://github.com/iamkun/dayjs/blob/dev/src/utils.js#L45
Hello @pi0
Please add more doc for jalaliday
And
Do not be tired ....
when I try to use jalaliday in a specific component I realize it converts my Jalali year 1399 to gregorian 3263 instead of 2020.
as I check more I find out its a combination of webpack and your library problem.
when someone import jalalidate in multiple modules in one special hierarchy and extend the original dayjs this library keep adding extra year in date convert process for example if I use this:
import dayjs from 'dayjs';
import jalaliday from 'jalaliday';
dayjs.extend(jalaliday);
dayjs.extend(jalaliday);
dayjs.extend(jalaliday);
the final result of dayjs(
1399-08-08, { jalali: true });
will be 4505
as you add more extend it add 621 years to the resulting year
3263->3884->4505->....
i think there must be a solution that multiple extend won't result in wrong date convert
hi,
When I want to change the date, the date is converted as follows and the same jalali date is returned
1400/05/07 => Thu May 08 1400 00:00:00 GMT+0325 (Iran Daylight Time)
const date = "1400/05/07"
dayjs(date ).calendar("gregory").locale("en")
Thanks for this lib.
but it seems there isn't any type definition for typescript types because when I use dayjs.calendar(...)
:
Property 'calendar' does not exist on type 'typeof import(".../node_modules/dayjs/index.d.ts")'.
I think you should extend the default dayjs's type definitions.
Day manipulation (add
and subtract
) methods don't work properly after extension. They reset the date to 1970-01-01.
I've created a sandbox to reproduce the issue here.
Version: 2.2.2
When I pass 2025/03/20, It gives back "1404/1/1" and it's wrong. It should return "1403/12/30"
امسال با توجه به اینکه ساعت را عقب نکشیدن ساعت خروجی عبارت زیر اشتباه بر می گردد.
dayjs(2023-04-10T10:19:56+0430).calendar('jalali').locale('fa').format('HH:mm - YYYY/MM/DD')
نتیجه
09:19 - 1402/01/21
when I use time zone .tz() function , it converted to georgian
Currently what you get out of months()
method is dependant on locale
which is wrong.
It should depend on calendar
, and locale
should only define the language:
dayjs.locale('fa')
console.log(dayjs.calendar('jalali').months())
// outputs: ['فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند']
// Correct!
console.log(dayjs.months())
// outputs: ['فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند']
// Wrong! It should be ژانویه فوریه مارچ etc.
dayjs.locale('en')
console.log(dayjs.calendar('jalali').months())
// outputs: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
// Wrong! It should be Farvardin, Ordibehesht, etc.
console.log(dayjs.months())
// outputs: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
// Correct!
how i can convert jalali date to gregory ?
endOf
and daysInMonth
functions don't work when they are called inside the Esfand month of years with no extra leap day.
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.