xsoh / moment-hijri Goto Github PK
View Code? Open in Web Editor NEWA Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js
Home Page: http://momentjs.com/docs/#/plugins/hijri/
License: MIT License
A Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js
Home Page: http://momentjs.com/docs/#/plugins/hijri/
License: MIT License
Trying to add it into my Angular 2 typescript project through npm install moment-hijri
but getting following error on terminal:
Cannot find module 'moment-hijri'
I have these parameters set in my tsconfig.json:
"module": "es6",
"moduleResolution": "node",
Also tried with module setting 'commonjs' and 'amd' but its the same error.
If moment-hijri
object is passed to DatePicker from antd as value
prop; then DatePicker errors because return of value.locale()
is undefined
minimal codes to reproduce
import moment from "moment-hijri";
import { DatePicker } from "antd";
export default const HijriDatePicker = (props) => {
return <DatePicker value={props.value} format="DD-MM-YYYY (iDD-iMM-iYYYY)" />
}
Here is CodeSandbox link to test it live.
Can we set global timezone for moment-hijri much like the moment-timezone allows.
Kindly i was try to add (moment hijri) but still not working , can you give me the steps with small explain ?
Thanks for this git
Please take a look at Eonasdan's bootstrap datetimepicker here
it uses moment with locales
is there any way i can implement your script with it
the page freezes when i load moment-hijri
thank you very much
Hello,
Is there any offset issues with the conversion calculations?
I've read that converting hijri-gregorian or gregorian-hijri may have one day offset.
This situation can happen with this plugin too?
Description: comparing 1443/11/01 to 1443/10/01 returns true also it should return false
Steps to replicate the bug: moment('1443/11/01', 'iYYYY/iMM/iDD').isSame(moment('1443/10/01', 'iYYYY/iMM/iDD'),'month')
Hi!
Getting the number of days in the month doesn't work.
Method iDaysInMonth()
returns value 'NaN'.
Workaround:
Method endOf('iMonth').iDate()
return value correctly.
I converted dates for +- 5 years interval from now to be sure it matches Hijri dates given by MS Umm al-Qura calendar and found 1 mismatch:
moment('2024-12-02').format('YYYY-M-D [is] iYYYY-iM-iD') // 2024-12-2 is 1446-5-30
But according to http://www.ummulqura.org.sa and other resources, it should be 1446-6-1
Hi @xsoh,
Could you please publish latest version to npm?
Hi
moment('14/14/1436', 'iDD/iMM/iYYYY').isValid() returns true....
moment('30/455/1436', 'iDD/iMM/iYYYY').isValid() returns true....
or what am I doing wrong ?
thanks
As @mj1856 suggested on this Add moment-hijri to plugins #164 pull, that the h
specifier might cause overlap with hour's specifier.
For that it should be change to another specifier. The better specifier is to use i
instead. That is because it represent Islamic Calendar and also Hijri
has two I`s ๐
This change will make a big difference for the tool usage, for that I suggest to be the v2.0 of moment-hijri.
why m.add(2, 'iDay'); or m.add(2, 'iDays'); is not working ??
I am trying to find number of days in a hijri year, for that I'm looping over days in months and found strange case that for 1 month of the year the number of days returned is 1.
Please observe the attached images.
This is an urgent issue. I have chosen this library and started it's implementation. this case is disrupting a major flow.
This is for timezone America/New_York and I'm using moment-timezone for setting zones
Hi,
Thank you very much for making this plugin ๐ .
I'm trying to execute this line (from the readme)
moment('2014-11-28 16:40:00', 'YYYY-M-D HH:mm:ss').endOf('hMonth').format('hYYYY/hM/hD HH:mm:ss'); // 1436/2/30 23:59:59
it doesn't give the result mentioned in the comment 1436/2/30 23:59:59
and also tried many variants, it looks like endOf
method is not affecting the date if given hmounth
or hyear
or anything outside the standard moment units.
Any thoughts about this ?
We are using the moment-hijri in a datepicker component. There we have noticed that if we try to get a date of 1501 or above it returns NaN. Infact I can see the comments in js also that it will return dates till year 1500 only. Any particular reason for this?
import * as momentHijri from 'moment-hijri'
momentHijri.locale('ar-SA')
momentHijri(momentHijri().format('iYYYY/iMM/iDD'), 'iYYYY/iMM/iDD').isValid()
Running this code returns false for me --- I would expect to be able to parse a value using the same format string used to generate it. Looking at the code, it might be because the parse logic isn't handling the Arabic numerals, ie: with my above format string, the parse would only handle '1111-11-11' format.
console.log(m._iMonths[m.iMonth()])
is this correct ? it is not showing anything tho(undefined)
Should parse when only Hijri date is in the format
it('should parse when only Hijri date is in the format', function() {
var m = moment('1990 28 3', 'YYYY hD M')
m.format('YYYY-MM-DD').should.be.equal('1990-03-25')
})
Should parse when only Hijri month is in the format
it('should parse when only Hijri month is in the format', function() {
var m = moment('1990 08 25', 'YYYY hM D')
m.format('YYYY-MM-DD').should.be.equal('1990-03-25')
})
When i trying to convert the moment hijri date to gregorian, i am facing the problem
moment("arabic date time", "iM-iD-iYYYY H:mm).format('M-D-YYYY')
I got the exception string.indexOf is not a function
Please how i can get hijri month lenght, i am using daysInMonth but it always return gregorian month lengh.
here is my code
var m = moment('1410/8/28', 'iYYYY/iM/iD');
var v1= m.iYear(); // 1410
var v2 = m.iMonth(); // 7
var v3 = m.iDate(); // 28
var v4 = m.iDayOfYear(); // 236
var v5 = m.iWeek(); // 35
var v6 = m.iWeekYear(); // 1410
var v7= m.daysInMonth();
Change localFormatingToken regex to support LTS mask as in momentjs
When the date is set to 1/1/1441 endOf('iMonth) will return 1. Which is wrong!
Even after including
<script src="locale/ar-sa.js"></script>
When I try to print the current month's name which is Shawwal, it always returns Ramadan this happened only in the 2022 year if I try past or next year it works fine
moment().add(1, "year").startOf("month").format("iMMMM")
Hi,
Thank you for this plugin.
I've noticed the issue described in the title. I believe it happens because of invoking the updateLocale
method. If you see how it's implemented, you will notice that it sets the global locale.
https://github.com/moment/moment/blob/develop/src/lib/locale/locales.js#L143
Hello everyone,
Thanks for a great project. I tried to use this library and it works most of the time but I faced some issues with the following dates:
1381,7,1
1980, 3, 31
1956, 12, 30
I get the wrong date for them compared to Um Alqura website. The converted date is off by one day.
Should parse when only Hijri year is in the format
it('should parse when only Hijri year is in the format', function() {
var m = moment('03 1410 25', 'MM hYYYY DD')
m.format('YYYY-MM-DD').should.be.equal('1990-03-25')
m = moment('03 10 25', 'MM hYY DD')
m.format('YYYY-MM-DD').should.be.equal('1990-03-25')
})
Hi, (ุงูุณูุงู
ุนูููู
)
iMonth function return wrong value, for example the date is 1439/8/19 in this case it should return 8 but it returns 7 .
Thank You
ู
ุซูุง ูู ุงูุนูุฏ ุนูุฏู
ุง ูุจุฏุฃ ุงูุชูุจูุฑุงุช ูููุงุ ุฃู ุนูุฏู
ุง ูููู ูููุฉ ุงูุฌู
ุนุฉ ูุงูู
ูุตูุฏ
ููุง ูู ุงููููุฉ ุงูุชู ุชุณุจู ุงูููุงุฑุ ุฃู ุฃู ุงูููู ูุฃุชู ุซู
ูุฃุชู ุงูููุงุฑ ูู ุงูุชูููู
ุงููุฌุฑูุ ุฃู ุฃู ุงูููู
ูุจุฏุฃ ุนูุฏ ู
ุบุฑุจ ุงูุดู
ุณ
ููู ุช ู ู ููุง ุฃู ุงูููุงุฑ ูู ุงูุชูููู ุงููุฌุฑู ูู ู ู ุงูุดุฑูู ุญุชู ุงูุบุฑูุจ ูุงูููู ูู ู ู ุงูุบุฑูุจ ุญุชู ุงูุดุฑูู ๐ุ ูุฃู ุงูููู ุงูููู ูุชููู ู ู ุงูููู ุซู ุงูููุงุฑ.
When parsing the month from iMMM format it uses a one-based index. So, Shw is month 10, but then it converts it to the Gregorian equivalent using zero-based index and so it is off by one month.
const input = '22 Shw 1440';
const output = moment(input, 'iDD iMMM iYYYY').format('iDD iMMM iYYYY');
if (input !== output) {
console.log(`${input} returned ${output}`);
}
output is "22 Shw 1440 returned 22 Dhu-Q 1440"
Hello,
I am trying to get the hijri date based on unix time but i am getting gregorian date instead.
const justNow = new Date();
const momentHijriNow = momentHijri.unix(justNow.valueOf() / 1000);
console.log('momentHijri now', momentHijriNow.format('iYYYY/iM/iD')); // momentHijri now i2019/i2/i6
Maybe I am doing really wrong :S
Thanks for your job ;)
Hello. I'm concerned using this library has implicit conflicts with other plugins. By adding methods to the singleton moment object at import time, it's possible to have conflicts at a distance in an app.
I'd advocate for exporting a "High Order Function" instead, so that the consumer can decide when/where to apply the plugin, and that will leave the original module unmodified.
ie:
require('moment');
var moment = require('moment-hijri');
becomes
var moment = require('moment-hijri')(require('moment'));
or in es6
import moment from 'moment';
import hijriify from 'moment-hijri';
const hijriMoment = hijiriify(moment);
Also remove need for AMD export in repo, as AMD projects could do:
define(['moment', 'moment-hijri'], function(moment, hijriify) {
var hijriMoment = hijriify(moment);
});
When I try to format a date with year greater than 1500 like this momentHijri(date).format("MMM YYYY"), I get undefined 0NaN and if I format it momentHijri(date).format("iMMMM iYYYY") gives wrong date e.g Mar -100100
Are you planning to support typescript or even provide a typing for your lib ?
Can I show Day names as ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
Is it work for mobile also ?
import * as momentHijri from 'moment-hijri'
momentHijri.locale('ar-SA')
momentHijri(momentHijri().format('iYYYY/iMM/iDD'), 'iYYYY/iMM/iDD').isValid()
Running this code returns false for me --- I would expect to be able to parse a value using the same format string used to generate it. Looking at the code, it might be because the parse logic isn't handling the Arabic numerals, ie: with my above format string, the parse would only handle '1111-11-11' format.
I'm using moment to make a calendar and this line is throwing the above error:
ev.date = moment(ev.eventTime, "YYYY-MM-DD");
where eventTime is:
{eventName: 'Interview - Jr. Web Developer', calendar: 'Work', color: 'orange', eventTime: moment("2020-05-16")},
The calendar works without moment-hijri dependency but I want to add hijri dates to the calendar.I haven't parsed hijri dates so far.
This line from moment-hijri.js is throwing the error:
string = string.slice(string.indexOf(parsedInput) + parsedInput.length)
Assalam, How can I change timezone for Hijri moment because default moment-hijri current date not same as my country (Malaysia)
Hi I tried to format from gregorian to Hijri date but gives me arabic text.
moment(value, "DD/MM/YYYY").format("iD/iM/iYYYY");
Am no sure if I should be posting the issue here or in the Git of the datetimepicker, however whenever I try to use the moment-hijri with the bootstrap-datetimepicker and setting the format at 'iDD/iMM/iYYYY' I keep getting the 'i' in front of the days/months/years and yes I did include the ar-sa file for moment.
So if you could please help out.
Should parse when only Hijri month string is in the format
it('should parse when only Hijri month string is in the format', function() {
var m = moment('1990 Sha 25', 'YYYY hMMM D')
m.format('YYYY-MM-DD').should.be.equal('1990-03-25')
m = moment('1990 Shaโban 25', 'YYYY hMMMM D')
m.format('YYYY-MM-DD').should.be.equal('1990-03-25')
})
I've tried to convert 1458/09/01, it gave me 2036/10/20
but here on the official site of the calendar http://www.ummulqura.org.sa/Index.aspx it gives 2036/10/21 .
UPDATE
after I've posted the issue, I tried the fork of @philips-emr here: https://github.com/philips-emr/moment-hijri, it gave the same results for other dates but for this one it gave the same as the official site.
m = moment('1355/8/28', 'iYYYY/iM/iD'); // Parse a Hijri date.
m.format('iYYYY/iM/iD [is] YYYY/M/D'); // 1410/8/28 is 1990/3/25
"1355/12/NaN is 1001/3/1"
I have created a project that, use this awesome library to make datepicker base on bootstrap 4
https://github.com/balbarak/bootstrap-hijri-datepicker
feel free to contribute
Thanks
how to get month name in English instead of araboc
Sometimes changing month returns wrong date. It happens only if current date is first day in month.
moment.format("iYYYY/iMM/iDD"); // "1438/05/01"
moment.iMonth(5);
moment.format("iYYYY/iMM/iDD"); // "1438/06/29"
Next same event is in 1441
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.