⚠️ WARNING: This project is no longer maintained.This repository is archived and is not accepting any new issues, pull requests, or updates.
Please consider using the following alternative:
This is a fork of jalali-moment and it's modified just to use with ant-design so if you want use it just for jalali dates and time you should go to jalali-moment page and see the original docs
Read this in other languages: فارسی
It was a fork of moment-jalali but the main goal of this repository is to facilitate converting any library using moment.js to be compatible with jalali calendar system. List of packages use jalali-moment to convert calendar system.
-
Use jalali moment in
This plugin provides using jalali and gregorian calendar system together on momentjs api.
.locale('fa');
it will use jalali calendar system.locale('any other locale');
it will use gregorian calendar system
jalali(Persian) calendar is a solar calendar system. It gains approximately 1 day on the Julian calendar every 128 years. Read more on Wikipedia.
Calendar conversion is based on the algorithm provided by Kazimierz M. Borkowski and has a very good performance.
This plugin adds Jalali (Persian, Khorshidi, Shamsi) calendar system to moment.js library.
Install via npm
npm install antd-jalali-moment -S
Install via yarn
yarn add antd-jalali-moment
Install via bower
bower install antd-jalali-moment --save
change webpack config and use alias for changing moment to antd-jalali-moment.
if you use react-app-rewired you can use this config.overrides.js
const { injectBabelPlugin } = require("react-app-rewired");
const rewireLess = require("react-app-rewire-less");
module.exports = function override(config, env) {
config = injectBabelPlugin(
["import", { libraryName: "antd", libraryDirectory: "es", style: "css" }],
config
);
config = injectBabelPlugin(
["import", { libraryName: "antd", style: true }],
config
);
config = injectBabelPlugin(["syntax-dynamic-import"], config);
config.resolve.alias["moment"] = "antd-jalali-moment"; // this is where we use alias
return config;
};
Install it via npm or yarn then wrap your App component in LocaleProvider component.
import React from "react";
import ReactDOM from "react-dom";
import { LocaleProvider } from "antd";
import fa_IR from "antd/lib/locale-provider/fa_IR";
import "moment/locale/fa";
import moment from "moment";
import App from "./App";
moment.locale("fa");
ReactDOM.render(
<LocaleProvider locale={fa_IR}>
<App />
</LocaleProvider>,
document.getElementById("root")
);
Basically with installing this package you bring jalali dates and time to LocaleProvider component so if you use redux or else and change language and locale at any time, dates and time goes back to original date system.
for using the original jalali-moment api read the original docs HERE.