Open SajjadGit opened 8 years ago
@SajjadGit Hello,
Have you tried something like this moment("10-1-1437 7:33", "iM-iD-iYYYY H:mm").format('M-D-YYYY')
and didn't work with you?
This was our fix if it helps
`function makeMoment(input, format, lang, utc) {
if (!(input instanceof String)) {
var tempMoment = moment(input);
input = tempMoment.toISOString();
}`
please any update on this issue I face it too when I change from Hijri to normal date no matter what I try as format it gives me the same result I even try to change from Hijri iso format to normal iso nothing is working here is my packages versions that I used and some of the code
P.S:-here is the format that I am sure it will give u the error moment(newValue, 'iYYYY-iMM-iDD').format('YYYY-MM-DD')
also moment(newValue, 'iYYYY-iMM-iDDTHH:mm:ssZ').format('YYYY-MM-DDTHH:mm:ssZ')
=============================the versions
"@date-io/date-fns": "^2.15.0",
"@date-io/hijri": "^2.15.0",
"@mui/lab": "^5.0.0-alpha.95",
"@mui/base": "^5.0.0-alpha.93",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.10.1",
"@mui/styles": "^5.9.3",
"@mui/x-date-pickers": "^5.0.0-beta.6",
"moment": "^2.29.4",versa
"moment-hijri": "^2.1.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
======================= the code
` import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment'; import { DatePicker } from '@mui/x-date-pickers/DatePicker'; import moment from 'moment-hijri'; import 'moment/locale/ar'; import 'moment/locale/tr'; import 'moment/locale/ro'; import 'moment/locale/ar-sa'; import MomentUtils from '@date-io/hijri';
const localeMap = { ar: 'ar', tr: 'tr', ro: 'ro', };
<LocalizationProvider
dateAdapter={isHijri ? MomentUtils : AdapterMoment}
dateLibInstance={moment}
adapterLocale={(isHijri && 'ar-sa') || localeMap[i18next.language] || 'en'}
>
<DatePicker
value={localValue}
onChange={onChangeHandler}
className="date-picker-component-wrapper"
maxDate={
isHijri && !maxDate ? moment('1499-12-29', 'iYYYY-iMM-iDD') : maxDate
}
minDate={
isHijri && !minDate ? moment('1356-01-01', 'iYYYY-iMM-iDD') : minDate
}
toolbarPlaceholder={toolbarPlaceholder}
inputFormat={(isHijri && hijriDisplayFormat) || displayFormat}
mask={(isHijri && hijriMask) || mask}
disableMaskedInput={disableMaskedInput}
disableFuture={disableFuture}
disablePast={disablePast}
disabled={disabled}
renderInput={(params) => (
<TextField
label={label}
helperText={
helperText
}
...params,
mask: (isHijri && hijriMask) || mask,
/>
)}
/>
</LocalizationProvider>`
as a workaround when changing from Hijri to regular date and vice versa I clear the date if filled and re-enter it by the user but this is not a good way I prefer to change as smooth as it should be
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