jalaali / moment-jalaali Goto Github PK
View Code? Open in Web Editor NEWA Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.
License: MIT License
A Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.
License: MIT License
با سلام.
گزارش یه مورد کوچیک:
تو لیست ماه ها ، ماه پنجم به جای "مرداد" نوشته شده: "امرداد"
(یعنی یه الف اولش اضافه داره)
با تشکر
I suggested to publish the min version of moment-jalaali.js
Is it possible to add the moment-jalaali version to moment-jalaali.js file ?!
Adding jalali-moment caused crashing browser when clicking on datetimepicker (https://eonasdan.github.io/bootstrap-datetimepicker)
it returns true in some invalid dates
moment('13922115', 'jYYYYjMMjDD').isValid() returns 'true'
supported? ('jW', etc.)
This (with day set to zero)
moment('1393/11/00', 'jYYYY/jMM/jDD').isValid();
returns true, is this correct ?!
Is there a way that we can integrate this package with amMoment and use it in angular projects?
سلام
ری-اکشن-کامرس یک نرم افزار فروشگاهی جدیده که توسعهدهندههاش از Moment.js برای تقویمش استفاده کردن، اما تجربه چندانی با تقویم زبانهای دیگه ندارن. اگر ممکنه بهشون مشورت بدین که این امکان رو اضافه کنن که بشه این تقویم جلالی رو هم بسادگی در برنامه شون فعال کرد.
تیمشون روی لینک زیر معمولا فعال هستند:
https://gitter.im/reactioncommerce/reaction
و برنامه شون هم به صورت متن باز روی گیتهاب در حال توسعه است:
https://github.com/reactioncommerce/reaction-core
https://github.com/reactioncommerce/reaction
نرمافزار Reaction طراحی و قابلیت های مدرنی داره و آماده شده نسخه بتای خودش رو منتشر کنه. این نرمافزار با Meteor نوشته شده و از RTL هم پشتیبانی میکنه. تا حالا به عربی و عبری هم ترجمه شده.
Actual Behaviour :
Right now when you call the daysInMonth method on a jalaali date it returns the maximum days of the Gregorian months ex. 31 and 30 or 28 .
Appropriate Behaviour would be to return the correct days in Shamsi Calender like 31 and 30 for first half and last half of the year and 29 for the last month where the year is a leap year.
The jalai validation isValidJalaaliDate accepts years which are less than zero ``jy >= -61 && jy <= 3177`
is it correct?!
It would be great if you could prepend j to d, dd, ddd, dddd to return persian days of the week without needing to load the persian language
Hi, Thanks for Great Plugin, very usefull,
i want to use this for below plugin, but when i call js to project code, after click on calendar button my browser is going to stop,
https://github.com/Eonasdan/bootstrap-datetimepicker
<script src="js/jquery-2.1.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
<script src="js/datepicker/moment.min.js"></script>
<script src="js/datepicker/moment-jalaali.js"></script>
<script src="js/datepicker/fa.js"></script>
<script src="js/datepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript">
$(function () {
var dateNow = new Date();
$('#datetimepicker2,#datetimepicker3').datetimepicker({
locale: 'fa',
defaultDate:dateNow,
format: 'YYYY-MM-DD'
});
});
can you help me.
best regards.
متاسفانه خروجی شامل اعداد با کدهای انگلیسی است و مناسب است که به کدهای فارسی تبدیل شود
*_راهکارهای دیگر
*_استفاده از لوکال-مومنت به جای مومنت علاوه بر افزایش حجم سربار باعث نمایش وارنینگ می شود
*_شیوه اصلاح
*_مشابه لوکال-مومنت می توان با استفاده از دو متد زیر اعداد را قبل از ورود تبدیل به انگلیسی کرد (برای پردازش های داخلی) و قبل از خروج با کدهای فارسی جایگزین نمود.
preparse
و postformat
hi, thanks alot for this library, but when I use it in requireJs, I face with the following error.
error: 'moment is not defined'
code lines:
require.modules = {
moment: { exports: moment }
};
I encountered an error while I was concatenating my libs (one of them being moment-jalali), and it turned out that the missing semicolon at the end of the file was the issue. I came here to fix it but it seems it's already fixed in #28 . However the content of build directory doesn't seem to be generated from last versions of builder because it lacks that semicolon.
It seems a bit strange cause the last update date is 4 months ago for build directory and 8 months ago for builder! Maybe that was a manual update of build directory.
How I can Convert Jalali parsed date to Gregorian date?
This is a good library, however we need our application to be a little more dynamic i.e. we need to let the user switch between calendar systems. With the current version of moment-jalaali it is only possible through a lot of conditional development i.e. one needs to check for the flag and call the appropriate method (e.g. year or jYear) with the appropriate arguments (mostly formatting).
Following issue #30 I have a proposal.
I would suggest using a flag as well as the custom methods, so the following conditions would be true:
var dt = new moment(Date.now(), 'll', 'en', moment.SYSTEM.JALALI),
currentJalaliYear = 1394,
currentGregorianYear = 2015;
dt.year() == currentJalaliYear;
dt.format('YYYY') == currentJalaliYear;
dt.switchSystem(moment.SYSTEM.GREGORIAN); // Changes the calendar system to Gregorian
dt.year() == currentGregorianYear;
dt.format('YYYY') == currentGregorianYear;
dt.jYear() == currentJalaliYear;
dt.format('jYYYY') == currentJalaliYear;
dt.gYear() == currentGregorianYear;
dt.format('gYYYY') == currentGregorianYear;
Of course the formatting is just a suggestion which I suspect may even conflict with the week year tokens.
Hi,
First I wanna thank you for the great work. It's really useful.
I tried to extend the library using the conventional methods of prototyping and came across multiple infinite loops caused by using this
to access original moment methods line year
, month
and date
. As an example I reffer you to master/index.js#L578:
j = toJalaali(this.year(), this.month(), this.date())
This makes it impossible to override these methods with new ones that use the base method. i.e.
function myMoment() {
return makeMoment();
}
extend(myMoment, moment);
myMoment.fn.year = function() {
if (this.isJalali)
return moment.fn.jYear.apply(this, arguments); // Infinite Loop
return moment.fn.year.apply(this, arguments); // Infinite Loop
}
function makeMoment() {
var m = new moment();
function Fn() {};
Fn.prototype = myMoment.fn
extend(Fn, m);
return new Fn;
}
Hi,
I pulled your repo via bower and tried to use moment.loadPersian()
in my script. It gives me the following error:
Uncaught TypeError: undefined is not a function
سلام.
ممنون از افزونه بسیار عالیتون.
اما من یه مشکل باهاش دارم.
وقتی یه تاریخ انتخاب میکنم و میخوام نمایشش بدم روز آخر اون ماه رو نشون میده.
مثلا من 14 تیر 92 رو انتخاب میکنم
ولی موقع نمایش تو جدول 31 تیر 92 رو برمیگردونه.
یه سرچ کردم ولی مث اینکه دیگران این مشکلو نداشتن
و جالبه بدونین که تو کنسول وقتی نمایشش میدم این آبجکت رو نشون میده:
_d: Thu May 21 2009 23:59:59 GMT+0430 (Iran Daylight Time)
_f: "YYYY-MM-DD---"
_i: "2009-05-08---"
_isAMomentObject: true
_isUTC: false
_isValid: true
_jDiff: 0
که _i همون تاریخیه که من میخوام
اما _d لحظه ی آخر ماه انتخابی منه که نشونش میده تو جدول
یه دنیا مرسی
moment 2.10.3
moment-jalaali 0.3.8
ممنون میشم راهنماییم کنین
after struggling for many hours on this:
moment.unix(timestamp/1000).format('jYYYY/jM/jD')
i found that simply it does not work. but this one do:
moment(Date(timestamp)).format('jYYYY/jM/jD')
even after calling moment.loadPersian()
the outcome of the format()
has latin digit characters.
I think this is wrong. In fact even digits should be converted to their corresponding arabic/farsi equivalent.
However making this a default behaviour will have backwards-compatibility issues, so what I suggest is an option to the loadPersian()
method:
moment.loadPersian = function(convertNumbers = false)...
here is a code I'm using to do the conversion. (could potentially be optimised for performance, although I doubt that would even be an issue)
// replcae digits
for (var i = 0; i < 10; i++) {
res = res.replace(new RegExp(i.toString(), 'g'), String.fromCharCode(0x06F0 + i));
}
which converts 27 اردیبهشت 1394
to ۲۷ اردیبهشت ۱۳۹۴
I tried to use this moment.js extension with bootstrap-datetimepicker, but when tried to add this library, the page goes into a loop and crashed. How can I resolve this issue and what's the correct way to add "moment.jalaali.js"? This is how I added the package into my page:
<script src="/Scripts/Libraries/moment.js"></script>
<script src="/Scripts/Libraries/moment.jalali.js"></script>
<script src="/Scripts/Plugins/datetimepicker.js"></script>
<script type="text/javascript">
$(document).ready(function () {
moment().format('jYYYY/jM/jD');
var m = moment('1366/2/18', 'jYYYY/jM/jD')
// It shows the following alert:
alert(m.format('jYYYY/jM/jD [is] YYYY/M/D'));
$('#birth-date').datetimepicker({
});
});
</script>
سلام ممنون از پلاگین مفیدتون
من از مومنت جی اس برای دیت پیکر متریال استفاده می کنم.
ولی وقتی
moment-jalaali.js
به صفحه اضافه می کنم دیت پیکر کار نمیکنه و خطای زیر رو توی کنسول مرورگر میاره
Uncaught TypeError: string.indexOf is not a function moment-jalaali.js:705
در ضمن اینم بگم که این دیت پیکر با همین سایت مومنت جی اس کار میکنه
.از سازنده ی دیت پیکر پرسیدم گفت خطا از مومنت جلالی جی اس هست و باید از شما بپرسم
ممنون
اسکرین شات مشکلتغیر تاریخ مشکل دارد
برای مثال :اگراز تاریخ 1394/12/1بخواهیم به ماه بعد تبدیل کنیم به جای تبدیل به 1395/1/1 ، به تاریخ 1394/12/29 تبدیل میشود . !!!
چرا؟؟
I found that the moment jalaali moment works for years less than 3177. Is it a must ?!
I am using moment isValid, isSame , and other functions which get user input directly, and it is possible that user enters some invalid date. Although I can check user date manually, but I want to know if the plugin can accept larger years, may be up to 9999 !
i get this error:
Uncaught ReferenceError: module is not defined
When I call moment('4444/12/12', 'jYYYY/jMM/jDD').isValid()
I did not get false as return, instead I see Error: Invalid Jalaali year 4444
in the console log.
Shouldn't the invalid year cause the validate to return false?!
Hi
I used FullCalendar in my project and tried to change in jalali but FullCalendar's new version used moment.js . how can i use moment-jalali in FullCalendar latest version?
the moment's endOf function don't work , it just returns the current time
moment().endOf('jMonth')
i think you never add jalaali units to the moment using addUnitAlias because when i comment the line that checks aliases the function wroks as expected :
function endOf (units) {
//units = normalizeUnits(units);
if (units === undefined || units === 'millisecond') {
return this;
}
return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
}
سلام و وقت بخیر
اول خواستم تشکر کنم و دوم اینکه من وقتی کد جاوا جلالی رو بارگذاری میکنم مرورگر کلا هنگ میکنه لطفا راهنمایی کنید
ممنون
<!DOCTYPE html>
<html>
<head>
<title>jalali moment </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/jquery-1.11.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/moment.min.js"></script>
<script src="js/moment-jalaali.js"></script>
<script src="js/bootstrap-datetimepicker.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar">X</span>
</span>
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
moment().format('jYYYY/jM/jD')
$('#datetimepicker1').datetimepicker( );
});
</script>
</div>
</div>
</body>
</html>
isn't it a good idea to be able to set a global configuration (moment.useJalaali()
or something) and use the regular moment API, as then moment see's the world form Jalaali view
it is useful for external libraries that use moment api to make them jalaali compatible
با سلام خدمت دوست عزیز
شاید این موضوع خیلی هم مهم نباشد ولی خواستم اشاره ای داشته باشم شاید برای شما مهم باشد.
نام گذاری شما برای نام این گاهشمار به جلالی اشتباه است.
همانگونه که شما هم میدانید گاهشماری فعلی و رسمی ایران گاهشمار هجری خورشیدی است که در انگلیسی با نام
Persian Calendar
میشناسند و در واقع گاهشمار جلالی یک گاهشمار با مبنای شروع تاریخ متفاوت و حتی طول ماهها و حتی نام ماههای متفاوتی است.
گاهشمار رسمی ایران نحوه محاسبه بر مبنای همان گاه شمار جلالی است با این تفاوت که مبنای شروع تاریخ و طول ماهها و همچنین نام ماههای متفاوتی دارد.
Salaam
In original moment
constructor has 4 arguments. but in moment-jalaali
get 3 arguments. Please add strict
argument
See moment code: https://github.com/moment/moment/blob/develop/moment.js#L1736
Salaam
Is it possible to add jalaaliAsDefault
option. for example:
moment.jalaaliAsDefault();
m = moment('1360/5/26', 'YYYY/M/D') // Parse a Jalaali date
m.format('YYYY/M/D') // 1360/5/26
m.Year() // 1360
m.Month() // 4
m.Date() // 26
m.DayOfYear() // 150
m.Week() // 22
m.WeekYear() // 1360
m.add(1, 'Year')
m.add(2, 'Month')
m.format('YYYY/M/D') // 1361/7/26
m.Month(11)
m.startOf('Month')
m.format('YYYY/M/D') // 1361/12/1
m.Year(1392)
m.startOf('Year')
m.format('YYYY/M/D') // 1392/1/1
m.subtract(1, 'Year')
m.subtract(1, 'Month')
m.format('YYYY/M/D') // 1390/12/1
moment.jalaaliAsDefault(false);
m = moment('1360/5/26', 'jYYYY/jM/jD') // Parse a Jalaali date
m.format('jYYYY/jM/jD [is] YYYY/M/D') // 1360/5/26 is 1981/8/17
this feature help us to simply change other libraries in order to support jalaali. for exampl Eonasdan/bootstrap-datetimepicker
Installing with via bower ends with this error:
bower ENOTFOUND Package moment/moment=moment/moment not found
Any comments ?!
Regards,
Alireza Fayttahi
in the build/moment-jalaali.js
file, there is no ;
at the end (there is one at the begining!).
this make my dev environment sad (which files are concatenated automatically, etc).
HI , Great plugin . Hww do I use moment.loadPersian() to display result of moment(new Date()).format('jYYYY/jM/jD'); in farsi ?
Thanks
سلام برنامه شما دارای مشکل است
var sample1 = moment('1360/5/26', 'jYYYY/jM/jD HH:mm');
var sample2 = moment('1394/9/24 14:59', 'jYYYY/jM/jD HH:mm').format('YYYY-M-D HH:mm:ss'); // 2013-8-25 16:40:00
var sample3 = moment('2015-12-13 14:00:00', 'YYYY-M-D HH:mm:ss').endOf('jMonth').format('jYYYY/jM/jD HH:mm:ss'); // 1392/6/31 23:59:59
console.log("sample2 : " + sample2);
Output Console:
sample2 : 2015-12-15 14:59:00
2 روز بیشتر نشون میده
در تبدیل به شمسی 8 روز اختلاف هست
سلام
لحظه آخر برخی از سالها رو اشتباه برمیگردونه.
مثلا تاریخ زیر به درستی 1388/12/29 برگردانده میشه
console.log(moment(1388 + '-' + 1 + '-' + 1, 'jYYYY-jM-jD').endOf('jYear').format('jYYYY/jM/jD'));
ولی بعضی سالها به جای آخر سال ، اول سال بعد رو برمیگردونه مثل سالهای 1378و1389و1395
و1400و1406و1412و1417و....
مثلا تاریخ زیر به اشتباه 1390/1/1 برگردانده میشه
console.log(moment(1389 + '-' + 1 + '-' + 1, 'jYYYY-jM-jD').endOf('jYear').format('jYYYY/jM/jD'));
hi
if we have :
var dd = moment('1392/1/1','jYYYY/jMM/jDD');
then this is not work:
dd.add(1,'d')
but this is work:
dd.add(2,'d')
سلام
بهتر نیست از کلمات پرکاربردتر مثل جمعه
به جای آدینه
و مرداد
به جای امرداد
استفاده بشه؟
با سلام
من در پروژه ام از ابزار
gulp
برای یکپارچه سازی فایلهای جاوا اسکریپت استفاده می کنم.
ولی وقتی پروژه را به سرور منتقل می کنم خطایی می دهد که متوجه شدم باید عبارت
use strict
را در کتابخانه شما اضافه کنم. ولی بعد خطا می دهد که
Uncaught TypeError: Cannot set property 'moment' of undefined
روی خط ۱۱۴۰ برنامه.
اگر ۶ خط آخر برنامه را حذف کنم دیگر خطا نمی دهد ولی مسلما برنامه درست کار نمی کند.
در صورت امکان راهنمایی بفرمایید بعد از اضافه کردن
use strict
چه تغییر دیگری باید در کتابخانه شما بدهم.
جهت اطلاع قبل از یکپارچه سازی برنامه بخوبی کار می کند.
با تشکر
I am not sure whether or not this is because Esfand is one day shorter than the rest, but when adding months that span across a year, the date is calculated incorrectly, as demonstrated by the failing test below:
it('adds the correct number of months to the given date', function () {
var m = moment("1393-04-08", "jYYYY-jMM-jDD");
m.format("jMM").should.equal("04");
m.add(9, 'jMonth');
m.format("jYYYY-jMM-jDD").should.equal("1394-01-08"); //actually is '1394-01-09'
});
سلام.
من از این افزونه ی شما تو کدم استفاده میکنم.
(angular and mvc and web api )
اما یه مشکلی دارم.
تاریخی که ثبت میکنم یک روز زودتر برمیگردونه.
مثلا من در فیلدهای فرمم 23 تیر 94 رو انتخاب میکنم
و وقتی ثبت رو میزنم 22 تیر 94 رو برمیگردونه.
میشه یه بررسی کنید ببینید مشکل کد من از کجاست؟
این نمونه ی کد اسکریپت من:
// تاریخ شروع سال
$scope.FirstYears = [];
$scope.FirstMonths = [];
$scope.FirstDays = [];
$scope.selectedFirstYear = today.jYear();
$scope.selectedFirstMonth = today.jMonth() + 1;
$scope.selectedFirstDay = today.jDate();
$scope.YearFirstDate = moment($scope.selectedFirstYear + '-' + $scope.selectedFirstMonth + '-' + $scope.selectedFirstDay, 'jYYYY-jM-jD');
for (var i = 1350; i <= 1450; i++) {
$scope.FirstYears.push({ id: i, text: i.toString() });
};
$scope.FirstMonths = [
{ id: 1, text: 'فروردین' },
{ id: 2, text: 'اردیبهشت' },
{ id: 3, text: 'خرداد' },
{ id: 4, text: 'تیر' },
{ id: 5, text: 'مرداد' },
{ id: 6, text: 'شهریور' },
{ id: 7, text: 'مهر' },
{ id: 8, text: 'آبان' },
{ id: 9, text: 'آذر' },
{ id: 10, text: 'دی' },
{ id: 11, text: 'بهمن' },
{ id: 12, text: 'اسفند' }
];
$scope.generateFirstDays = function () {
$scope.YearFirstDate = moment($scope.selectedFirstYear + '-' + $scope.selectedFirstMonth + '-' + $scope.selectedFirstDay, 'jYYYY-jM-jD');
if ($scope.YearFirstDate.isValid()) {
$scope.endOfSelectedFirstMonth = $scope.YearFirstDate.clone().endOf('jMonth').format('jD');
$scope.FirstDays.splice(0, 31);
for (var i = 1; i <= $scope.endOfSelectedFirstMonth; i++) {
$scope.FirstDays.push({ id: i, text: i.toString() });
}
}
else {
$("#FirstDayInput").select2("val", $("#FirstDayInput").val() - 1);
$scope.selectedFirstDay --;
$scope.generateFirstDays();
}
}
$scope.generateFirstDays();
$("#FirstYearInput").select2({
data: { results: $scope.FirstYears, text: 'text' },
formatNoMatches: 'ورودی نامعتبر'
});
$("#FirstMonthInput").select2({
data: { results: $scope.FirstMonths, text: 'text' },
formatNoMatches: 'ورودی نامعتبر'
});
$("#FirstDayInput").select2({
data: { results: $scope.FirstDays, text: 'text' },
formatNoMatches: 'ورودی نامعتبر'
});
$("#FirstYearInput").on("change", function (e) {
$scope.selectedFirstYear = e.val;
$scope.generateFirstDays();
});
$("#FirstMonthInput").on("change", function (e) {
$scope.selectedFirstMonth = e.val;
$scope.generateFirstDays();
});
$("#FirstDayInput").on("change", function (e) {
$scope.selectedFirstDay = e.val;
$scope.generateFirstDays();
});
// ثبت
$scope.btnSubmit = function (record, index) {
$scope.newRecord = {
InvYear: $scope.InvYear,
YearFirstDate: $scope.YearFirstDate,
YearEndDate: $scope.YearEndDate
};
if ($scope.newRecord.InvYear) {
$http.post("http://localhost:35621/api/YearApi", $scope.newRecord).success(function (response) {
if (response == 0) {
$scope.getWholeData();
}
});
}
};
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.