xsoh / moment-hijri

A Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js
http://momentjs.com/docs/#/plugins/hijri/
MIT License
200 stars 82 forks source link

Parse logic doesn't match format logic #48

Closed mdentremont closed 2 years ago

mdentremont commented 5 years ago
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.

talal424 commented 4 years ago

i don't think preparse() has any effect on this situation

this should do trick if you don't need Arabic numerals

import * as momentHijri from 'moment-hijri'

momentHijri.locale('ar-SA')

momentHijri.updateLocale('ar-sa', {
  postformat: string => string
})

momentHijri(momentHijri().format('iYYYY/iMM/iDD'), 'iYYYY/iMM/iDD').isValid() //true
talal424 commented 4 years ago

47

soheils2 commented 3 years ago

hi can you add this to Readme? that can Help other people who dont want arabic numbers as default setup! tnx